/** * Const'r * * @param array $params Any parameters that the view might need. * <pre> * In addition to the params taken by Ansel_View_Gallery, this view * can also take: * * groupby - Group the results (owner) * * owner - The owner to group by * * tags - Limit to galleries matching tags * * gallery_ids - No fitering, just show these galleries * * pager_url - The url for the pager to use see Ansel_Gallery for * more information on the url parameters. */ public function __construct(array $params = array()) { global $prefs, $notification, $registry; parent::__construct($params); $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage'); // View $this->_view = $GLOBALS['injector']->createInstance('Horde_View'); $this->_view->addTemplatePath(ANSEL_TEMPLATES . '/view'); $this->_view->sortBy = !empty($this->_params['sort']) ? $this->_params['sort'] : 'name'; $this->_view->sortDir = isset($this->_params['sort_dir']) ? $this->_params['sort_dir'] : 0; // Check for grouping. if (empty($this->_params['groupby'])) { $this->_view->groupby = Horde_Util::getFormData('groupby', $prefs->getValue('groupby')); } else { $this->_view->groupby = $this->_params['groupby']; } $this->_view->gPerPage = $prefs->getValue('tilesperpage'); // Listing a single user? if (empty($this->_params['owner'])) { $this->_owner = Horde_Util::getFormData('owner'); $this->_owner = empty($this->_owner) ? null : $this->_owner; } else { $this->_owner = $this->_params['owner']; } // Special? $this->_special = Horde_Util::getFormData('special'); if (!$this->_owner && !$this->_special && $this->_view->groupby != 'none') { Ansel::getUrlFor('group', array('groupby' => $this->_view->groupby))->redirect(); exit; } // If we aren't supplied with a page number, default to page 0. if (isset($this->_params['page'])) { $this->_page = $this->_params['page']; } else { $this->_page = Horde_Util::getFormData('page', 0); } // If we are calling from the api, we can just pass a list of ids if (!empty($this->_params['api']) && is_array($this->_params['gallery_ids'])) { $this->_view->start = $this->_page * $this->_view->gPerPage; $this->_view->numGalleries = count($this->_params['gallery_ids']); if ($this->_view->numGalleries > $this->_view->start) { $getThese = array_slice($this->_params['gallery_ids'], $this->_view->start, $this->_view->gPerPage); $this->_view->galleryList = $ansel_storage->getGalleries($getThese); } else { $this->_view->galleryList = array(); } } else { // Set list filter/title $filter = array(); if (!is_null($this->_owner)) { $filter['owner'] = $this->_owner; } $this->_view->numGalleries = $ansel_storage->countGalleries($registry->getAuth(), array('attributes' => $filter, 'all_levels' => false, 'tags' => !empty($params['tags']) ? $params['tags'] : null)); if ($this->_view->numGalleries == 0 && empty($this->_params['api'])) { if ($this->_owner && $this->_owner == $registry->getAuth()) { $notification->push(_("You have no photo galleries, add one!"), 'horde.message'); Horde::url('gallery.php')->add('actionID', 'add')->redirect(); exit; } $notification->push(_("There are no photo galleries available."), 'horde.message'); $this->_view->galleryList = array(); } else { $this->_view->galleryList = $ansel_storage->listGalleries(array('attributes' => $filter, 'all_levels' => false, 'from' => $this->_page * $this->_view->gPerPage, 'count' => $this->_view->gPerPage, 'sort_by' => $this->_view->sortBy, 'direction' => $this->_view->sortDir, 'tags' => !empty($params['tags']) ? $params['tags'] : null)); } } }