From: Michael J. Rubinsky Date: Tue, 1 Feb 2011 16:45:30 +0000 (-0500) Subject: start cleaning up Ansel_View. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9e582ed196ffadda4aa9551b15cba1c8f93dacdf;p=horde.git start cleaning up Ansel_View. Abstract out another base class. Reduces code duplication for some of the methods only needed by "Ansel" views, (as opposed to javascript embedded views). --- diff --git a/ansel/lib/View/Ansel.php b/ansel/lib/View/Ansel.php new file mode 100644 index 000000000..cb9671cdc --- /dev/null +++ b/ansel/lib/View/Ansel.php @@ -0,0 +1,88 @@ + + * @package Ansel + */ +abstract class Ansel_View_Ansel extends Ansel_View_Base +{ + /** + * The ansel resource this view is for. + * @TODO: visibility protected + * @var mixed Either an Ansel_Gallery or Ansel_Image + */ + public $resource; + + /** + * The gallery object (will be eq to $resource in a gallery view + * + * @TODO: visibility protected + * @var Ansel_Gallery + */ + public $gallery; + + /** + * Collection of Ansel_Widgets to display in this view. + * + * @var array + */ + protected $_widgets = array(); + + /** + * Add an Ansel_Widget to be displayed in this view. + * + * @param Ansel_Widget $widget The Ansel_Widget to display + */ + public function addWidget($widget) + { + $result = $widget->attach($this); + if (!empty($result)) { + $this->_widgets[] = $widget; + } + } + + /** + * Output any widgets associated with this view. + * + */ + public function renderWidgets() + { + $this->_renderWidgets(); + } + + /** + * Count the number of widgets we have attached. + * + * @return integer The number of widgets attached to this view. + */ + public function countWidgets() + { + return count($this->_widgets); + } + + /** + * Default widget rendering, can be overridden by any subclass. + * + */ + protected function _renderWidgets() + { + echo '
'; + foreach ($this->_widgets as $widget) { + if ($widget->autoRender) { + echo $widget->html(); + echo '
'; + } + } + echo '
'; + } + + abstract public function viewType(); + abstract public function getGalleryCrumbData(); + abstract public function getTitle(); + abstract public function html(); +} \ No newline at end of file diff --git a/ansel/lib/View/Base.php b/ansel/lib/View/Base.php index 487c07d61..720721587 100644 --- a/ansel/lib/View/Base.php +++ b/ansel/lib/View/Base.php @@ -16,27 +16,6 @@ abstract class Ansel_View_Base protected $_params = array(); /** - * The ansel resource this view is for. - * - * @var mixed Either an Ansel_Gallery or Ansel_Image - */ - public $resource; - - /** - * The gallery object (will be eq to $resource in a gallery view - * - * @var Ansel_Gallery - */ - public $gallery; - - /** - * Collection of Ansel_Widgets to display in this view. - * - * @var array - */ - protected $_widgets = array(); - - /** * Const'r * * Any javascript files needed by the (non-api) view should be included @@ -117,6 +96,16 @@ abstract class Ansel_View_Base } /** + * Getter for the view parameters. + * + * @return unknown_type + */ + public function getParams() + { + return $this->_params; + } + + /** * Todo * * @param integer $galleryId The gallery id @@ -167,60 +156,16 @@ abstract class Ansel_View_Base return $gallery; } - /** - * Add an Ansel_Widget to be displayed in this view. - * - * @param Ansel_Widget $widget The Ansel_Widget to display - */ - public function addWidget($widget) - { - $result = $widget->attach($this); - if (!empty($result)) { - $this->_widgets[] = $widget; - } - } - - /** - * Output any widgets associated with this view. - * - */ - public function renderWidgets() - { - $this->_renderWidgets(); - } - - /** - * Count the number of widgets we have attached. - * - * @return integer The number of widgets attached to this view. - */ - public function countWidgets() - { - return count($this->_widgets); - } - - /** - * Default widget rendering, can be overridden by any subclass. - * - */ - protected function _renderWidgets() - { - echo '
'; - foreach ($this->_widgets as $widget) { - if ($widget->autoRender) { - echo $widget->html(); - echo '
'; - } - } - echo '
'; - } /** - * JSON representation of this gallery's images. + * JSON representation of this gallery's images. We don't use + * Ansel_Gallery::toJson() on purpose since that is a general jsonification + * of the gallery data. This method is specific to the view, paging, links + * etc... * - * @param array $params An array of parameters for this method: + * @param Ansel_Gallery $gallery The gallery to represent in this view + * @param array $params An array of parameters for this method: *
-     *      images     - Array of Ansel_Images to generate JSON for [null]
      *      full       - Should a full URL be generated? [false]
      *      from       - Starting image count [0]
      *      count      - The number of images to include (starting at from) [0]
@@ -231,7 +176,7 @@ abstract class Ansel_View_Base
      *
      * @return string  A serialized JSON array.
      */
-    public function json($params = array())
+    static public function json(Ansel_Gallery $gallery, $params = array())
     {
         global $conf, $prefs;
 
@@ -251,10 +196,10 @@ abstract class Ansel_View_Base
         $curpage =  0;
 
         if (empty($params['images'])) {
-            $images = $this->gallery->getImages($params['from'], $params['count']);
+            $images = $gallery->getImages($params['from'], $params['count']);
         }
 
-        $style = $this->gallery->getStyle();
+        $style = $gallery->getStyle();
         foreach ($images as $image) {
             // Calculate the page this image will appear on in the
             // gallery view.
@@ -270,15 +215,15 @@ abstract class Ansel_View_Base
                           $curpage);
             if ($params['view_links']) {
                 $data[] = (string)Ansel::getUrlFor('view',
-                    array('gallery' => $this->gallery->id,
-                          'slug' => $this->gallery->get('slug'),
+                    array('gallery' => $gallery->id,
+                          'slug' => $gallery->get('slug'),
                           'image' => $image->id,
                           'view' => 'Image',
                           'page' => $curpage),
                     true);
                 $data[] = (string)Ansel::getUrlFor('view',
                     array('gallery' => $image->gallery,
-                          'slug' => $this->gallery->get('slug'),
+                          'slug' => $gallery->get('slug'),
                           'view' => 'Gallery'),
                     true);
             }
@@ -289,26 +234,4 @@ abstract class Ansel_View_Base
         return Horde_Serialize::serialize($json, Horde_Serialize::JSON);
     }
 
-    /**
-     * Getter for the view parameters.
-     *
-     * @return unknown_type
-     */
-    public function getParams()
-    {
-        return $this->_params;
-    }
-
-    /**
-     * @abstract
-     * @return unknown_type
-     */
-    abstract public function viewType();
-
-    abstract public function getGalleryCrumbData();
-
-    abstract public function getTitle();
-
-    abstract public function html();
-
 }
diff --git a/ansel/lib/View/EmbeddedRenderer/Mini.php b/ansel/lib/View/EmbeddedRenderer/Mini.php
index ac4d284d4..9d7cef4d8 100644
--- a/ansel/lib/View/EmbeddedRenderer/Mini.php
+++ b/ansel/lib/View/EmbeddedRenderer/Mini.php
@@ -10,8 +10,13 @@
  * @author  Michael J. Rubinsky 
  * @package Ansel
  */
-class Ansel_View_EmbeddedRenderer_Mini extends Ansel_View_Gallery
+class Ansel_View_EmbeddedRenderer_Mini extends Ansel_View_Base
 {
+    public function __construct($params = array())
+    {
+        $this->_params = $params;
+    }
+
     /**
      * Build the javascript that will render the view.
      *
@@ -62,12 +67,15 @@ class Ansel_View_EmbeddedRenderer_Mini extends Ansel_View_Gallery
         }
 
         if (empty($images)) {
-            $json = $this->json(array('full' => true,
+            $images =
+            $json = self::json($this->gallery,
+                                array('full' => true,
                                       'from' => $start,
                                       'count' => $count,
                                       'image_view' => $thumbsize,
                                       'view_links' => true));
-            $json_full = $this->json(array('full' => true,
+            $json_full = self::json($this->gallery,
+                                     array('full' => true,
                                            'from' => $start,
                                            'count' => $count,
                                            'view_links' => true));
diff --git a/ansel/lib/View/Gallery.php b/ansel/lib/View/Gallery.php
index 3f1679e6a..968ffaa48 100644
--- a/ansel/lib/View/Gallery.php
+++ b/ansel/lib/View/Gallery.php
@@ -10,7 +10,7 @@
  *
  * @package Ansel
  */
-class Ansel_View_Gallery extends Ansel_View_Base
+class Ansel_View_Gallery extends Ansel_View_Ansel
 {
     /**
      *  Holds the object that does the actual rendering.
diff --git a/ansel/lib/View/GalleryRenderer/GalleryLightbox.php b/ansel/lib/View/GalleryRenderer/GalleryLightbox.php
index 1badd8605..f2b27a3ca 100644
--- a/ansel/lib/View/GalleryRenderer/GalleryLightbox.php
+++ b/ansel/lib/View/GalleryRenderer/GalleryLightbox.php
@@ -58,14 +58,22 @@ class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRende
         /* Get JSON data for view */
         // 0 == normal, 1 == by date
         if ($this->mode == 0) {
-            $json = $this->view->json(array(
-                'full' => !empty($this->view->api),
-                'perpage' => $this->perpage));
+            $json = Ansel_View_Base::json(
+                $this->view->gallery,
+                array(
+                    'full' => !empty($this->view->api),
+                    'perpage' => $this->perpage
+                )
+            );
         } else {
             if (!empty($this->date['day']) && $this->numTiles) {
-                $json = $this->view->json(array(
-                    'full' => !empty($this->view->api),
-                    'perpage' => $this->perpage));
+                $json = Ansel_View_Base::json(
+                    $this->view->gallery,
+                    array(
+                        'full' => !empty($this->view->api),
+                        'perpage' => $this->perpage
+                    )
+                );
             } else {
                 $json = '[]';
             }
diff --git a/ansel/lib/View/Image.php b/ansel/lib/View/Image.php
index 94e610dd5..9a7b669b3 100644
--- a/ansel/lib/View/Image.php
+++ b/ansel/lib/View/Image.php
@@ -10,7 +10,7 @@
  *
  * @package Ansel
  */
-class Ansel_View_Image extends Ansel_View_Base
+class Ansel_View_Image extends Ansel_View_Ansel
 {
 
     protected $_slug;
diff --git a/ansel/lib/View/List.php b/ansel/lib/View/List.php
index 0d8a5eed9..723d94ff3 100644
--- a/ansel/lib/View/List.php
+++ b/ansel/lib/View/List.php
@@ -7,10 +7,12 @@
  * See the enclosed file COPYING for license information (GPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  *
+ * @TODO: should extend Base, not Ansel
+ *
  * @author  Michael J. Rubinsky 
  * @package Ansel
  */
-class Ansel_View_List extends Ansel_View_Base
+class Ansel_View_List extends Ansel_View_Ansel
 {
     private $_groupby;
     private $_owner;
diff --git a/ansel/lib/View/Results.php b/ansel/lib/View/Results.php
index 5caec0fcd..e7f83b7a8 100644
--- a/ansel/lib/View/Results.php
+++ b/ansel/lib/View/Results.php
@@ -8,12 +8,13 @@
  * See the enclosed file COPYING for license information (GPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  *
+ * @TODO: Should extend Base, not Ansel
  * @author  Michael J. Rubinsky 
  * @category Horde
  * @license  http://www.fsf.org/copyleft/gpl.html GPL
  * @package  Ansel
  */
-class Ansel_View_Results extends Ansel_View_Base
+class Ansel_View_Results extends Ansel_View_Ansel
 {
     /**
      * Instance of our tag search
diff --git a/ansel/templates/view/slideshow.inc b/ansel/templates/view/slideshow.inc
index e24473cbe..6d97fd97f 100644
--- a/ansel/templates/view/slideshow.inc
+++ b/ansel/templates/view/slideshow.inc
@@ -1,6 +1,6 @@