Skip to content

Commit

Permalink
Fix update function for 'Language and script notes'. (#13657)
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung authored and melanie kung committed Sep 24, 2023
1 parent 7b7ffdb commit f26368b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
37 changes: 37 additions & 0 deletions lib/model/QubitObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,45 @@ public function getStatus($options = [])
return QubitStatus::getOne($criteria);
}

/**
* Check to see if note is saved in memory (field was updated).
*
*
* Used by ISAD, DACS, and RAD templates when duplicating a description,
* specifcally for updating the 'Language and script notes' field.
*
* @param array $options
*
* @return array $notes
*/
public function getMemoryNotesByType(array $options = [])
{
// Check memory for notes
if (count($this->notes) > 0)
{
$noteTypeId = $options['noteTypeId'];
$notes = new ArrayObject();

foreach($this->notes as $note)
{
if ($note->typeId == $noteTypeId)
{
$notes->append($note);
}
}

if (count($notes) > 0)
{
return $notes;
}
}

return $this->getNotesByType($options);
}

public function getNotesByType(array $options = [])
{

$criteria = new Criteria();
$criteria->addJoin(QubitNote::TYPE_ID, QubitTerm::ID);
$criteria->add(QubitNote::OBJECT_ID, $this->id);
Expand Down
2 changes: 1 addition & 1 deletion plugins/sfIsadPlugin/lib/sfIsadPlugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __set($name, $value)
{
switch ($name) {
case 'languageNotes':
$note = $this->resource->getNotesByType(['noteTypeId' => QubitTerm::LANGUAGE_NOTE_ID])->offsetGet(0);
$note = $this->resource->getMemoryNotesByType(['noteTypeId' => QubitTerm::LANGUAGE_NOTE_ID])->offsetGet(0);
$missingNote = 0 === count($note);

if (0 == strlen($value)) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/sfRadPlugin/lib/sfRadPlugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function setProperty($name, $value)
return $this;

case 'languageNotes':
$note = $this->resource->getNotesByType(['noteTypeId' => QubitTerm::LANGUAGE_NOTE_ID])->offsetGet(0);
$note = $this->resource->getMemoryNotesByType(['noteTypeId' => QubitTerm::LANGUAGE_NOTE_ID])->offsetGet(0);
$missingNote = 0 === count($note);

if (0 == strlen($value)) {
Expand Down

0 comments on commit f26368b

Please sign in to comment.