start cleaning up Ansel_View.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 1 Feb 2011 16:45:30 +0000 (11:45 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 1 Feb 2011 16:52:21 +0000 (11:52 -0500)
Abstract out another base class. Reduces code duplication for some
of the methods only needed by "Ansel" views, (as opposed to javascript
embedded views).

ansel/lib/View/Ansel.php [new file with mode: 0644]
ansel/lib/View/Base.php
ansel/lib/View/EmbeddedRenderer/Mini.php
ansel/lib/View/Gallery.php
ansel/lib/View/GalleryRenderer/GalleryLightbox.php
ansel/lib/View/Image.php
ansel/lib/View/List.php
ansel/lib/View/Results.php
ansel/templates/view/slideshow.inc

diff --git a/ansel/lib/View/Ansel.php b/ansel/lib/View/Ansel.php
new file mode 100644 (file)
index 0000000..cb9671c
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+/**
+ * Abstract Ansel_View class for Ansel UI specific views.
+ * Copyright 2011 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael J. Rubinsky <mrubinsk@horde.org>
+ * @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 '<div class="anselWidgets">';
+        foreach ($this->_widgets as $widget) {
+            if ($widget->autoRender) {
+                echo $widget->html();
+                echo '<br />';
+            }
+        }
+        echo '</div>';
+    }
+
+    abstract public function viewType();
+    abstract public function getGalleryCrumbData();
+    abstract public function getTitle();
+    abstract public function html();
+}
\ No newline at end of file
index 487c07d..7207215 100644 (file)
@@ -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 '<div class="anselWidgets">';
-        foreach ($this->_widgets as $widget) {
-            if ($widget->autoRender) {
-                echo $widget->html();
-                echo '<br />';
-            }
-        }
-        echo '</div>';
-    }
 
    /**
-     * 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:
      *   <pre>
-     *      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();
-
 }
index ac4d284..9d7cef4 100644 (file)
  * @author  Michael J. Rubinsky <mrubinsk@horde.org>
  * @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));
index 3f1679e..968ffaa 100644 (file)
@@ -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.
index 1badd86..f2b27a3 100644 (file)
@@ -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 = '[]';
             }
index 94e610d..9a7b669 100644 (file)
@@ -10,7 +10,7 @@
  *
  * @package Ansel
  */
-class Ansel_View_Image extends Ansel_View_Base
+class Ansel_View_Image extends Ansel_View_Ansel
 {
 
     protected $_slug;
index 0d8a5ee..723d94f 100644 (file)
@@ -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 <mrubinsk@horde.org>
  * @package Ansel
  */
-class Ansel_View_List extends Ansel_View_Base
+class Ansel_View_List extends Ansel_View_Ansel
 {
     private $_groupby;
     private $_owner;
index 5caec0f..e7f83b7 100644 (file)
@@ -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 <mrubinsk@horde.org>
  * @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
index e24473c..6d97fd9 100644 (file)
@@ -1,6 +1,6 @@
 <script type="text/javascript">
 //<![CDATA[
-SlideController.initialize(<?php echo $this->json(array('view_links' => true)) ?>, <?php echo $imageIndex ?>, "<?php echo $GLOBALS['registry']->get('webroot')?>", <?php echo $this->gallery->id ?>, "<?php echo $this->gallery->getName()?>");
+SlideController.initialize(<?php echo self::json($this->view->gallery, array('view_links' => true)) ?>, <?php echo $imageIndex ?>, "<?php echo $GLOBALS['registry']->get('webroot')?>", <?php echo $this->gallery->id ?>, "<?php echo $this->gallery->getName()?>");
 //]]>
 
 function stopSlideShow()