Author: jablko
Date: Sun Oct 17 16:36:07 2010
New Revision: 8200
Log:
Factor relationships into components
Added:
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/relatedAuthorityRecordsComponent.class.php
- copied, changed from r8196,
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/relatedFunctionsComponent.class.php
- copied, changed from r8196,
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/relatedResourcesComponent.class.php
- copied, changed from r8196,
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php
Modified:
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/templates/editSuccess.php
Modified:
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php
==============================================================================
---
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php
Sun Oct 17 12:38:28 2010 (r8199)
+++
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php
Sun Oct 17 16:36:07 2010 (r8200)
@@ -40,56 +40,20 @@
'language',
'script',
'sources',
- 'maintenanceNotes',
- 'relation[authorizedFormOfName]',
- 'relation[category]',
- 'relation[description]',
- 'relation[startDate]',
- 'relation[endDate]',
- 'relation[dateDisplay]',
- 'relatedEntity[object]',
- 'relatedEntity[description]',
- 'relatedEntity[startDate]',
- 'relatedEntity[endDate]',
- 'relatedEntity[dateDisplay]',
- 'relatedResource[object]',
- 'relatedResource[description]',
- 'relatedResource[startDate]',
- 'relatedResource[endDate]',
- 'relatedResource[dateDisplay]');
+ 'maintenanceNotes');
protected function earlyExecute()
{
parent::earlyExecute();
- // Find function to function relations with current function as subject or
- // object
- $criteria = new Criteria;
- $criterion1 = $criteria->getNewCriterion(QubitRelation::OBJECT_ID,
$this->resource->id, Criteria::EQUAL);
- $criterion2 = $criteria->getNewCriterion(QubitRelation::SUBJECT_ID,
$this->resource->id, Criteria::EQUAL);
- $criterion1->addOr($criterion2);
- $criteria->add($criterion1);
- $criteria->addAlias('ro', QubitFunction::TABLE_NAME);
- $criteria->addJoin(QubitRelation::OBJECT_ID, 'ro.id');
- $criteria->addAlias('rs', QubitFunction::TABLE_NAME);
- $criteria->addJoin(QubitRelation::SUBJECT_ID, 'rs.id');
- $criteria->addAscendingOrderByColumn(QubitRelation::TYPE_ID);
-
- $this->relatedFunctions = QubitRelation::get($criteria);
-
- // Get actors (object) related to this function (subject)
- $criteria = new Criteria;
- $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
- $criteria->addJoin(QubitRelation::OBJECT_ID, QubitActor::ID);
-
- $this->actorRelations = QubitRelation::get($criteria);
-
- // Get information objects (object) related to this function (subject)
- $criteria = new Criteria;
- $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
- $criteria->addJoin(QubitRelation::OBJECT_ID, QubitInformationObject::ID);
+ $this->relatedFunctionsComponent = new
sfIsdfPluginRelatedFunctionsComponent($this->context, 'sfIsdfPlugin',
'relatedFunctions');
+ $this->relatedFunctionsComponent->execute($this->request);
- $this->infoObjectRelations = QubitRelation::get($criteria);
+ $this->relatedAuthorityRecordsComponent = new
sfIsdfPluginRelatedAuthorityRecordsComponent($this->context, 'sfIsdfPlugin',
'relatedAuthorityRecords');
+ $this->relatedAuthorityRecordsComponent->execute($this->request);
+
+ $this->relatedResourcesComponent = new
sfIsdfPluginRelatedResourcesComponent($this->context, 'sfIsdfPlugin',
'relatedResources');
+ $this->relatedResourcesComponent->execute($this->request);
}
/**
@@ -136,31 +100,6 @@
break;
- case 'relation[authorizedFormOfName]':
- case 'relatedEntity[object]':
- case 'relatedResource[object]':
- $choices = array();
-
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
-
- break;
-
- case 'relation[category]':
- $this->form->setValidator($name, new sfValidatorString);
-
- $choices = array();
- $choices[null] = null;
-
- foreach
(QubitTaxonomy::getTermsById(QubitTaxonomy::ISDF_RELATION_TYPE_ID) as $term)
- {
- $choices[$this->context->routing->generate(null, array($term,
'module' => 'term'))] = $term;
- }
-
- $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
-
- break;
-
case 'authorizedFormOfName':
case 'classification':
case 'dates':
@@ -184,28 +123,6 @@
break;
- case 'relation[startDate]':
- case 'relation[endDate]':
- case 'relation[dateDisplay]':
- case 'relatedEntity[startDate]':
- case 'relatedEntity[endDate]':
- case 'relatedEntity[dateDisplay]':
- case 'relatedResource[startDate]':
- case 'relatedResource[endDate]':
- case 'relatedResource[dateDisplay]':
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormInput);
-
- break;
-
- case 'relation[description]':
- case 'relatedEntity[description]':
- case 'relatedResource[description]':
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormTextarea);
-
- break;
-
default:
return parent::addField($name);
@@ -259,191 +176,4 @@
return parent::processField($field);
}
}
-
- /**
- * Process form
- *
- * @return void
- */
- protected function processForm()
- {
- $this->updateRelations();
- $this->updateOtherRelations('relatedEntity');
- $this->updateOtherRelations('relatedResource');
- $this->deleteRelations();
-
- return parent::processForm();
- }
-
- /**
- * Update function relationships
- */
- protected function updateRelations()
- {
- if (isset($this->request->relations))
- {
- // JavaScript (multiple) relationship update
- $relationsData = $this->request->relations;
- }
- else if (isset($this->request->relation))
- {
- // Non-JavaScript (single) relationship update
- $relationsData = array($this->request->relation);
- }
- else
- {
- return;
- }
-
- // Loop through func events
- foreach ($relationsData as $relationData)
- {
- // Get related function
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['authorizedFormOfName']));
- $relatedFuncId = (isset($params['id'])) ? $params['id'] : null;
- if (null === $relatedFunction = QubitFunction::getById($relatedFuncId))
- {
- continue; // If no related function, skip update
- }
-
- // Get relation
- if (isset($relationData['id']))
- {
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['id']));
-
- if (null === $relation = QubitRelation::getById($params['id']))
- {
- // If a relation id is passed, but relation object doesn't exist then
- // skip this row
- continue;
- }
- }
- else
- {
- $relation = new QubitRelation;
- }
-
- // Set category (typeId)
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['category']));
- $typeId = (isset($params['id'])) ? $params['id'] : null;
- $relation->typeId = $typeId;
-
- $relation->startDate = $relationData['startDate'];
- $relation->endDate = $relationData['endDate'];
-
- // Add notes
- $relation->updateNote($relationData['description'],
QubitTerm::RELATION_NOTE_DESCRIPTION_ID);
- $relation->updateNote($relationData['dateDisplay'],
QubitTerm::RELATION_NOTE_DATE_DISPLAY_ID);
-
- // Default to current function as subject of relationship
- if ($relation->subjectId == $this->resource->id || null ==
$relation->subjectId)
- {
- $relation->object = $relatedFunction;
- $this->resource->relationsRelatedBysubjectId[] = $relation;
- }
- else
- {
- $relation->subject = $relatedFunction;
- $this->resource->relationsRelatedByobjectId[] = $relation;
- }
- }
-
- return $this;
- }
-
- /**
- * Update entity relationships
- */
- protected function updateOtherRelations($formName)
- {
- if (isset($this->request["{$formName}s"]))
- {
- // JavaScript (multiple) relationship update
- $relationsData = $this->request["{$formName}s"];
- }
- else if (isset($this->request[$formName]))
- {
- // Non-JavaScript (single) relationship update
- $relationsData = array($this->request[$formName]);
- }
- else
- {
- return;
- }
-
- // Loop through relation rows
- foreach ($relationsData as $relationData)
- {
- // Get relation
- if (isset($relationData['id']))
- {
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['id']));
-
- if (null === $relation = QubitRelation::getById($params['id']))
- {
- continue; // If we can't find an existing relation, skip this row
- }
- }
- else
- {
- $relation = new QubitRelation;
- }
-
- // Get related information object (object)
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['object']));
- $objectId = (isset($params['id'])) ? $params['id'] : null;
-
- switch ($formName)
- {
- case 'relatedEntity':
- $object = QubitActor::getById($objectId);
-
- break;
-
- case 'relatedResource':
- $object = QubitInformationObject::getById($objectId);
-
- break;
- }
-
- if (null === $object)
- {
- continue; // If no related object, skip update
- }
- else
- {
- $relation->object = $object;
- }
-
- $relation->startDate = $relationData['startDate'];
- $relation->endDate = $relationData['endDate'];
-
- // Add notes
- $relation->updateNote($relationData['description'],
QubitTerm::RELATION_NOTE_DESCRIPTION_ID);
- $relation->updateNote($relationData['dateDisplay'],
QubitTerm::RELATION_NOTE_DATE_DISPLAY_ID);
-
- $this->resource->relationsRelatedBysubjectId[] = $relation;
- }
-
- return $this;
- }
-
- /**
- * Delete all relationships marked for deletion
- */
- protected function deleteRelations()
- {
- if (is_array($deleteRelations = $this->request->deleteRelations))
- {
- foreach ($deleteRelations as $deleteId => $doDelete)
- {
- if (null !== ($relation = QubitRelation::getById($deleteId)))
- {
- $relation->delete();
- }
- }
- }
-
- return $this;
- }
}
Copied and modified:
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/relatedAuthorityRecordsComponent.class.php
(from r8196,
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php)
==============================================================================
---
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php
Sun Oct 17 12:28:49 2010 (r8196, copy source)
+++
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/relatedAuthorityRecordsComponent.class.php
Sun Oct 17 16:36:07 2010 (r8200)
@@ -17,343 +17,54 @@
* along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>.
*/
-class sfIsdfPluginEditAction extends FunctionEditAction
+class sfIsdfPluginRelatedAuthorityRecordsComponent extends sfComponent
{
// Arrays not allowed in class constants
public static
$NAMES = array(
- 'type',
- 'authorizedFormOfName',
- 'parallelName',
- 'otherName',
- 'classification',
- 'dates',
- 'description',
- 'history',
- 'legislation',
- 'descriptionIdentifier',
- 'institutionIdentifier',
- 'rules',
- 'descriptionStatus',
- 'descriptionDetail',
- 'revisionHistory',
- 'language',
- 'script',
- 'sources',
- 'maintenanceNotes',
- 'relation[authorizedFormOfName]',
- 'relation[category]',
- 'relation[description]',
- 'relation[startDate]',
- 'relation[endDate]',
- 'relation[dateDisplay]',
'relatedEntity[object]',
'relatedEntity[description]',
'relatedEntity[startDate]',
'relatedEntity[endDate]',
- 'relatedEntity[dateDisplay]',
- 'relatedResource[object]',
- 'relatedResource[description]',
- 'relatedResource[startDate]',
- 'relatedResource[endDate]',
- 'relatedResource[dateDisplay]');
+ 'relatedEntity[dateDisplay]');
- protected function earlyExecute()
- {
- parent::earlyExecute();
-
- // Find function to function relations with current function as subject or
- // object
- $criteria = new Criteria;
- $criterion1 = $criteria->getNewCriterion(QubitRelation::OBJECT_ID,
$this->resource->id, Criteria::EQUAL);
- $criterion2 = $criteria->getNewCriterion(QubitRelation::SUBJECT_ID,
$this->resource->id, Criteria::EQUAL);
- $criterion1->addOr($criterion2);
- $criteria->add($criterion1);
- $criteria->addAlias('ro', QubitFunction::TABLE_NAME);
- $criteria->addJoin(QubitRelation::OBJECT_ID, 'ro.id');
- $criteria->addAlias('rs', QubitFunction::TABLE_NAME);
- $criteria->addJoin(QubitRelation::SUBJECT_ID, 'rs.id');
- $criteria->addAscendingOrderByColumn(QubitRelation::TYPE_ID);
-
- $this->relatedFunctions = QubitRelation::get($criteria);
-
- // Get actors (object) related to this function (subject)
- $criteria = new Criteria;
- $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
- $criteria->addJoin(QubitRelation::OBJECT_ID, QubitActor::ID);
-
- $this->actorRelations = QubitRelation::get($criteria);
-
- // Get information objects (object) related to this function (subject)
- $criteria = new Criteria;
- $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
- $criteria->addJoin(QubitRelation::OBJECT_ID, QubitInformationObject::ID);
-
- $this->infoObjectRelations = QubitRelation::get($criteria);
- }
-
- /**
- * Add fields to form
- *
- * @param $name string
- * @return void
- */
protected function addField($name)
{
switch ($name)
{
- case 'type':
- $this->form->setDefault('type',
$this->context->routing->generate(null, array($this->resource->type, 'module'
=> 'term')));
- $this->form->setValidator('type', new sfValidatorString);
-
- $choices = array();
- $choices[null] = null;
- foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::FUNCTION_ID) as
$item)
- {
- $choices[$this->context->routing->generate(null, array($item,
'module' => 'term'))] = $item;
- }
-
- $this->form->setWidget('type', new sfWidgetFormSelect(array('choices'
=> $choices)));
-
- break;
-
- case 'maintenanceNotes':
- $this->maintenanceNote = null;
-
- // Check for existing maintenance note related to this object
- $criteria = new Criteria;
- $criteria = $this->resource->addnotesCriteria($criteria);
- $criteria->add(QubitNote::TYPE_ID, QubitTerm::MAINTENANCE_NOTE_ID);
- $note = QubitNote::getOne($criteria);
-
- if (null !== $note)
- {
- $this->form->setDefault('maintenanceNotes', $note->content);
- $this->maintenanceNote = $note;
- }
- $this->form->setValidator('maintenanceNotes', new sfValidatorString);
- $this->form->setWidget('maintenanceNotes', new sfWidgetFormTextarea);
-
- break;
-
- case 'relation[authorizedFormOfName]':
case 'relatedEntity[object]':
- case 'relatedResource[object]':
- $choices = array();
-
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
-
- break;
-
- case 'relation[category]':
- $this->form->setValidator($name, new sfValidatorString);
-
- $choices = array();
- $choices[null] = null;
-
- foreach
(QubitTaxonomy::getTermsById(QubitTaxonomy::ISDF_RELATION_TYPE_ID) as $term)
- {
- $choices[$this->context->routing->generate(null, array($term,
'module' => 'term'))] = $term;
- }
-
- $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
-
- break;
-
- case 'authorizedFormOfName':
- case 'classification':
- case 'dates':
- case 'descriptionIdentifier':
- case 'institutionIdentifier':
- $this->form->setDefault($name, $this->resource[$name]);
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormInput);
-
- break;
-
- case 'history':
- case 'description':
- case 'legislation':
- case 'rules':
- case 'revisionHistory':
- case 'sources':
- $this->form->setDefault($name, $this->resource[$name]);
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormTextarea);
-
- break;
-
- case 'relation[startDate]':
- case 'relation[endDate]':
- case 'relation[dateDisplay]':
case 'relatedEntity[startDate]':
case 'relatedEntity[endDate]':
case 'relatedEntity[dateDisplay]':
- case 'relatedResource[startDate]':
- case 'relatedResource[endDate]':
- case 'relatedResource[dateDisplay]':
$this->form->setValidator($name, new sfValidatorString);
$this->form->setWidget($name, new sfWidgetFormInput);
break;
- case 'relation[description]':
case 'relatedEntity[description]':
- case 'relatedResource[description]':
$this->form->setValidator($name, new sfValidatorString);
$this->form->setWidget($name, new sfWidgetFormTextarea);
break;
-
- default:
-
- return parent::addField($name);
}
}
- /**
- * Process form fields
- *
- * @param $field mixed symfony form widget
- * @return void
- */
- protected function processField($field)
- {
- switch ($field->getName())
- {
- case 'type':
- unset($this->resource->type);
-
- $value = $this->form->getValue($field->getName());
- if (isset($value))
- {
- $params = $this->context->routing->parse(Qubit::pathInfo($value));
- $this->resource->type = $params['_sf_route']->resource;
- }
-
- break;
-
- case 'maintenanceNotes':
- // Check for existing maintenance note related to this object
- $criteria = new Criteria;
- $criteria = $this->resource->addnotesCriteria($criteria);
- $criteria->add(QubitNote::TYPE_ID, QubitTerm::MAINTENANCE_NOTE_ID);
- $note = QubitNote::getOne($criteria);
-
- if (null === $note)
- {
- // Create a maintenance note for this object if one doesn't exist
- $note = new QubitNote;
- $note->typeId = QubitTerm::MAINTENANCE_NOTE_ID;
- }
-
- $note->content = $this->form->getValue('maintenanceNotes');
-
- $this->resource->notes[] = $note;
-
- break;
-
- default:
-
- return parent::processField($field);
- }
- }
-
- /**
- * Process form
- *
- * @return void
- */
protected function processForm()
{
- $this->updateRelations();
$this->updateOtherRelations('relatedEntity');
- $this->updateOtherRelations('relatedResource');
$this->deleteRelations();
-
- return parent::processForm();
}
- /**
- * Update function relationships
- */
- protected function updateRelations()
+ public function execute($request)
{
- if (isset($this->request->relations))
- {
- // JavaScript (multiple) relationship update
- $relationsData = $this->request->relations;
- }
- else if (isset($this->request->relation))
- {
- // Non-JavaScript (single) relationship update
- $relationsData = array($this->request->relation);
- }
- else
- {
- return;
- }
-
- // Loop through func events
- foreach ($relationsData as $relationData)
- {
- // Get related function
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['authorizedFormOfName']));
- $relatedFuncId = (isset($params['id'])) ? $params['id'] : null;
- if (null === $relatedFunction = QubitFunction::getById($relatedFuncId))
- {
- continue; // If no related function, skip update
- }
-
- // Get relation
- if (isset($relationData['id']))
- {
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['id']));
-
- if (null === $relation = QubitRelation::getById($params['id']))
- {
- // If a relation id is passed, but relation object doesn't exist then
- // skip this row
- continue;
- }
- }
- else
- {
- $relation = new QubitRelation;
- }
-
- // Set category (typeId)
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['category']));
- $typeId = (isset($params['id'])) ? $params['id'] : null;
- $relation->typeId = $typeId;
-
- $relation->startDate = $relationData['startDate'];
- $relation->endDate = $relationData['endDate'];
-
- // Add notes
- $relation->updateNote($relationData['description'],
QubitTerm::RELATION_NOTE_DESCRIPTION_ID);
- $relation->updateNote($relationData['dateDisplay'],
QubitTerm::RELATION_NOTE_DATE_DISPLAY_ID);
-
- // Default to current function as subject of relationship
- if ($relation->subjectId == $this->resource->id || null ==
$relation->subjectId)
- {
- $relation->object = $relatedFunction;
- $this->resource->relationsRelatedBysubjectId[] = $relation;
- }
- else
- {
- $relation->subject = $relatedFunction;
- $this->resource->relationsRelatedByobjectId[] = $relation;
- }
- }
+ // Get actors (object) related to this function (subject)
+ $criteria = new Criteria;
+ $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
+ $criteria->addJoin(QubitRelation::OBJECT_ID, QubitActor::ID);
- return $this;
+ $this->actorRelations = QubitRelation::get($criteria);
}
- /**
- * Update entity relationships
- */
protected function updateOtherRelations($formName)
{
if (isset($this->request["{$formName}s"]))
@@ -428,9 +139,6 @@
return $this;
}
- /**
- * Delete all relationships marked for deletion
- */
protected function deleteRelations()
{
if (is_array($deleteRelations = $this->request->deleteRelations))
Copied and modified:
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/relatedFunctionsComponent.class.php
(from r8196,
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php)
==============================================================================
---
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php
Sun Oct 17 12:28:49 2010 (r8196, copy source)
+++
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/relatedFunctionsComponent.class.php
Sun Oct 17 16:36:07 2010 (r8200)
@@ -17,128 +17,23 @@
* along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>.
*/
-class sfIsdfPluginEditAction extends FunctionEditAction
+class sfIsdfPluginRelatedFunctionsComponent extends sfComponent
{
// Arrays not allowed in class constants
public static
$NAMES = array(
- 'type',
- 'authorizedFormOfName',
- 'parallelName',
- 'otherName',
- 'classification',
- 'dates',
- 'description',
- 'history',
- 'legislation',
- 'descriptionIdentifier',
- 'institutionIdentifier',
- 'rules',
- 'descriptionStatus',
- 'descriptionDetail',
- 'revisionHistory',
- 'language',
- 'script',
- 'sources',
- 'maintenanceNotes',
'relation[authorizedFormOfName]',
'relation[category]',
'relation[description]',
'relation[startDate]',
'relation[endDate]',
- 'relation[dateDisplay]',
- 'relatedEntity[object]',
- 'relatedEntity[description]',
- 'relatedEntity[startDate]',
- 'relatedEntity[endDate]',
- 'relatedEntity[dateDisplay]',
- 'relatedResource[object]',
- 'relatedResource[description]',
- 'relatedResource[startDate]',
- 'relatedResource[endDate]',
- 'relatedResource[dateDisplay]');
+ 'relation[dateDisplay]');
- protected function earlyExecute()
- {
- parent::earlyExecute();
-
- // Find function to function relations with current function as subject or
- // object
- $criteria = new Criteria;
- $criterion1 = $criteria->getNewCriterion(QubitRelation::OBJECT_ID,
$this->resource->id, Criteria::EQUAL);
- $criterion2 = $criteria->getNewCriterion(QubitRelation::SUBJECT_ID,
$this->resource->id, Criteria::EQUAL);
- $criterion1->addOr($criterion2);
- $criteria->add($criterion1);
- $criteria->addAlias('ro', QubitFunction::TABLE_NAME);
- $criteria->addJoin(QubitRelation::OBJECT_ID, 'ro.id');
- $criteria->addAlias('rs', QubitFunction::TABLE_NAME);
- $criteria->addJoin(QubitRelation::SUBJECT_ID, 'rs.id');
- $criteria->addAscendingOrderByColumn(QubitRelation::TYPE_ID);
-
- $this->relatedFunctions = QubitRelation::get($criteria);
-
- // Get actors (object) related to this function (subject)
- $criteria = new Criteria;
- $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
- $criteria->addJoin(QubitRelation::OBJECT_ID, QubitActor::ID);
-
- $this->actorRelations = QubitRelation::get($criteria);
-
- // Get information objects (object) related to this function (subject)
- $criteria = new Criteria;
- $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
- $criteria->addJoin(QubitRelation::OBJECT_ID, QubitInformationObject::ID);
-
- $this->infoObjectRelations = QubitRelation::get($criteria);
- }
-
- /**
- * Add fields to form
- *
- * @param $name string
- * @return void
- */
protected function addField($name)
{
switch ($name)
{
- case 'type':
- $this->form->setDefault('type',
$this->context->routing->generate(null, array($this->resource->type, 'module'
=> 'term')));
- $this->form->setValidator('type', new sfValidatorString);
-
- $choices = array();
- $choices[null] = null;
- foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::FUNCTION_ID) as
$item)
- {
- $choices[$this->context->routing->generate(null, array($item,
'module' => 'term'))] = $item;
- }
-
- $this->form->setWidget('type', new sfWidgetFormSelect(array('choices'
=> $choices)));
-
- break;
-
- case 'maintenanceNotes':
- $this->maintenanceNote = null;
-
- // Check for existing maintenance note related to this object
- $criteria = new Criteria;
- $criteria = $this->resource->addnotesCriteria($criteria);
- $criteria->add(QubitNote::TYPE_ID, QubitTerm::MAINTENANCE_NOTE_ID);
- $note = QubitNote::getOne($criteria);
-
- if (null !== $note)
- {
- $this->form->setDefault('maintenanceNotes', $note->content);
- $this->maintenanceNote = $note;
- }
- $this->form->setValidator('maintenanceNotes', new sfValidatorString);
- $this->form->setWidget('maintenanceNotes', new sfWidgetFormTextarea);
-
- break;
-
case 'relation[authorizedFormOfName]':
- case 'relatedEntity[object]':
- case 'relatedResource[object]':
$choices = array();
$this->form->setValidator($name, new sfValidatorString);
@@ -161,123 +56,46 @@
break;
- case 'authorizedFormOfName':
- case 'classification':
- case 'dates':
- case 'descriptionIdentifier':
- case 'institutionIdentifier':
- $this->form->setDefault($name, $this->resource[$name]);
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormInput);
-
- break;
-
- case 'history':
- case 'description':
- case 'legislation':
- case 'rules':
- case 'revisionHistory':
- case 'sources':
- $this->form->setDefault($name, $this->resource[$name]);
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormTextarea);
-
- break;
-
case 'relation[startDate]':
case 'relation[endDate]':
case 'relation[dateDisplay]':
- case 'relatedEntity[startDate]':
- case 'relatedEntity[endDate]':
- case 'relatedEntity[dateDisplay]':
- case 'relatedResource[startDate]':
- case 'relatedResource[endDate]':
- case 'relatedResource[dateDisplay]':
$this->form->setValidator($name, new sfValidatorString);
$this->form->setWidget($name, new sfWidgetFormInput);
break;
case 'relation[description]':
- case 'relatedEntity[description]':
- case 'relatedResource[description]':
$this->form->setValidator($name, new sfValidatorString);
$this->form->setWidget($name, new sfWidgetFormTextarea);
break;
-
- default:
-
- return parent::addField($name);
}
}
- /**
- * Process form fields
- *
- * @param $field mixed symfony form widget
- * @return void
- */
- protected function processField($field)
- {
- switch ($field->getName())
- {
- case 'type':
- unset($this->resource->type);
-
- $value = $this->form->getValue($field->getName());
- if (isset($value))
- {
- $params = $this->context->routing->parse(Qubit::pathInfo($value));
- $this->resource->type = $params['_sf_route']->resource;
- }
-
- break;
-
- case 'maintenanceNotes':
- // Check for existing maintenance note related to this object
- $criteria = new Criteria;
- $criteria = $this->resource->addnotesCriteria($criteria);
- $criteria->add(QubitNote::TYPE_ID, QubitTerm::MAINTENANCE_NOTE_ID);
- $note = QubitNote::getOne($criteria);
-
- if (null === $note)
- {
- // Create a maintenance note for this object if one doesn't exist
- $note = new QubitNote;
- $note->typeId = QubitTerm::MAINTENANCE_NOTE_ID;
- }
-
- $note->content = $this->form->getValue('maintenanceNotes');
-
- $this->resource->notes[] = $note;
-
- break;
-
- default:
-
- return parent::processField($field);
- }
- }
-
- /**
- * Process form
- *
- * @return void
- */
protected function processForm()
{
$this->updateRelations();
- $this->updateOtherRelations('relatedEntity');
- $this->updateOtherRelations('relatedResource');
$this->deleteRelations();
+ }
+
+ public function execute($request)
+ {
+ // Find function to function relations with current function as subject or
+ // object
+ $criteria = new Criteria;
+ $criterion1 = $criteria->getNewCriterion(QubitRelation::OBJECT_ID,
$this->resource->id, Criteria::EQUAL);
+ $criterion2 = $criteria->getNewCriterion(QubitRelation::SUBJECT_ID,
$this->resource->id, Criteria::EQUAL);
+ $criterion1->addOr($criterion2);
+ $criteria->add($criterion1);
+ $criteria->addAlias('ro', QubitFunction::TABLE_NAME);
+ $criteria->addJoin(QubitRelation::OBJECT_ID, 'ro.id');
+ $criteria->addAlias('rs', QubitFunction::TABLE_NAME);
+ $criteria->addJoin(QubitRelation::SUBJECT_ID, 'rs.id');
+ $criteria->addAscendingOrderByColumn(QubitRelation::TYPE_ID);
- return parent::processForm();
+ $this->relations = QubitRelation::get($criteria);
}
- /**
- * Update function relationships
- */
protected function updateRelations()
{
if (isset($this->request->relations))
@@ -351,86 +169,6 @@
return $this;
}
- /**
- * Update entity relationships
- */
- protected function updateOtherRelations($formName)
- {
- if (isset($this->request["{$formName}s"]))
- {
- // JavaScript (multiple) relationship update
- $relationsData = $this->request["{$formName}s"];
- }
- else if (isset($this->request[$formName]))
- {
- // Non-JavaScript (single) relationship update
- $relationsData = array($this->request[$formName]);
- }
- else
- {
- return;
- }
-
- // Loop through relation rows
- foreach ($relationsData as $relationData)
- {
- // Get relation
- if (isset($relationData['id']))
- {
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['id']));
-
- if (null === $relation = QubitRelation::getById($params['id']))
- {
- continue; // If we can't find an existing relation, skip this row
- }
- }
- else
- {
- $relation = new QubitRelation;
- }
-
- // Get related information object (object)
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['object']));
- $objectId = (isset($params['id'])) ? $params['id'] : null;
-
- switch ($formName)
- {
- case 'relatedEntity':
- $object = QubitActor::getById($objectId);
-
- break;
-
- case 'relatedResource':
- $object = QubitInformationObject::getById($objectId);
-
- break;
- }
-
- if (null === $object)
- {
- continue; // If no related object, skip update
- }
- else
- {
- $relation->object = $object;
- }
-
- $relation->startDate = $relationData['startDate'];
- $relation->endDate = $relationData['endDate'];
-
- // Add notes
- $relation->updateNote($relationData['description'],
QubitTerm::RELATION_NOTE_DESCRIPTION_ID);
- $relation->updateNote($relationData['dateDisplay'],
QubitTerm::RELATION_NOTE_DATE_DISPLAY_ID);
-
- $this->resource->relationsRelatedBysubjectId[] = $relation;
- }
-
- return $this;
- }
-
- /**
- * Delete all relationships marked for deletion
- */
protected function deleteRelations()
{
if (is_array($deleteRelations = $this->request->deleteRelations))
Copied and modified:
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/relatedResourcesComponent.class.php
(from r8196,
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php)
==============================================================================
---
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/editAction.class.php
Sun Oct 17 12:28:49 2010 (r8196, copy source)
+++
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/actions/relatedResourcesComponent.class.php
Sun Oct 17 16:36:07 2010 (r8200)
@@ -17,73 +17,19 @@
* along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>.
*/
-class sfIsdfPluginEditAction extends FunctionEditAction
+class sfIsdfPluginRelatedResourcesComponent extends sfComponent
{
// Arrays not allowed in class constants
public static
$NAMES = array(
- 'type',
- 'authorizedFormOfName',
- 'parallelName',
- 'otherName',
- 'classification',
- 'dates',
- 'description',
- 'history',
- 'legislation',
- 'descriptionIdentifier',
- 'institutionIdentifier',
- 'rules',
- 'descriptionStatus',
- 'descriptionDetail',
- 'revisionHistory',
- 'language',
- 'script',
- 'sources',
- 'maintenanceNotes',
- 'relation[authorizedFormOfName]',
- 'relation[category]',
- 'relation[description]',
- 'relation[startDate]',
- 'relation[endDate]',
- 'relation[dateDisplay]',
- 'relatedEntity[object]',
- 'relatedEntity[description]',
- 'relatedEntity[startDate]',
- 'relatedEntity[endDate]',
- 'relatedEntity[dateDisplay]',
'relatedResource[object]',
'relatedResource[description]',
'relatedResource[startDate]',
'relatedResource[endDate]',
'relatedResource[dateDisplay]');
- protected function earlyExecute()
+ public function execute($request)
{
- parent::earlyExecute();
-
- // Find function to function relations with current function as subject or
- // object
- $criteria = new Criteria;
- $criterion1 = $criteria->getNewCriterion(QubitRelation::OBJECT_ID,
$this->resource->id, Criteria::EQUAL);
- $criterion2 = $criteria->getNewCriterion(QubitRelation::SUBJECT_ID,
$this->resource->id, Criteria::EQUAL);
- $criterion1->addOr($criterion2);
- $criteria->add($criterion1);
- $criteria->addAlias('ro', QubitFunction::TABLE_NAME);
- $criteria->addJoin(QubitRelation::OBJECT_ID, 'ro.id');
- $criteria->addAlias('rs', QubitFunction::TABLE_NAME);
- $criteria->addJoin(QubitRelation::SUBJECT_ID, 'rs.id');
- $criteria->addAscendingOrderByColumn(QubitRelation::TYPE_ID);
-
- $this->relatedFunctions = QubitRelation::get($criteria);
-
- // Get actors (object) related to this function (subject)
- $criteria = new Criteria;
- $criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
- $criteria->addJoin(QubitRelation::OBJECT_ID, QubitActor::ID);
-
- $this->actorRelations = QubitRelation::get($criteria);
-
// Get information objects (object) related to this function (subject)
$criteria = new Criteria;
$criteria->add(QubitRelation::SUBJECT_ID, $this->resource->id);
@@ -92,52 +38,10 @@
$this->infoObjectRelations = QubitRelation::get($criteria);
}
- /**
- * Add fields to form
- *
- * @param $name string
- * @return void
- */
protected function addField($name)
{
switch ($name)
{
- case 'type':
- $this->form->setDefault('type',
$this->context->routing->generate(null, array($this->resource->type, 'module'
=> 'term')));
- $this->form->setValidator('type', new sfValidatorString);
-
- $choices = array();
- $choices[null] = null;
- foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::FUNCTION_ID) as
$item)
- {
- $choices[$this->context->routing->generate(null, array($item,
'module' => 'term'))] = $item;
- }
-
- $this->form->setWidget('type', new sfWidgetFormSelect(array('choices'
=> $choices)));
-
- break;
-
- case 'maintenanceNotes':
- $this->maintenanceNote = null;
-
- // Check for existing maintenance note related to this object
- $criteria = new Criteria;
- $criteria = $this->resource->addnotesCriteria($criteria);
- $criteria->add(QubitNote::TYPE_ID, QubitTerm::MAINTENANCE_NOTE_ID);
- $note = QubitNote::getOne($criteria);
-
- if (null !== $note)
- {
- $this->form->setDefault('maintenanceNotes', $note->content);
- $this->maintenanceNote = $note;
- }
- $this->form->setValidator('maintenanceNotes', new sfValidatorString);
- $this->form->setWidget('maintenanceNotes', new sfWidgetFormTextarea);
-
- break;
-
- case 'relation[authorizedFormOfName]':
- case 'relatedEntity[object]':
case 'relatedResource[object]':
$choices = array();
@@ -146,50 +50,6 @@
break;
- case 'relation[category]':
- $this->form->setValidator($name, new sfValidatorString);
-
- $choices = array();
- $choices[null] = null;
-
- foreach
(QubitTaxonomy::getTermsById(QubitTaxonomy::ISDF_RELATION_TYPE_ID) as $term)
- {
- $choices[$this->context->routing->generate(null, array($term,
'module' => 'term'))] = $term;
- }
-
- $this->form->setWidget($name, new sfWidgetFormSelect(array('choices'
=> $choices)));
-
- break;
-
- case 'authorizedFormOfName':
- case 'classification':
- case 'dates':
- case 'descriptionIdentifier':
- case 'institutionIdentifier':
- $this->form->setDefault($name, $this->resource[$name]);
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormInput);
-
- break;
-
- case 'history':
- case 'description':
- case 'legislation':
- case 'rules':
- case 'revisionHistory':
- case 'sources':
- $this->form->setDefault($name, $this->resource[$name]);
- $this->form->setValidator($name, new sfValidatorString);
- $this->form->setWidget($name, new sfWidgetFormTextarea);
-
- break;
-
- case 'relation[startDate]':
- case 'relation[endDate]':
- case 'relation[dateDisplay]':
- case 'relatedEntity[startDate]':
- case 'relatedEntity[endDate]':
- case 'relatedEntity[dateDisplay]':
case 'relatedResource[startDate]':
case 'relatedResource[endDate]':
case 'relatedResource[dateDisplay]':
@@ -198,162 +58,22 @@
break;
- case 'relation[description]':
- case 'relatedEntity[description]':
case 'relatedResource[description]':
$this->form->setValidator($name, new sfValidatorString);
$this->form->setWidget($name, new sfWidgetFormTextarea);
break;
-
- default:
-
- return parent::addField($name);
}
}
- /**
- * Process form fields
- *
- * @param $field mixed symfony form widget
- * @return void
- */
- protected function processField($field)
- {
- switch ($field->getName())
- {
- case 'type':
- unset($this->resource->type);
-
- $value = $this->form->getValue($field->getName());
- if (isset($value))
- {
- $params = $this->context->routing->parse(Qubit::pathInfo($value));
- $this->resource->type = $params['_sf_route']->resource;
- }
-
- break;
-
- case 'maintenanceNotes':
- // Check for existing maintenance note related to this object
- $criteria = new Criteria;
- $criteria = $this->resource->addnotesCriteria($criteria);
- $criteria->add(QubitNote::TYPE_ID, QubitTerm::MAINTENANCE_NOTE_ID);
- $note = QubitNote::getOne($criteria);
-
- if (null === $note)
- {
- // Create a maintenance note for this object if one doesn't exist
- $note = new QubitNote;
- $note->typeId = QubitTerm::MAINTENANCE_NOTE_ID;
- }
-
- $note->content = $this->form->getValue('maintenanceNotes');
-
- $this->resource->notes[] = $note;
-
- break;
-
- default:
-
- return parent::processField($field);
- }
- }
-
- /**
- * Process form
- *
- * @return void
- */
protected function processForm()
{
- $this->updateRelations();
- $this->updateOtherRelations('relatedEntity');
$this->updateOtherRelations('relatedResource');
$this->deleteRelations();
return parent::processForm();
}
- /**
- * Update function relationships
- */
- protected function updateRelations()
- {
- if (isset($this->request->relations))
- {
- // JavaScript (multiple) relationship update
- $relationsData = $this->request->relations;
- }
- else if (isset($this->request->relation))
- {
- // Non-JavaScript (single) relationship update
- $relationsData = array($this->request->relation);
- }
- else
- {
- return;
- }
-
- // Loop through func events
- foreach ($relationsData as $relationData)
- {
- // Get related function
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['authorizedFormOfName']));
- $relatedFuncId = (isset($params['id'])) ? $params['id'] : null;
- if (null === $relatedFunction = QubitFunction::getById($relatedFuncId))
- {
- continue; // If no related function, skip update
- }
-
- // Get relation
- if (isset($relationData['id']))
- {
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['id']));
-
- if (null === $relation = QubitRelation::getById($params['id']))
- {
- // If a relation id is passed, but relation object doesn't exist then
- // skip this row
- continue;
- }
- }
- else
- {
- $relation = new QubitRelation;
- }
-
- // Set category (typeId)
- $params =
$this->context->routing->parse(Qubit::pathInfo($relationData['category']));
- $typeId = (isset($params['id'])) ? $params['id'] : null;
- $relation->typeId = $typeId;
-
- $relation->startDate = $relationData['startDate'];
- $relation->endDate = $relationData['endDate'];
-
- // Add notes
- $relation->updateNote($relationData['description'],
QubitTerm::RELATION_NOTE_DESCRIPTION_ID);
- $relation->updateNote($relationData['dateDisplay'],
QubitTerm::RELATION_NOTE_DATE_DISPLAY_ID);
-
- // Default to current function as subject of relationship
- if ($relation->subjectId == $this->resource->id || null ==
$relation->subjectId)
- {
- $relation->object = $relatedFunction;
- $this->resource->relationsRelatedBysubjectId[] = $relation;
- }
- else
- {
- $relation->subject = $relatedFunction;
- $this->resource->relationsRelatedByobjectId[] = $relation;
- }
- }
-
- return $this;
- }
-
- /**
- * Update entity relationships
- */
protected function updateOtherRelations($formName)
{
if (isset($this->request["{$formName}s"]))
@@ -428,9 +148,6 @@
return $this;
}
- /**
- * Delete all relationships marked for deletion
- */
protected function deleteRelations()
{
if (is_array($deleteRelations = $this->request->deleteRelations))
Modified:
trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/templates/editSuccess.php
==============================================================================
--- trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/templates/editSuccess.php
Sun Oct 17 12:38:28 2010 (r8199)
+++ trunk/plugins/sfIsdfPlugin/modules/sfIsdfPlugin/templates/editSuccess.php
Sun Oct 17 16:36:07 2010 (r8200)
@@ -62,11 +62,11 @@
<legend><?php echo __('Relationships area') ?></legend>
- <?php echo get_partial('relatedFunctions', array('form' => $form)) ?>
+ <?php echo get_partial('relatedFunctions',
$relatedFunctionsComponent->getVarHolder()->getAll()) ?>
- <?php echo get_partial('relatedAuthorityRecords', array('form' => $form))
?>
+ <?php echo get_partial('relatedAuthorityRecords',
$relatedAuthorityRecordsComponent->getVarHolder()->getAll()) ?>
- <?php echo get_partial('relatedResources', array('form' => $form)) ?>
+ <?php echo get_partial('relatedResources',
$relatedResourcesComponent->getVarHolder()->getAll()) ?>
</fieldset>
--
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.