Author: jablko Date: Wed Oct 27 17:09:36 2010 New Revision: 8578 Log: Extend default edit action
Modified: trunk/apps/qubit/modules/physicalobject/actions/editAction.class.php Modified: trunk/apps/qubit/modules/physicalobject/actions/editAction.class.php ============================================================================== --- trunk/apps/qubit/modules/physicalobject/actions/editAction.class.php Wed Oct 27 17:08:31 2010 (r8577) +++ trunk/apps/qubit/modules/physicalobject/actions/editAction.class.php Wed Oct 27 17:09:36 2010 (r8578) @@ -25,7 +25,7 @@ * @author David Juhasz <[email protected]> * @version SVN: $Id */ -class PhysicalObjectEditAction extends sfAction +class PhysicalObjectEditAction extends DefaultEditAction { public static $NAMES = array( @@ -33,6 +33,15 @@ 'name', 'type'); + protected function earlyExecute() + { + $this->resource = new QubitPhysicalObject; + if (isset($this->getRoute()->resource)) + { + $this->resource = $this->getRoute()->resource; + } + } + protected function addField($name) { switch ($name) @@ -48,76 +57,41 @@ case 'type': $this->form->setDefault('type', $this->context->routing->generate(null, array($this->resource->type, 'module' => 'term'))); $this->form->setValidator('type', new sfValidatorString); - - $choices = QubitTerm::getIndentedChildTree(QubitTerm::CONTAINER_ID, ' ', array('returnObjectInstances' => true)); - $this->form->setWidget('type', new sfWidgetFormSelect(array('choices' => $choices))); + $this->form->setWidget('type', new sfWidgetFormSelect(array('choices' => QubitTerm::getIndentedChildTree(QubitTerm::CONTAINER_ID, ' ', array('returnObjectInstances' => true))))); break; + + default: + + return parent::addField($name); } } protected function processField($field) { - switch ($name = $field->getName()) + switch ($field->getName()) { - case 'location': - case 'name': - $this->resource[$name] = $this->form->getValue($name); - - break; - case 'type': unset($this->resource->type); $params = $this->context->routing->parse(Qubit::pathInfo($this->form->getValue('type'))); - if (isset($params['id'])) - { - $this->resource->typeId = $params['id']; - } + $this->resource->type = $params['_sf_route']->resource; break; - } - } - protected function processForm() - { - foreach ($this->form as $field) - { - if (isset($this->request[$field->getName()])) - { - $this->processField($field); - } + default: + + return parent::processField($field); } } public function execute($request) { - $this->form = new sfForm; - - $this->resource = new QubitPhysicalObject; - - if (isset($request->id)) - { - $this->resource = QubitPhysicalObject::getById($request->id); - - if (!isset($this->resource)) - { - $this->forward404(); - } - } - - // HACK: Use static::$NAMES in PHP 5.3, - // http://php.net/oop5.late-static-bindings - $class = new ReflectionClass($this); - foreach ($class->getStaticPropertyValue('NAMES') as $name) - { - $this->addField($name); - } + parent::execute($request); if ($request->isMethod('post')) { $this->form->bind($request->getPostParameters()); - if ($this->form->isValid()) { $this->processForm(); -- You received this message because you are subscribed to the Google Groups "Qubit Toolkit Commits" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/qubit-commits?hl=en.
