Parent category may not become a child category of its own child category or categories.
$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)
//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,
*
* @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