Ansel_Gallery::_getDefaultImageId PHP Method

_getDefaultImageId() protected method

Returns the id for the key image of this gallery.
protected _getDefaultImageId ( ) : integer | boolean
return integer | boolean The image id or false if none found.
    protected function _getDefaultImageId()
    {
        if ($this->countImages()) {
            if ($default = $this->get('default')) {
                return $default;
            }
            $keys = $this->listImages();
            $this->set('default', $keys[count($keys) - 1]);
            $this->set('default_type', 'auto');
            $this->save();
            return $keys[count($keys) - 1];
        }
        if ($this->hasSubGalleries()) {
            try {
                $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->listGalleries(array('parent' => $this->id, 'all_levels' => false));
                foreach ($galleries as $gallery) {
                    if ($default_img = $gallery->getKeyImage()) {
                        return $default_img;
                    }
                }
            } catch (Ansel_Exception $e) {
                return false;
            }
        }
    }