diff --git a/library/Class/Album.php b/library/Class/Album.php index 7fa5482b491ceda5b2b09edeee8b9efae60b4866..a2dec9d6792b8d4fc88c288e5d190857d66ba68d 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -788,20 +788,37 @@ class Class_Album extends Storm_Model_Abstract { public function beforeSave() { $this->updateDateMaj(); $this->collectAuthors(); + $this->collectEditors(); } public function collectAuthors() { - if (!isset($this->_attributes['authors'])) - return; - $authors = $this->_attributes['authors']; - unset($this->_attributes['authors']); + xdebug_break(); + $authors = $this->_collect('authors',self::AUTHOR_FIELD); + if(isset($authors['author'])) + foreach($authors['author'] as $k => $v) + $this->addAuthor($v, $authors['fonction'][$k]); + } - $this->clearZones(self::AUTHOR_FIELD); - foreach($authors['author'] as $k => $v) - $this->addAuthor($v, $authors['fonction'][$k]); + + public function collectEditors() { + $editors = $this->_collect('editors', self::EDITOR_FIELD); + if(isset($editors['editor'])) + foreach($editors['editor'] as $k => $v) + $this->addEditor($v); } + + protected function _collect($field, $zone) { + if (!isset($this->_attributes[$field])) + return []; + $fields = $this->_attributes[$field]; + unset($this->_attributes[$field]); + + $this->clearZones($zone); + return $fields; + } + public function updateDateMaj() { $this->setDateMaj(date('Y-m-d H:i:s', self::getTimeSource()->time())); @@ -1296,7 +1313,6 @@ class Class_Album extends Storm_Model_Abstract { foreach($notes as $k => $v){ if (is_array($v) && isset($v['field']) && $v['field'] == $field) { $notes[$k]['data'][] = [$subfield, $value]; - return $this; } } return $this->addZone($field, [[$subfield, $value]]); @@ -1304,30 +1320,37 @@ class Class_Album extends Storm_Model_Abstract { public function clearZones($zone) { - return $this->setNotes($this->_clearZones($zone)); + return $this->setNotes($this->_clearZones([$zone])); } /** @return string */ public function getNotesForPseudoNotice() { - return serialize($this->_clearZones(self::AUTHOR_FIELD)); + return serialize($this->_clearZones([self::AUTHOR_FIELD, self::EDITOR_FIELD])); } - protected function _clearZones($zone) { + protected function _clearZones($zones) { $notes = $this->getNotesAsArray(); $to_delete = []; - foreach($notes as $k => $note) - if (is_array($note) && $note['field'] == $zone) - $to_delete[] = $k; - + foreach($zones as $zone) + $to_delete = array_merge($to_delete, $this->_clearZone($zone,$notes)); + foreach($to_delete as $i) unset($notes[$i]); - + return $notes; } + protected function _clearZone($zone, $notes) { + $to_delete=[]; + foreach($notes as $k => $note) + if (is_array($note) && $note['field'] == $zone) + $to_delete[] = $k; + return $to_delete; + } + public function acceptVisitor($visitor) { $visitor->visitAlbum($this); @@ -1401,6 +1424,23 @@ class Class_Album extends Storm_Model_Abstract { } + /** + * Editor from unimarc container + * @return array + */ + public function getEditors() { + $values = []; + $datas=$this->getDatasOfField(Class_Album::EDITOR_FIELD); + foreach($datas as $data){ + foreach($data as $value) { + if ($value[0] == 'c') + $values[] = $value[1]; + } + } + return $values; + } + + /** * add author in unimarc container if not present with the same function */ diff --git a/tests/application/modules/admin/controllers/AlbumControllerTest.php b/tests/application/modules/admin/controllers/AlbumControllerTest.php index 979605a10c78f31bb6db9f011b384bbe37c5f9dd..79b2c03102e5d4f0d7bf10363616714224629774 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerTest.php @@ -695,6 +695,7 @@ class Admin_AlbumControllerPostAlbumRenaissanceToPatrimoineTest extends Admin_Al 'pcdm4' => '0683;0684', 'author' => ['pba', 'lla'], 'fonction' => ['realisateur', 'bassiste'], + 'editor' => ['Glo' , 'Pba'], 'duration' => '00:04:08']); $this->new_album = Class_Album::findFirstBy(['order'=>'id desc']); $this->new_notice = $this->new_album->getNotice(); @@ -737,6 +738,20 @@ class Admin_AlbumControllerPostAlbumRenaissanceToPatrimoineTest extends Admin_Al $this->assertEquals('2;3', $this->new_album->getNatureDoc()); } + + /** @test */ + public function shouldHaveEditorGlo() { + $this->assertContains('Glo', $this->new_album->getEditors()); + } + + + /** @test */ + public function shouldHaveEditorPba() { + $this->assertContains('Pba', $this->new_album->getEditors()); + } + + + /** @test */ public function pseudoNoticeShouldBeIndexed() { $this->assertNotNull($this->new_notice);