From: Michael J. Rubinsky Date: Fri, 31 Jul 2009 17:02:05 +0000 (-0400) Subject: Horde 4 refactoring for GalleryRenderer objects X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ec459bf42ea73a4cdc3cc94e7d2712cfc00e9328;p=horde.git Horde 4 refactoring for GalleryRenderer objects --- diff --git a/ansel/lib/View/GalleryRenderer.php b/ansel/lib/View/GalleryRenderer.php deleted file mode 100644 index 3056fd4fa..000000000 --- a/ansel/lib/View/GalleryRenderer.php +++ /dev/null @@ -1,219 +0,0 @@ - - * @package Ansel - */ -class Ansel_View_GalleryRenderer { - - /** - * The Ansel_View_Gallery object that this Renderer belongs to. - * - * @var Ansel_View_Gallery - */ - var $view; - - /** - * The gallery id for this view's gallery - * - * @var integer - */ - var $galleryId; - - /** - * Gallery slug for current gallery. - * - * @var string - */ - var $gallerySlug; - - /** - * The current page we are viewing - * - * @var integer - */ - var $page = 0; - - /** - * The display mode of the current gallery. - * 0 == Normal - * 1 == Group by date - * - * @var integer - */ - var $mode; - - /** - * The style definition array for this gallery. - * - * @var array - */ - var $style; - - /** - * Holds number of tiles to display per page - * - * @var integer - */ - var $perpage; - - /** - * The tile number we are starting with on the current page. - * - * @var integer - */ - var $pagestart; - - /** - * The last tile number on the current page. - * - * @var integer - */ - var $pageend; - - /** - * The total number of tiles that this view contains - * - * @var integer - */ - var $numTiles; - - /** - * The Ansel_Image or Ansel_DateGallery objects that appear on the current - * page in the current view. - * - * @var array of Ansel_Image or Ansel_DateGallery objects. - */ - var $children; - - /** - * If we are grouping by date, this holds the currently selected date parts. - * - * @var array containing sufficient date parts for the current depth. - */ - var $date = array(); - - /** - * Constructor - * - * @param Ansel_View_Gallery The view object for this renderer. - * - * @return Ansel_View_Renderer_Gallery - */ - function Ansel_View_GalleryRenderer($view) - { - $this->view = $view; - } - - /** - * Initialize the renderer. This *must* be called before any attempt is made - * to display or otherwise interact with the renderer. - * - */ - function init() - { - global $prefs, $conf; - - $this->galleryId = $this->view->gallery->id; - $this->gallerySlug = $this->view->gallery->get('slug'); - if (isset($this->view->_params['page'])) { - $this->page = $this->view->_params['page']; - } - - /* Number perpage from prefs or config */ - $this->perpage = min($prefs->getValue('tilesperpage'), - $conf['thumbnail']['perpage']); - - /* Calculate the starting and ending images on this page */ - $this->pagestart = ($this->page * $this->perpage) + 1; - - /* Fetch the children */ - $this->fetchChildren($this->view->_params['force_grouping']); - - /* Do we have an explicit style set? If not, use the gallery's */ - if (!empty($this->view->_params['style'])) { - $this->style = Ansel::getStyleDefinition($this->view->_params['style']); - } else { - $this->style = $this->view->gallery->getStyle(); - } - - /* Include any widgets */ - if (!empty($this->style['widgets'])) { - /* Special case widgets - these are built in */ - if (array_key_exists('Actions', $this->style['widgets'])) { - /* Don't show action widget if no actions */ - if (Horde_Auth::getAuth() || - !empty($conf['report_content']['driver']) && - (($conf['report_content']['allow'] == 'authenticated' && Horde_Auth::isAuthenticated()) || - $conf['report_content']['allow'] == 'all')) { - - $this->view->addWidget(Ansel_Widget::factory('Actions')); - } - unset($this->style['widgets']['Actions']); - } - - // I *think* this is more efficient, iterate over the children - // since we already have them instead of calling listImages. - //$image_ids = $this->view->gallery->listImages($this->pagestart, $this->pagestart + $this->perpage); - $ids = array(); - foreach ($this->children as $child) { - if (is_a($child, 'Ansel_Image')) { - $ids[] = $child->id; - } - } - // Gallery widgets always receive an array of image ids for - // the current page. - foreach ($this->style['widgets'] as $wname => $wparams) { - $wparams = array_merge($wparams, array('images' => $ids)); - $this->view->addWidget(Ansel_Widget::factory($wname, $wparams)); - } - } - - /* See if any renderer specific tasks need to be done as well */ - $this->_init(); - } - - /** - * Default implementation for fetching children/images for this view. - * Other view classes can override this if they need anything special. - * - */ - function fetchChildren($noauto) - { - /* Total number of tiles for this gallery view */ - $this->numTiles = $this->view->gallery->countGalleryChildren(PERMS_SHOW, false, $noauto); - - /* Children to display on this page */ - $this->children = $this->view->gallery->getGalleryChildren( - PERMS_SHOW, - $this->page * $this->perpage, - $this->perpage, - !empty($this->view->_params['force_grouping'])); - - /* The last tile number to display on the current page */ - $this->pageend = min($this->numTiles, $this->pagestart + $this->perpage - 1); - } - - /** - * Return the HTML for this view. Done this way so we can override this in - * subclasses if desired. - * - * @return string - */ - function html() - { - if (is_a($this->view->gallery, 'PEAR_Error')) { - echo htmlspecialchars($this->view->gallery->getMessage(), ENT_COMPAT, Horde_Nls::getCharset()); - return; - } - - return $this->_html(); - } - -} diff --git a/ansel/lib/View/GalleryRenderer/Base.php b/ansel/lib/View/GalleryRenderer/Base.php new file mode 100644 index 000000000..1b3a66dd5 --- /dev/null +++ b/ansel/lib/View/GalleryRenderer/Base.php @@ -0,0 +1,213 @@ + + * @package Ansel + */ +abstract class Ansel_View_GalleryRenderer_Base +{ + /** + * The Ansel_View_Gallery object that this Renderer belongs to. + * + * @var Ansel_View_Gallery + */ + public $view; + + /** + * The gallery id for this view's gallery + * + * @var integer + */ + public $galleryId; // TODO: probably can remove this (get the id from the view's gallery) + + /** + * Gallery slug for current gallery. + * + * @var string + */ + var $gallerySlug; // Ditto. + + /** + * The current page we are viewing + * //TODO: use __get() for these type of things... + * @var integer + */ + public $page = 0; + + /** + * The display mode of the current gallery. + * 0 == Normal + * 1 == Group by date + * + * @var integer + */ + public $mode; + + /** + * The style definition array for this gallery. + * + * @var array + */ + public $style; + + /** + * Holds number of tiles to display per page + * + * @var integer + */ + public $perpage; + + /** + * The tile number we are starting with on the current page. + * + * @var integer + */ + public $pagestart; + + /** + * The last tile number on the current page. + * + * @var integer + */ + public $pageend; + + /** + * The total number of tiles that this view contains + * + * @var integer + */ + public $numTiles; + + /** + * The Ansel_Image or Ansel_DateGallery objects that appear on the current + * page in the current view. + * + * @var array of Ansel_Image or Ansel_DateGallery objects. + */ + public $children; + + /** + * If we are grouping by date, this holds the currently selected date parts. + * + * @var array containing sufficient date parts for the current depth. + */ + public $date = array(); + + /** + * Constructor + * + * @param Ansel_View_Gallery The view object for this renderer. + * + * @return Ansel_View_Renderer_Gallery + */ + public function __construct($view) + { + $this->view = $view; + } + + /** + * Initialize the renderer. This *must* be called before any attempt is made + * to display or otherwise interact with the renderer. + * + * @TODO: Not sure why I didn't put this in the const'r - try moving it. + * + */ + public function init() + { + global $prefs, $conf; + + $this->galleryId = $this->view->gallery->id; + $this->gallerySlug = $this->view->gallery->get('slug'); + if (isset($this->view->_params['page'])) { + $this->page = $this->view->_params['page']; + } + + /* Number perpage from prefs or config */ + $this->perpage = min($prefs->getValue('tilesperpage'), + $conf['thumbnail']['perpage']); + + /* Calculate the starting and ending images on this page */ + $this->pagestart = ($this->page * $this->perpage) + 1; + + /* Fetch the children */ + $this->fetchChildren($this->view->_params['force_grouping']); + + /* Do we have an explicit style set? If not, use the gallery's */ + if (!empty($this->view->_params['style'])) { + $this->style = Ansel::getStyleDefinition($this->view->_params['style']); + } else { + $this->style = $this->view->gallery->getStyle(); + } + + /* Include any widgets */ + if (!empty($this->style['widgets'])) { + /* Special case widgets - these are built in */ + if (array_key_exists('Actions', $this->style['widgets'])) { + /* Don't show action widget if no actions */ + if (Horde_Auth::getAuth() || + !empty($conf['report_content']['driver']) && + (($conf['report_content']['allow'] == 'authenticated' && Horde_Auth::isAuthenticated()) || + $conf['report_content']['allow'] == 'all')) { + + $this->view->addWidget(Ansel_Widget::factory('Actions')); + } + unset($this->style['widgets']['Actions']); + } + + // I *think* this is more efficient, iterate over the children + // since we already have them instead of calling listImages. + //$image_ids = $this->view->gallery->listImages($this->pagestart, $this->pagestart + $this->perpage); + $ids = array(); + foreach ($this->children as $child) { + if (is_a($child, 'Ansel_Image')) { + $ids[] = $child->id; + } + } + // Gallery widgets always receive an array of image ids for + // the current page. + foreach ($this->style['widgets'] as $wname => $wparams) { + $wparams = array_merge($wparams, array('images' => $ids)); + $this->view->addWidget(Ansel_Widget::factory($wname, $wparams)); + } + } + + /* See if any renderer specific tasks need to be done as well */ + $this->_init(); + } + + /** + * Default implementation for fetching children/images for this view. + * Other view classes can override this if they need anything special. + * + */ + public function fetchChildren($noauto) + { + /* Total number of tiles for this gallery view */ + $this->numTiles = $this->view->gallery->countGalleryChildren(PERMS_SHOW, false, $noauto); + + /* Children to display on this page */ + $this->children = $this->view->gallery->getGalleryChildren( + PERMS_SHOW, + $this->page * $this->perpage, + $this->perpage, + !empty($this->view->_params['force_grouping'])); + + /* The last tile number to display on the current page */ + $this->pageend = min($this->numTiles, $this->pagestart + $this->perpage - 1); + } + + /** + * Return the HTML for this view. Done this way so we can override this in + * subclasses if desired. + * + * @return string + */ + abstract public function html(); + abstract protected function _init(); +} diff --git a/ansel/lib/View/GalleryRenderer/Gallery.php b/ansel/lib/View/GalleryRenderer/Gallery.php index f806a4b20..b901ca2ea 100644 --- a/ansel/lib/View/GalleryRenderer/Gallery.php +++ b/ansel/lib/View/GalleryRenderer/Gallery.php @@ -11,13 +11,13 @@ * @author Michael J. Rubinsky * @package Ansel */ -class Ansel_View_GalleryRenderer_Gallery extends Ansel_View_GalleryRenderer { - +class Ansel_View_GalleryRenderer_Gallery extends Ansel_View_GalleryRenderer_Base +{ /** * Perform any tasks that should be performed before the view is rendered. * */ - function _init() + protected function _init() { } @@ -27,7 +27,7 @@ class Ansel_View_GalleryRenderer_Gallery extends Ansel_View_GalleryRenderer { * @return string The HTML. * */ - function _html() + public function html() { global $conf, $prefs, $registry; diff --git a/ansel/lib/View/GalleryRenderer/GalleryLightbox.php b/ansel/lib/View/GalleryRenderer/GalleryLightbox.php index d70051b4b..f4f062d82 100644 --- a/ansel/lib/View/GalleryRenderer/GalleryLightbox.php +++ b/ansel/lib/View/GalleryRenderer/GalleryLightbox.php @@ -11,13 +11,13 @@ * @author Michael J. Rubinsky * @package Ansel */ -class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRenderer { - +class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRenderer_Base +{ /** * Perform any tasks that should be performed before the view is rendered. * */ - function _init() + protected function _init() { if (empty($this->view->_params['image_onclick'])) { $this->view->_params['image_onclick'] = 'return lb.start(%i);'; @@ -36,7 +36,7 @@ class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRende * * @return string The HTML */ - function _html() + public function html() { global $conf, $prefs, $registry;