From 5156db70b6bd735b1110f931749a466795276935 Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-loas.afi-sa.net>
Date: Wed, 5 Feb 2014 12:09:26 +0100
Subject: [PATCH] rel #8257 refacto editors album

---
 library/Class/Album.php        | 12 ++++++++++++
 library/ZendAfi/Form/Album.php | 20 +++++++++-----------
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/library/Class/Album.php b/library/Class/Album.php
index 28e9b011a0f..7fa5482b491 100644
--- a/library/Class/Album.php
+++ b/library/Class/Album.php
@@ -77,6 +77,7 @@ class Class_Album extends Storm_Model_Abstract {
 	const URI_TYPE_PHOTO = 'photo';
 	const URI_TYPE_EXTERNAL_URI = 'external_uri';
 	const AUTHOR_FIELD = '701';
+	const EDITOR_FIELD = '210';
 	
 	
 	protected static $DEFAULT_THUMBNAIL_VALUES;
@@ -1010,6 +1011,17 @@ class Class_Album extends Storm_Model_Abstract {
 		}
 	}
 
+	
+	public function getDatasOfField($field) {
+		return array_filter(
+			array_map(
+				function($note) use ($field) {
+					return is_array($note) && $field === $note['field'] ? 
+						$note['data'] : null;
+				},
+				$this->getNotesAsArray()));
+	}
+	
 
 	/** @return string */
 	public function getVideoUrl() {
diff --git a/library/ZendAfi/Form/Album.php b/library/ZendAfi/Form/Album.php
index 427766087cd..c242365bd89 100644
--- a/library/ZendAfi/Form/Album.php
+++ b/library/ZendAfi/Form/Album.php
@@ -97,11 +97,10 @@ class ZendAfi_Form_Album extends ZendAfi_Form {
 
 	public function addAuthorsFor($album) {
 		$values = ['author' => [], 'fonction' => []];
-		foreach($album->getNotesAsArray() as $note) {
-			if (!is_array($note) || '701' != $note['field'])
-				continue;
-			$values['author'][] = $note['data']['a'];
-			$values['fonction'][] = $note['data']['4'];
+		$datas=$album->getDatasOfField(Class_Album::AUTHOR_FIELD);
+		foreach($datas as $data) {
+			$values['author'][] = $data['a'];
+			$values['fonction'][] = $data['4'];
 		}
 		$this->authors->setValues($values);
 		return $this;
@@ -110,12 +109,11 @@ class ZendAfi_Form_Album extends ZendAfi_Form {
 
 	public function addEditorsFor($album) {
 		$values = ['editor' => []];
-		foreach($album->getNotesAsArray() as $note) {
-			if (!is_array($note) || '210' != $note['field'])
-				continue;
-			foreach($note['data'] as $data) {
-				if ($data[0] == 'c')
-					$values['editor'][] = $data[1];
+		$datas=$album->getDatasOfField(Class_Album::EDITOR_FIELD);
+		foreach($datas as $data){
+			foreach($data as $value) {
+				if ($value[0] == 'c')
+					$values['editor'][] = $value[1];
 			}
 		}
 		$this->editors->setValues($values);
-- 
GitLab