Author: david
Date: Fri Dec 11 13:09:17 2009
New Revision: 4150
Log:
Defer save of relation notes until save of parent QubitRelation object.
Modified:
trunk/apps/qubit/modules/actor/actions/editAction.class.php
trunk/lib/model/QubitRelation.php
Modified: trunk/apps/qubit/modules/actor/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/actor/actions/editAction.class.php Fri Dec 11
13:06:56 2009 (r4149)
+++ trunk/apps/qubit/modules/actor/actions/editAction.class.php Fri Dec 11
13:09:17 2009 (r4150)
@@ -312,13 +312,19 @@
$relation->setStartDate(QubitDate::standardize($actorRelationRow['startDate']));
$relation->setEndDate(QubitDate::standardize($actorRelationRow['endDate']));
- // Save new relation and related actor
- $relatedActor->save();
- $relation->save();
-
// Add notes (after save of $relation so we have an object_id)
$relation->updateNote($actorRelationRow['description'],
QubitTerm::RELATION_NOTE_DESCRIPTION_ID);
$relation->updateNote($actorRelationRow['dateDisplay'],
QubitTerm::RELATION_NOTE_DATE_DISPLAY_ID);
+
+ // Add relation to appropriate array
+ if ($this->actor->id == $relation->objectId)
+ {
+ $this->actor->relationsRelatedByobjectId[] = $relation;
+ }
+ else
+ {
+ $this->actor->relationsRelatedBysubjectId[] = $relation;
+ }
}
return $this;
Modified: trunk/lib/model/QubitRelation.php
==============================================================================
--- trunk/lib/model/QubitRelation.php Fri Dec 11 13:06:56 2009 (r4149)
+++ trunk/lib/model/QubitRelation.php Fri Dec 11 13:09:17 2009 (r4150)
@@ -235,10 +235,10 @@
}
/**
- * Get opposite vertex of relation
+ * Get opposite vertex of relation
*
* @param integer $referenceId primary key of reference object
- * @return mixed other object in relationship
+ * @return mixed other object in relationship
*/
public function getOpposedObject($referenceId)
{
@@ -265,19 +265,17 @@
public function addNote($text, $noteTypeId)
{
// Don't create a note with a blank text or a null noteTypeId
- if (0 == strlen($text) || null == $noteTypeId)
+ if (0 < strlen($text) && 0 !== intval($noteTypeId))
{
- return;
- }
+ $newNote = new QubitNote;
+ $newNote->setScope('QubitRelation');
+ $newNote->setContent($text);
+ $newNote->setTypeId($noteTypeId);
- $newNote = new QubitNote;
- $newNote->setObjectId($this->getId());
- $newNote->setScope('QubitRelation');
- $newNote->setContent($text);
- $newNote->setTypeId($noteTypeId);
- $newNote->save();
+ $this->notes[] = $newNote;
+ }
- return $newNote;
+ return $this;
}
/**
@@ -289,22 +287,36 @@
*/
public function updateNote($text, $noteTypeId)
{
- if (null === ($currentNote = $this->getNoteByTypeId($noteTypeId)))
+ $existingNote = false;
+ foreach ($this->notes as $key => $note)
{
-
- return $this->addNote($text, $noteTypeId);
+ if ($note->typeId == $noteTypeId)
+ {
+ if (0 == strlen($text))
+ {
+ // If $text is blank, then delete note object
+ $note->delete();
+ unset($this->notes[$key]);
+ }
+ else
+ {
+ // Update existing note
+ $note->setContent($text);
+ }
+
+ $existingNote = true;
+ break;
+ }
}
- else if (0 == strlen($text))
+
+ if (false === $existingNote)
{
- // If $text is blank, then delete note object
- $currentNote->delete();
+ // Add new note
+ return $this->addNote($text, $noteTypeId);
}
else
{
- $currentNote->setContent($text);
- $currentNote->save();
-
- return $currentNote;
+ 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.com/group/qubit-commits?hl=en.