Author: sevein
Date: Thu Apr 19 14:12:27 2012
New Revision: 11475

Log:
Create DefaultBrowseAction class, modify repository browser controller to 
extend it

Added:
   branches/2.0/apps/qubit/modules/default/actions/browseAction.class.php
Modified:
   branches/2.0/apps/qubit/modules/repository/actions/browseAction.class.php

Added: branches/2.0/apps/qubit/modules/default/actions/browseAction.class.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ branches/2.0/apps/qubit/modules/default/actions/browseAction.class.php      
Thu Apr 19 14:12:27 2012        (r11475)
@@ -0,0 +1,54 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+class DefaultBrowseAction extends sfAction
+{
+  protected $query;
+
+  protected function addFacet($name)
+  {
+    $facet = new Elastica_Facet_Terms($name);
+    $facet->setField($name);
+    $facet->setSize(50);
+
+    $this->query->addFacet($facet);
+  }
+
+  public function execute($request)
+  {
+    $this->earlyExecute();
+
+    if (empty($request->limit))
+    {
+      $request->limit = sfConfig::get('app_hits_per_page');
+    }
+
+    $this->query->setLimit($request->limit);
+
+    if (!empty($request->page))
+    {
+      $this->query->setFrom(($request->page - 1) * $request->limit);
+    }
+
+    foreach ($this::$FACETS as $name)
+    {
+      $this->addFacet($name);
+    }
+  }
+}

Modified: 
branches/2.0/apps/qubit/modules/repository/actions/browseAction.class.php
==============================================================================
--- branches/2.0/apps/qubit/modules/repository/actions/browseAction.class.php   
Thu Apr 19 13:45:04 2012        (r11474)
+++ branches/2.0/apps/qubit/modules/repository/actions/browseAction.class.php   
Thu Apr 19 14:12:27 2012        (r11475)
@@ -24,24 +24,13 @@
  * @version    svn:$Id$
  */
 
-class RepositoryBrowseAction extends sfAction
+class RepositoryBrowseAction extends DefaultBrowseAction
 {
-  protected $query;
-
   public static
     $FACETS = array(
       'types',
       'contact.i18n.region');
 
-  protected function addFacet($name)
-  {
-    $facet = new Elastica_Facet_Terms($name);
-    $facet->setField($name);
-    $facet->setSize(50);
-
-    $this->query->addFacet($facet);
-  }
-
   protected function buildFacetTable($name, $facet)
   {
     $ids = array();
@@ -81,29 +70,22 @@
         }
 
         break;
-    }
-  }
 
-  public function execute($request)
-  {
-    if (empty($request->limit))
-    {
-      $request->limit = sfConfig::get('app_hits_per_page');
-    }
+      default:
 
-    $this->query = new Elastica_Query(new Elastica_Query_MatchAll());
+        return parent::buildFacetTable($name);
 
-    foreach ($this::$FACETS as $facet)
-    {
-      $this->addFacet($facet);
     }
+  }
 
-    $this->query->setLimit($request->limit);
+  protected function earlyExecute()
+  {
+    $this->query = new Elastica_Query(new Elastica_Query_MatchAll());
+  }
 
-    if (!empty($request->page))
-    {
-      $this->query->setFrom(($request->page - 1) * $request->limit);
-    }
+  public function execute($request)
+  {
+    parent::execute($request);
 
     try
     {

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to