Redaxscript\Modules\Gallery\Gallery::_renderItem PHP Method

_renderItem() public static method

renderItem
Since: 2.6.0
public static _renderItem ( string $directory = null, array $optionArray = [] ) : string
$directory string
$optionArray array
return string
    public static function _renderItem($directory = null, $optionArray = [])
    {
        $outputItem = null;
        /* html elements */
        $imageElement = new Html\Element();
        $imageElement->init('img', ['class' => self::$_configArray['className']['image']]);
        $linkElement = new Html\Element();
        $linkElement->init('a');
        /* gallery directory */
        $galleryDirectory = new Directory();
        $galleryDirectory->init($directory, [self::$_configArray['thumbDirectory']]);
        $galleryDirectoryArray = $galleryDirectory->getArray();
        /* adjust order */
        if ($optionArray['order'] === 'desc') {
            $galleryDirectoryArray = array_reverse($galleryDirectoryArray);
        }
        /* gallery data */
        $galleryCounter = 0;
        $galleryTotal = count($galleryDirectoryArray);
        /* process directory */
        foreach ($galleryDirectoryArray as $value) {
            $imagePath = $directory . '/' . $value;
            $thumbPath = $directory . '/' . self::$_configArray['thumbDirectory'] . '/' . $value;
            /* get image data */
            $imageData = self::_getExifData($imagePath);
            /* collect item output */
            $outputItem .= '<li>';
            $outputItem .= $linkElement->copy()->attr(['href' => $imagePath, 'data-counter' => ++$galleryCounter, 'data-total' => $galleryTotal, 'data-artist' => array_key_exists('artist', $imageData) ? $imageData['artist'] : null, 'data-date' => array_key_exists('date', $imageData) ? $imageData['date'] : null, 'data-description' => array_key_exists('description', $imageData) ? $imageData['description'] : null])->html($imageElement->copy()->attr(['src' => $thumbPath, 'alt' => array_key_exists('description', $imageData) ? $imageData['description'] : $value]));
            $outputItem .= '</li>';
        }
        return $outputItem;
    }