$this->forward404Unless($companyOfficeId == $companyUserId, sprintf('Category does not exist (%s).', $request->getParameter('id')));
- $this->form = new CompanyCategoryForm($company_category);
+ $this->form = new CompanyCategoryForm($company_category, array('company_user_id' => $companyUserId));
$this->processForm($request, $this->form);
'required' => true,
'query' => $companyCategs));
- if (!$this->getObject()->isNew())
- {
- $this->setDefault('parent_category', $this->getObject()->getNode()->getParent()->getId());
- }
$this->widgetSchema->setLabels(array('parent_category' => 'Parent Company Category'));
$this->widgetSchema->setLabels(array('general_categ_id' => 'General Category'));
$companyCateg = CompanyCategoryTable::getInstance()->findOneById($this->values['parent_category']);
//Second one, right here
- $this->getObject()->getNode()->insertAsFirstChildOf($companyCateg);
+ //First of all, we have to check if this node already has a parent
+ if ($this->getObject()->getNode()->getParent() != null)
+ {
+ //We have to move the node
+ $this->getObject()->getNode()->moveAsFirstChildOf($companyCateg);
+ }
+ else
+ {
+ //We have to insert the node
+ $this->getObject()->getNode()->insertAsFirstChildOf($companyCateg);
+ }
+ }
+
+ /**
+ * Overriding updateDefaultsFromObject method from lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php
+ *
+ */
+ protected function updateDefaultsFromObject()
+ {
+ parent::updateDefaultsFromObject();
+
+ if (!$this->getObject()->isNew())
+ {
+ $this->setDefault('parent_category', $this->getObject()->getNode()->getParent()->getId());
+ }
}
}
*/
public function getCompanyCategoriesByCompanyIdQuery($companyId)
{
- return $this->createQuery('cg')->where('cg.company_id = ?', $companyId)
- ->orWhere('cg.id = ?', '1')
- ->orderBy('cg.id');
+ return $this->createQuery('cc')->where('cc.company_id = ?', $companyId)
+ ->orWhere('cc.id = ?', '1')
+ ->orderBy('cc.lft');
}
}