$this->forward404Unless($companyId == $companyUserId, sprintf('Category does not exist (%s).', $request->getParameter('id')));
- $this->form = new CompanyCategoryForm($company_category, array('company_user_id' => $companyUserId));
+ $this->form = new CompanyCategoryForm($company_category, array('company_user_id' => $companyUserId, 'current_category' => $companyCategoryId));
}
public function executeUpdate(sfWebRequest $request)
$this->useFields(array('general_categ_id'));
//Narrow down the valid options for some field validators
- $companyCategs = CompanyCategoryTable::getInstance()->getCompanyCategoriesByCompanyIdQuery($this->getOption('company_user_id'));
+ $companyCategs = CompanyCategoryTable::getInstance()->getCompanyCategoriesByCompanyIdQuery($this->getOption('company_user_id'),
+ $this->getOption('current_category'));
$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)
+ public function getCompanyCategoriesByCompanyIdQuery($companyId, $currentCategory = null)
{
- return $this->createQuery('cc')->where('cc.company_id = ?', $companyId)
- ->orWhere('cc.id = ?', '1')
- ->orderBy('cc.lft');
+ if ($currentCategory != null)
+ {
+ return $this->createQuery('cc')->where('cc.company_id = ?', $companyId)
+ ->andWhere('cc.id != ?', $currentCategory)
+ ->orWhere('cc.id = ?', '1')
+ ->orderBy('cc.lft');
+ }
+ else
+ {
+ return $this->createQuery('cc')->where('cc.company_id = ?', $companyId)
+ ->orWhere('cc.id = ?', '1')
+ ->orderBy('cc.lft');
+ }
}
}