From a345a56f5b0551999c6c898d5865ee64e1b8afc6 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Tue, 11 Dec 2012 05:17:47 +0100 Subject: [PATCH] Fixed error. While editing company categories. Parent category may not become a child category of its own child category or categories. --- apps/companyfront/modules/category/actions/actions.class.php | 4 +++- lib/form/doctrine/CompanyCategoryForm.class.php | 4 +++- lib/model/doctrine/CompanyCategoryTable.class.php | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/companyfront/modules/category/actions/actions.class.php b/apps/companyfront/modules/category/actions/actions.class.php index fca69a5..b902fcc 100644 --- a/apps/companyfront/modules/category/actions/actions.class.php +++ b/apps/companyfront/modules/category/actions/actions.class.php @@ -75,7 +75,9 @@ class categoryActions extends sfActions $this->forward404Unless($companyId == $companyUserId, sprintf('Category does not exist (%s).', $request->getParameter('id'))); - $this->form = new CompanyCategoryForm($company_category, array('company_user_id' => $companyUserId, 'current_category' => $companyCategoryId)); + $this->form = new CompanyCategoryForm($company_category, array('company_user_id' => $companyUserId, 'current_category' => $companyCategoryId, + 'current_category_lft' => $company_category->getLft(), + 'current_category_rgt' => $company_category->getRgt())); } public function executeUpdate(sfWebRequest $request) diff --git a/lib/form/doctrine/CompanyCategoryForm.class.php b/lib/form/doctrine/CompanyCategoryForm.class.php index d894346..2fee475 100644 --- a/lib/form/doctrine/CompanyCategoryForm.class.php +++ b/lib/form/doctrine/CompanyCategoryForm.class.php @@ -20,7 +20,9 @@ class CompanyCategoryForm extends BaseCompanyCategoryForm //Narrow down the valid options for some field validators $companyCategs = CompanyCategoryTable::getInstance()->getCompanyCategoriesByCompanyIdQuery($this->getOption('company_user_id'), - $this->getOption('current_category')); + $this->getOption('current_category'), + $this->getOption('current_category_lft'), + $this->getOption('current_category_rgt')); $this->widgetSchema['parent_category'] = new sfWidgetFormDoctrineChoice(array('model' => $this->getModelName(), 'add_empty' => false, diff --git a/lib/model/doctrine/CompanyCategoryTable.class.php b/lib/model/doctrine/CompanyCategoryTable.class.php index 69c4b1d..0d4bafc 100644 --- a/lib/model/doctrine/CompanyCategoryTable.class.php +++ b/lib/model/doctrine/CompanyCategoryTable.class.php @@ -23,13 +23,13 @@ class CompanyCategoryTable extends Doctrine_Table * * @return related company categories to a company as Doctrine Query */ - public function getCompanyCategoriesByCompanyIdQuery($companyId, $currentCategory = null) + public function getCompanyCategoriesByCompanyIdQuery($companyId, $currentCategory = null, $currentLft = null, $currentRgt = null) { if ($currentCategory != null) { - return $this->createQuery('cc')->where('cc.company_id = ?', $companyId) - ->andWhere('cc.id != ?', $currentCategory) - ->orWhere('cc.level = ?', '0') + 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 -- 2.1.4