From 80d80fa11015c51b8ecf22ff107dc4a5860466b8 Mon Sep 17 00:00:00 2001 From: Gusa Date: Sat, 15 Dec 2012 02:35:42 +0100 Subject: [PATCH] Users may not use main category (Producto) for ads OMFG This is the last change. --- lib/form/doctrine/AdForm.class.php | 2 +- lib/model/doctrine/CompanyCategoryTable.class.php | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) 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'); + } } -- 2.1.4