From: Gusa Date: Sat, 15 Dec 2012 01:35:42 +0000 (+0100) Subject: Users may not use main category (Producto) for ads X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=80d80fa11015c51b8ecf22ff107dc4a5860466b8;p=mobi%2F.git Users may not use main category (Producto) for ads OMFG This is the last change. --- diff --git a/lib/form/doctrine/AdForm.class.php b/lib/form/doctrine/AdForm.class.php index ac00b08..00e8c9b 100644 --- a/lib/form/doctrine/AdForm.class.php +++ b/lib/form/doctrine/AdForm.class.php @@ -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(), diff --git a/lib/model/doctrine/CompanyCategoryTable.class.php b/lib/model/doctrine/CompanyCategoryTable.class.php index 03b68be..4abbe2b 100644 --- a/lib/model/doctrine/CompanyCategoryTable.class.php +++ b/lib/model/doctrine/CompanyCategoryTable.class.php @@ -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'); + } }