Author: david
Date: Thu Dec 10 15:38:49 2009
New Revision: 4141
Log:
Save ISDF relationships.
Modified:
trunk/apps/qubit/modules/function/actions/editAction.class.php
Modified: trunk/apps/qubit/modules/function/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/function/actions/editAction.class.php Thu Dec
10 13:35:33 2009 (r4140)
+++ trunk/apps/qubit/modules/function/actions/editAction.class.php Thu Dec
10 15:38:49 2009 (r4141)
@@ -27,6 +27,11 @@
*/
class FunctionEditAction extends sfAction
{
+ /**
+ * Define form field names
+ *
+ * @var string
+ */
public static $NAMES = array(
'type',
'authorizedFormOfName',
@@ -56,6 +61,12 @@
'relation[dateDisplay]'
);
+ /**
+ * Add fields to form
+ *
+ * @param $name string
+ * @return void
+ */
protected function addField($name)
{
switch ($name)
@@ -248,6 +259,12 @@
}
+ /**
+ * Process form fields
+ *
+ * @param $field mixed symfony form widget
+ * @return void
+ */
protected function processField($field)
{
switch ($name = $field->getName())
@@ -343,6 +360,11 @@
}
}
+ /**
+ * Process form
+ *
+ * @return void
+ */
protected function processForm()
{
foreach ($this->form as $field)
@@ -350,27 +372,19 @@
$this->processField($field);
}
- //Actor Relations
- //TODO
- //$this->funcRelations = $this->func->getActorRelations();
- //$this->funcRelationCategories =
QubitTaxonomy::getTermsById(QubitTaxonomy::ACTOR_RELATION_TYPE_ID);
-
- //Related resources (events)
- //TODO
- //$this->events = $this->func->getEvents();
- //$this->eventTypes =
QubitTerm::getOptionsForSelectList(QubitTaxonomy::EVENT_TYPE_ID);
- //$this->resourceTypeTerms =
array(QubitTerm::getById(QubitTerm::ARCHIVAL_MATERIAL_ID));
-
- // TODO
- //$this->updateActorRelations();
- //$this->deleteActorRelations();
- //$this->updateEvents();
- //$this->deleteEvents();
+ $this->updateRelations();
+ $this->deleteRelations();
// Save function after updating it's attributes
$this->func->save();
}
+ /**
+ * Execute edit action
+ *
+ * @param $request sfWebRequest
+ * @see lib/vendor/symfony/lib/action/sfAction
+ */
public function execute($request)
{
$this->form = new sfForm;
@@ -418,7 +432,7 @@
{
$this->processForm();
- $this->redirect(array('module' => 'function', 'action' => 'show', 'id'
=> $this->func->id));
+ //$this->redirect(array('module' => 'function', 'action' => 'show',
'id' => $this->func->id));
}
}
@@ -426,113 +440,19 @@
}
/**
- * Update func relationships
- *
- * @return ActorEditAction $this object
+ * Update function relationships
*/
- protected function updateActorRelations()
+ protected function updateRelations()
{
- if ($this->hasRequestParameter('updateActorRelations'))
+ if ($this->hasRequestParameter('relations'))
{
- // Data from YUI dialog
- $funcRelationData = $this->getRequestParameter('updateActorRelations');
+ // Javascript (multiple) relationship update
+ $relationsData = $this->getRequestParameter('relations');
}
- else
+ else if ($this->hasRequestParameter('relation'))
{
- // Data from plain html folm
- $funcRelationData =
array($this->getRequestParameter('editActorRelation'));
- }
-
- foreach ($funcRelationData as $funcRelationRow)
- {
- // If no func name specified then don't update this func relation
- if (0 == strlen($relatedActorName = $funcRelationRow['funcName']))
- {
- continue;
- }
-
- // If related func doesn't exist, create a new func
- if (null === ($relatedActor =
QubitActor::getByAuthorizedFormOfName($relatedActorName)))
- {
- $relatedActor = new QubitActor;
- $relatedActor->setAuthorizedFormOfName($relatedActorName);
- $relatedActor->save();
- }
-
- // Create/edit relation
- if (isset($funcRelationRow['id']))
- {
- if (null === ($relation =
QubitRelation::getById($funcRelationRow['id'])))
- {
- throw new sfException('Relation id '.$funcRelationRow['id'].' does
not exist.');
- }
- else
- {
- // Update related func based on current direction of relationship
- if ($this->func->getId() == $relation->getSubjectId())
- {
- $relation->setObjectId($relatedActor->getId());
- }
- else if ($this->func->getId() == $relation->getObjectId())
- {
- $relation->setSubjectId($relatedActor->getId());
- }
- else
- {
- throw new sfException('Invalid relation.');
- }
- }
- }
- else
- {
- $relation = new QubitRelation;
- $relation->setSubjectId($this->func->getId());
- $relation->setObjectId($relatedActor->getId());
- }
-
- $relation->setTypeId($funcRelationRow['categoryId']);
-
$relation->setStartDate(QubitDate::standardize($funcRelationRow['startDate']));
-
$relation->setEndDate(QubitDate::standardize($funcRelationRow['endDate']));
-
- // Save new relation and related func
- $relatedActor->save();
- $relation->save();
-
- // Add notes (after save of $relation so we have an object_id)
- $relation->updateNote($funcRelationRow['description'],
QubitTerm::RELATION_NOTE_DESCRIPTION_ID);
- $relation->updateNote($funcRelationRow['dateDisplay'],
QubitTerm::RELATION_NOTE_DATE_DISPLAY_ID);
- }
-
- return $this;
- }
-
- protected function deleteActorRelations()
- {
- if ($this->hasRequestParameter('deleteRelations'))
- {
- foreach ((array) $this->getRequestParameter('deleteRelations') as
$relationId => $value)
- {
- $relation = QubitRelation::getById($relationId);
- $relation->delete();
- }
- }
- }
- /**
- * Add or update events related to this func
- *
- * @return ActorEditAction this object
- */
- protected function updateEvents()
- {
- if ($this->hasRequestParameter('updateEvents'))
- {
- // The 'updateEvents' array is created by the funcEventDialog.js
- $updateEvents = $this->getRequestParameter('updateEvents');
- }
- else if ($this->hasRequestParameter('newEvent'))
- {
- // The 'newEvent' array means a non-javascript form submission
- $updateEvents = array($this->getRequestParameter('newEvent'));
+ // Non-javascript (single) relationship update
+ $relationsData = array($this->getRequestParameter('relation'));
}
else
{
@@ -540,80 +460,64 @@
}
// Loop through func events
- foreach ($updateEvents as $eventFormData)
+ foreach ($relationsData as $relationData)
{
- // Create new event or update an existing one
- if (isset($eventFormData['id']))
+ // Get relation
+ if (isset($relationData['id']))
{
- if (null === $event = QubitEvent::getById($eventFormData['id']))
+ if (null === $relation = QubitRelation::getById($relationData['id']))
{
continue; // If we can't find the object, then skip this row
}
}
else
{
- $event = new QubitEvent;
+ $relation = new QubitRelation;
}
- // Assign resource to event
- if (0 == strlen($eventFormData['resourceTitle']))
+ // Get name
+ if (null === $subject =
QubitFunction::getById($relationData['authorizedFormOfName']))
{
- continue; // If no resource name, don't update event
+ continue; // If no related subject, skip update
}
else
{
- // Create resource object (only type is "archival material" right now)
- if (QubitTerm::ARCHIVAL_MATERIAL_ID ==
$eventFormData['resourceTypeId'])
- {
- // Check if info object already exists
- $criteria = new Criteria;
- $criteria->addJoin(QubitInformationObject::ID,
QubitInformationObjectI18n::ID, Criteria::INNER_JOIN);
- $criteria->add(QubitInformationObjectI18n::TITLE,
$eventFormData['resourceTitle'], Criteria::EQUAL);
- if (null === ($resource = QubitInformationObject::getOne($criteria)))
- {
- $resource = new QubitInformationObject;
- $resource->setTitle($eventFormData['resourceTitle']);
- $resource->setCollectionTypeId($eventFormData['resourceTypeId']);
- $resource->setParentId(QubitInformationObject::ROOT_ID);
- $resource->save();
- }
- }
- else
- {
- continue;
- }
-
- // Assign resource to event
- $event->setInformationObjectId($resource->getId());
+ $relation->subject = $subject;
}
- // Update other event properties
- $event->setActorId($this->func->getId());
- $event->setTypeId($eventFormData['typeId']);
- $event->setDateDisplay($eventFormData['dateDisplay']);
-
$event->setStartDate(QubitDate::standardize($eventFormData['startDate']));
- $event->setEndDate(QubitDate::standardize($eventFormData['endDate']));
+ // Set type_id
+ $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['type']));
+ $typeId = (isset($params['id'])) ? $params['id'] : null;
+ $relation->typeId = $typeId;
- $event->save();
+ $relation->startDate =
QubitDate::standardize($relationData['dateStart']);
+ $relation->endDate = QubitDate::standardize($relationData['dateEnd']);
+
+ // TODO object term relation
+ // $relations->categoryId = $relationsData['categoryId'];
+
+ // TODO notes
+ //$relations->dateDisplay = $relationsData['dateDisplay'];
+ //$relations->description = $relationsData['description'];
+
+ $this->func->relationsRelatedByobjectId[] = $relation;
}
return $this;
}
/**
- * Delete related events that are marked for deletion.
- *
- * @return ActorEditAction $this object
+ * Delete function relationships
*/
- public function deleteEvents()
+ public function deleteRelations()
{
- if (is_array($deleteEvents = $this->getRequestParameter('deleteEvents'))
&& count($deleteEvents))
+ if (is_array($deleteRelations =
$this->getRequestParameter('deleteRelations')) && count($deleteRelations))
{
- foreach ($deleteEvents as $deleteId => $doDelete)
+ foreach ($deleteRelations as $deleteId => $doDelete)
{
- if (null !== ($event = QubitEvent::getById($deleteId)))
+ if (null !== ($relation = QubitRelation::getById($deleteId)))
{
- $event->delete();
+ $relation->delete();
}
}
}
--
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.