Ansel_View_Base::_getGallery PHP Method

_getGallery() protected method

Todo
protected _getGallery ( integer $galleryId = null, string $slug = '' ) : Ansel_Gallery
$galleryId integer The gallery id
$slug string The gallery slug
return Ansel_Gallery The requested Ansel_Gallery object
    protected function _getGallery($galleryId = null, $slug = '')
    {
        if (is_null($galleryId) && empty($slug)) {
            $galleryId = !empty($this->_params['gallery_id']) ? $this->_params['gallery_id'] : null;
            $slug = !empty($this->_params['gallery_slug']) ? $this->_params['gallery_slug'] : null;
        }
        if (empty($galleryId) && empty($slug)) {
            throw new Ansel_Exception(_("No gallery specified"));
        }
        // If we have a slug, use it.
        try {
            if (!empty($slug)) {
                $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGalleryBySlug($slug);
            } else {
                $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($galleryId);
            }
        } catch (Ansel_Exception $e) {
            throw new Horde_Exception_NotFound($e->getmessage());
        }
        if (!$gallery->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) {
            throw new Horde_Exception_PermissionDenied(_("Access denied to this gallery."));
        }
        /* Set any date info we might have */
        if (!empty($this->_params['year'])) {
            $date = Ansel::getDateParameter(array('year' => $this->_params['year'], 'month' => $this->_params['month'], 'day' => $this->_params['day']));
        } else {
            $date = array();
        }
        $gallery->setDate($date);
        return $gallery;
    }