Ansel_ImageGenerator::_getStackImages PHP Method

_getStackImages() protected method

Utility function to return an array of Horde_Images to use in building a stack. Returns a random set of 5 images from the gallery, or the explicitly set key image plus 4 others.
protected _getStackImages ( ) : array
return array An array of Horde_Image objects.
    protected function _getStackImages()
    {
        $images = array();
        $gallery = $this->_params['gallery'];
        // Make sure we have images. We can't go deeper into subgalleries
        // since some of them may not have HORDE_PERMS::READ and the
        // keyimage-thumbnails are generated by the first user who views
        // them, using their perms.
        if (!$gallery->countImages() && $gallery->hasSubGalleries()) {
            return array();
        }
        $cnt = min(5, $gallery->countImages());
        $default = $gallery->get('default');
        if (!empty($default) && $default > 0) {
            try {
                $img = $gallery->getImage($default);
                $img->load('screen');
                $images[] = $img->getHordeImage();
                $cnt--;
            } catch (Ansel_Exception $e) {
                Horde::log($e, 'ERR');
            }
        }
        for ($i = 0; $i < $cnt; $i++) {
            $rnd = mt_rand(0, $cnt);
            try {
                $temp = $gallery->getImages($rnd, 1);
                if (count($temp)) {
                    $aimg = array_shift($temp);
                    $aimg->load('screen');
                    $images[] = $aimg->getHordeImage();
                }
            } catch (Ansel_Exception $e) {
                Horde::log($e, 'ERR');
            }
        }
        // Reverse the array to ensure the requested key image
        // is the last in the array (so it will appear on the top of
        // the stack.
        return array_reverse($images);
    }