Author: david
Date: Mon Aug 31 16:59:44 2009
New Revision: 3133
Log:
When a new preferred term is chosen for a group of equivalent terms, update
related information objects with the preferred term.
Modified:
trunk/apps/qubit/modules/term/actions/editAction.class.php
Modified: trunk/apps/qubit/modules/term/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/term/actions/editAction.class.php Mon Aug 31
15:52:19 2009 (r3132)
+++ trunk/apps/qubit/modules/term/actions/editAction.class.php Mon Aug 31
16:59:44 2009 (r3133)
@@ -128,6 +128,10 @@
}
$this->term->save();
+
+ // For equivalence relations make sure existing info objects use the
+ // preferred term
+ $this->updateInfoObjectPreferredTerms();
}
public function addNote($content, $typeId)
@@ -208,7 +212,6 @@
$relation->setTypeId(QubitTerm::TERM_RELATION_EQUIVALENCE_ID);
$relation->setObjectId($relatedTerm->getId());
$this->term->relationsRelatedBysubjectId[] = $relation;
- break;
}
}
@@ -279,4 +282,50 @@
}
}
}
+
+ public function updateInfoObjectPreferredTerms()
+ {
+ // Get non-preferred terms
+ $nonPrefIds = array();
+ if (0 < count($objectTerms =
$this->term->getEquivalentTerms(array('direction' => 'subjectToObject'))))
+ {
+ foreach ($objectTerms as $objectTerm)
+ {
+ $nonPrefIds[] = $objectTerm->id;
+ }
+ }
+
+ // Get preferred term
+ if (null !== ($preferredTerms =
$this->term->getEquivalentTerms(array('direction' => 'objectToSubject'))))
+ {
+ $preferredTerm = $preferredTerms->offsetGet(0);
+ $nonPrefIds[] = $this->term->id;
+ }
+ else if (0 < count($nonPrefIds))
+ {
+ $preferredTerm = $this->term;
+ }
+ else
+ {
+ // Don't do anything if there are no equivalent terms
+ return $this;
+ }
+
+ // Replace non-preferred terms with preferred term for related info objects
+ $criteria = new Criteria;
+ $criteria->add(QubitObjectTermRelation::TERM_ID, $nonPrefIds,
Criteria::IN);
+ if (0 < count($objectTermRelations =
QubitObjectTermRelation::get($criteria)))
+ {
+ foreach ($objectTermRelations as $objectTermRelation)
+ {
+ if ($objectTermRelation->getObject() instanceof QubitInformationObject)
+ {
+ $objectTermRelation->termId = $preferredTerm->id;
+ $objectTermRelation->save();
+ }
+ }
+ }
+
+ return $this;
+ }
}
--~--~---------~--~----~------------~-------~--~----~
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.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---