Skip to content

Commit

Permalink
Fix update function for 'Language and script notes'. (#13657) (#1664)
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung authored Oct 4, 2023
1 parent a1ebb2f commit 7e25350
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
27 changes: 27 additions & 0 deletions lib/model/QubitObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,33 @@ 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.
*
* @return array $notes
*/
public function getMemoryNotesByType(array $options = [])
{
// Check memory for notes
if (!count($this->notes) < 0) {
return $this->getNotesByType($options);
}

$noteTypeId = $options['noteTypeId'];
$notes = new ArrayObject();

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

return $notes;
}

public function getNotesByType(array $options = [])
{
$criteria = new Criteria();
Expand Down
10 changes: 9 additions & 1 deletion plugins/sfIsadPlugin/lib/sfIsadPlugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,20 @@ 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)) {
// Delete note if it's available
if (!$missingNote) {
// Update deleted note on duplication
if (!isset($value)) {
$note->content = $value;

break;
}

$note->delete();
}

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 7e25350

Please sign in to comment.