Alexander Nicolaysen Sørnes : Move matching of categories in SQL statements to a separate functions

Alexander Nicolaysen Sørnes asornes at winehq.org
Sun Aug 9 10:53:17 CDT 2009


Module: appdb
Branch: master
Commit: 0fe5512f08392647b183d25332f6f5581dbc43ea
URL:    http://source.winehq.org/git/appdb.git/?a=commit;h=0fe5512f08392647b183d25332f6f5581dbc43ea

Author: Alexander Nicolaysen Sørnes <alex at thehandofagony.com>
Date:   Sun Aug  9 15:38:38 2009 +0200

Move matching of categories in SQL statements to a separate functions

---

 include/application.php |   18 ++----------------
 include/category.php    |   17 +++++++++++++++++
 2 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/include/application.php b/include/application.php
index 75f1bb5..256afa1 100644
--- a/include/application.php
+++ b/include/application.php
@@ -1022,14 +1022,7 @@ class Application {
         if($aOptions['appCategory'])
         {
             $oCategory = new Category($aOptions['appCategory']);
-            $aSubCats = $oCategory->getSubCatList();
-            $sWhereFilter .= " AND ( catId = '{$aOptions['appCategory']}' ";
-            foreach($aSubCats as $oCat)
-            {
-                $iCatId = $oCat->objectGetId();
-                $sWhereFilter .= " OR catId = '$iCatId' ";
-            }
-            $sWhereFilter .= ") ";
+            $sWhereFilter .= ' AND ' . $oCategory->getSqlQueryPart();
         }
         /* Should we add a limit clause to the query? */
         if($iRows || $iStart)
@@ -1278,14 +1271,7 @@ class Application {
         if($aOptions['appCategory'])
         {
             $oCategory = new Category($aOptions['appCategory']);
-            $aSubCats = $oCategory->getSubCatList();
-            $sWhereFilter .= " AND ( catId = '{$aOptions['appCategory']}' ";
-            foreach($aSubCats as $oCat)
-            {
-                $iCatId = $oCat->objectGetId();
-                $sWhereFilter .= " OR catId = '$iCatId' ";
-            }
-            $sWhereFilter .= ") ";
+            $sWhereFilter .= ' AND ' . $oCategory->getSqlQueryPart();
         }
 
         if($sState != 'accepted' && !application::canEdit())
diff --git a/include/category.php b/include/category.php
index daab5be..6156d1a 100644
--- a/include/category.php
+++ b/include/category.php
@@ -176,6 +176,23 @@ class Category {
         return $aCats;
     }
 
+    /* Returns an SQL statement that will match items in the current category
+       and all sub-categories */
+    public function getSqlQueryPart()
+    {
+        $sRet = '';
+        $aSubCats = $this->getSubCatList();
+        $sRet .= " ( catId = '{$this->iCatId}' ";
+        foreach($aSubCats as $oCat)
+        {
+            $iCatId = $oCat->objectGetId();
+            $sRet .= " OR catId = '$iCatId' ";
+        }
+        $sRet .= ") ";
+
+        return $sRet;
+    }
+
     function objectGetMail($sAction, $bMailSubmitter, $bParentAction)
     {
         /* We don't send notification mails */




More information about the wine-cvs mailing list