Users may not use main category (Producto) for ads
authorGusa <gu.martinm@gmail.com>
Sat, 15 Dec 2012 01:35:42 +0000 (02:35 +0100)
committerGusa <gu.martinm@gmail.com>
Sat, 15 Dec 2012 01:35:42 +0000 (02:35 +0100)
OMFG This is the last change.

lib/form/doctrine/AdForm.class.php
lib/model/doctrine/CompanyCategoryTable.class.php

index ac00b08..00e8c9b 100644 (file)
@@ -17,7 +17,7 @@ class AdForm extends BaseAdForm
     $this->useFields(array('company_categ_id', 'ad_mobile_image'));
 
     //Narrow down the valid options for some field validators
-    $companyCategs = CompanyCategoryTable::getInstance()->getCompanyCategoriesByCompanyIdQuery($this->getOption('company_user_id'));
+    $companyCategs = CompanyCategoryTable::getInstance()->getCompanyCategoriesByCompanyIdQuerySkipMain($this->getOption('company_user_id'));
 
     //The default value is not good enough for us. We need narrow down the results.
     $this->widgetSchema['company_categ_id'] = new sfWidgetFormDoctrineChoice(array('model'    => $this->getModelName(),
index 03b68be..4abbe2b 100644 (file)
@@ -27,16 +27,29 @@ class CompanyCategoryTable extends Doctrine_Table
     {
         if ($currentCategory != null)
         {
-            return $this->createQuery('cc')->where('cc.level != ?', '0')
-                                           ->andWhere('cc.company_id = ?', $companyId)
+            return $this->createQuery('cc')->where('cc.level = ?', '0')
+                                           ->orWhere('cc.company_id = ?', $companyId)
                                            ->andWhere('cc.lft > ? or cc.lft < ?', array($currentRgt, $currentLft))
                                            ->orderBy('cc.lft');
         }
         else
         {
             return $this->createQuery('cc')->where('cc.company_id = ?', $companyId)
-                                           ->andWhere('cc.level != ?', '0')
+                                           ->orWhere('cc.level = ?', '0')
                                            ->orderBy('cc.lft');
         }
     }
+
+
+   /**
+    * Returns company categories by company id skipping the main category called Producto.
+    *
+    * @return related company categories to a company as Doctrine Query
+    */
+    public function getCompanyCategoriesByCompanyIdQuerySkipMain($companyId)
+    {
+        return $this->createQuery('cc')->where('cc.company_id = ?', $companyId)
+                                       ->andWhere('cc.level != ?', '0')
+                                       ->orderBy('cc.lft');
+    }
 }