Author: jablko
Date: Wed Oct 27 14:28:37 2010
New Revision: 8570
Log:
Use $route->resource, fixes issue 1850
Modified:
trunk/apps/qubit/modules/informationobject/actions/editPhysicalObjectsAction.class.php
Modified:
trunk/apps/qubit/modules/informationobject/actions/editPhysicalObjectsAction.class.php
==============================================================================
---
trunk/apps/qubit/modules/informationobject/actions/editPhysicalObjectsAction.class.php
Wed Oct 27 14:01:06 2010 (r8569)
+++
trunk/apps/qubit/modules/informationobject/actions/editPhysicalObjectsAction.class.php
Wed Oct 27 14:28:37 2010 (r8570)
@@ -52,8 +52,8 @@
switch ($name)
{
case 'containers':
- $this->form->setValidator('containers', new sfValidatorString);
- $this->form->setWidget('containers', new
sfWidgetFormSelect(array('choices' => array())));
+ $this->form->setValidator('containers', new sfValidatorPass);
+ $this->form->setWidget('containers', new
sfWidgetFormSelect(array('choices' => array(), 'multiple' => true)));
break;
@@ -76,92 +76,54 @@
protected function processForm()
{
- $this->deleteRelations();
- $this->updatePhysicalObjects();
- }
-
- public function execute($request)
- {
- parent::execute($request);
-
- $this->relations =
QubitRelation::getRelationsByObjectId($this->resource->id, array('typeId' =>
QubitTerm::HAS_PHYSICAL_OBJECT_ID));
-
- if ($request->isMethod('post'))
+ foreach ($this->form->getValue('containers') as $item)
{
- $this->form->bind($request->getPostParameters());
-
- if ($this->form->isValid())
- {
- $this->processForm();
-
- $this->resource->save();
-
- $this->redirect(array($this->resource, 'module' =>
'informationobject'));
- }
+ $params = $this->context->routing->parse(Qubit::pathInfo($item));
+ $this->resource->addPhysicalObject($params['_sf_route']->resource);
}
- }
- public function updatePhysicalObjects()
- {
- // Preferentially use "new container" input data over the selector so that
- // new object data is not lost (but only if an object name is entered)
- if (0 < strlen($this->form->getValue('name')))
+ $value = $this->form->getValue('name');
+ if (isset($value))
{
$physicalObject = new QubitPhysicalObject;
-
- $physicalObject->name = $this->form->getValue('name');
-
+ $physicalObject->name = $value;
$physicalObject->location = $this->form->getValue('location');
$params =
$this->context->routing->parse(Qubit::pathInfo($this->form->getValue('type')));
- if (isset($params['id']))
- {
- $physicalObject->typeId = $params['id'];
- }
+ $physicalObject->type = $params['_sf_route']->resource;
$physicalObject->save();
- // Link info object to physical object
$this->resource->addPhysicalObject($physicalObject);
}
- // If form is not populated, add any existing physical objects that are
- // selected
- else if ($physicalObjectIds = $this->form->getValue('containers'))
+ if (isset($this->request->delete_relations))
{
- // Make sure that $physicalObjectIds is an array, even if it's only got
- // one value
- $physicalObjectIds = (is_array($physicalObjectIds)) ? $physicalObjectIds
: array($physicalObjectIds);
-
- foreach ($physicalObjectIds as $physicalObjectId)
+ foreach ($this->request->delete_relations as $item)
{
- // If a value is set for this select box, and the physical object
- // exists, add a relation to this info object
- $params =
$this->context->routing->parse(Qubit::pathInfo($physicalObjectId));
- if (isset($params['id']))
- {
- if (null !== $physicalObject =
QubitPhysicalObject::getById($params['id']))
- {
- $this->resource->addPhysicalObject($physicalObject);
- }
- }
+ $params = $this->context->routing->parse(Qubit::pathInfo($item));
+ $params['sf_route']->resource->delete();
}
}
}
- /**
- * Delete related physical objects marked for deletion.
- *
- * @param sfRequest request object
- */
- public function deleteRelations()
+ public function execute($request)
{
- if (isset($this->request->delete_relations))
+ parent::execute($request);
+
+ $this->relations =
QubitRelation::getRelationsByObjectId($this->resource->id, array('typeId' =>
QubitTerm::HAS_PHYSICAL_OBJECT_ID));
+
+ if ($request->isMethod('post'))
{
- foreach ($this->request->delete_relations as $item)
+ $this->form->bind($request->getPostParameters());
+
+ if ($this->form->isValid())
{
- $params = $this->context->routing->parse(Qubit::pathInfo($item));
- $params['sf_route']->resource->delete();
+ $this->processForm();
+
+ $this->resource->save();
+
+ $this->redirect(array($this->resource, 'module' =>
'informationobject'));
}
}
}
--
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.