From 8d1a3bcc0ecf80a11b759bdb467685d56781e21c Mon Sep 17 00:00:00 2001
From: pbarroca <pbarroca@afi-sa.fr>
Date: Mon, 20 Jan 2014 12:36:21 +0100
Subject: [PATCH] =?UTF-8?q?Bibnum=20:=20Ajout=20dur=C3=A9e=20totale=20sur?=
 =?UTF-8?q?=20les=20albums?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 library/Class/Album.php                       | 11 +++++++++
 library/ZendAfi/Form/Album.php                | 19 ++++++++++++++-
 .../admin/controllers/AlbumControllerTest.php | 23 ++++++++++++++++---
 3 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/library/Class/Album.php b/library/Class/Album.php
index cbb6e0fcc3a..bed0523b932 100644
--- a/library/Class/Album.php
+++ b/library/Class/Album.php
@@ -71,6 +71,7 @@ class Class_Album extends Storm_Model_Abstract {
 	const DEFAULT_CODE_LANGUE = 'fre';
 	const VIDEO_URL_FIELD = '856';
 	const VIDEO_URL_TYPE = 'video';
+	const DURATION_FIELD = '215$a';
 	const URI_TYPE_POSTER = 'poster';
 	const URI_TYPE_TRAILER = 'trailer';
 	const URI_TYPE_PHOTO = 'photo';
@@ -1017,6 +1018,16 @@ class Class_Album extends Storm_Model_Abstract {
 				'data' => ['x' => self::VIDEO_URL_TYPE, 'a' => $url]]]);
 	}
 
+
+	public function getDuration() {
+		return $this->getNote(self::DURATION_FIELD);
+	}
+
+	
+	public function setDuration($hh_mm_ss) {
+		return $this->addNote(self::DURATION_FIELD, $hh_mm_ss);
+	}
+
 		
 	public function setNotes($array_or_string) {
 		if (is_array($array_or_string)) 
diff --git a/library/ZendAfi/Form/Album.php b/library/ZendAfi/Form/Album.php
index 38e5dd8496e..535d9b1b434 100644
--- a/library/ZendAfi/Form/Album.php
+++ b/library/ZendAfi/Form/Album.php
@@ -27,6 +27,7 @@ class ZendAfi_Form_Album extends ZendAfi_Form {
 
 		$form
 			->populate($album->toArray())
+			->addDurationFor($album)
 			->addRightsFor($album)
 			->addVignetteFor($album)
 			->addFileFor($album)
@@ -51,6 +52,7 @@ class ZendAfi_Form_Album extends ZendAfi_Form {
 												 'cote',
 												 'editeur',
 												 'provenance',
+												 'duration',
 												 'id_langue',
 												 'type_doc_id',
 												 'nature_doc',
@@ -70,7 +72,19 @@ class ZendAfi_Form_Album extends ZendAfi_Form {
 		return $form;
 	}
 
-		
+
+	public function addDurationFor($album) {
+		$this->duration->setValue($album->getDuration());
+		return $this;
+	}
+
+
+	public function addEditorFor($album) {
+		$this->editor->setValue($album->getEditor());
+		return $this;
+	}
+
+
 	public function init() {
 		parent::init();
 		Class_ScriptLoader::getInstance()
@@ -117,6 +131,9 @@ class ZendAfi_Form_Album extends ZendAfi_Form {
 			->addElement('text', 'provenance', ['label' => 'Provenance', 
 																					'size' => 75])
 
+			->addElement('text', 'duration', ['label' => 'Durée totale', 
+																				'size' => 8])
+
 			->addElement('select', 'id_langue', ['label' => 'Langue', 
 																					 'multioptions' => Class_CodifLangue::allByIdLibelle()])
 
diff --git a/tests/application/modules/admin/controllers/AlbumControllerTest.php b/tests/application/modules/admin/controllers/AlbumControllerTest.php
index d343e42708b..44f2d9849a8 100644
--- a/tests/application/modules/admin/controllers/AlbumControllerTest.php
+++ b/tests/application/modules/admin/controllers/AlbumControllerTest.php
@@ -683,7 +683,8 @@ class Admin_AlbumControllerPostAlbumRenaissanceToPatrimoineTest extends Admin_Al
 												 'type_doc_id' => '102',
 												 'genre' => '32;23',
 												 'dewey' => '0277;0285',
-												 'pcdm4' => '0683;0684']);
+												 'pcdm4' => '0683;0684',
+												 'duration' => '00:04:08',]);
 
 		$this->new_album = Class_Album::findFirstBy(['order'=>'id desc']);
 		$this->new_notice = $this->new_album->getNotice();
@@ -743,12 +744,14 @@ class Admin_AlbumControllerPostAlbumRenaissanceToPatrimoineTest extends Admin_Al
 		$this->assertContains('G23', explode(' ', $this->new_notice->getFacettes()));
 	}
 
+
   /** @test */
 	public function shouldHaveFacetDeweyLecture() {
 		$this->assertContains('D0277',  explode(' ', $this->new_notice->getFacettes()));
 	}
 
- /** @test */
+
+	/** @test */
 	public function shouldHaveFacetPcdm4() {
 		$this->assertContains('P0683',  explode(' ', $this->new_notice->getFacettes()));
 	}
@@ -760,6 +763,10 @@ class Admin_AlbumControllerPostAlbumRenaissanceToPatrimoineTest extends Admin_Al
 	}
 
 
+	/** @test */
+	public function shouldHave215aDuration() {
+		$this->assertContains('00:04:08', $this->new_notice->get_subfield('215', 'a'));
+	}
 }
 
 
@@ -824,7 +831,9 @@ class Admin_AlbumControllerEditAlbumMesBDTest extends Admin_AlbumControllerTestC
 			->setCatId(2)
 			->setBibliotheques('74')
 			->setAnnexes('73;93')
-			->setSections('42');
+			->setSections('42')
+			->setDuration('00:05:00')
+			->save();
 		$this->dispatch('/admin/album/edit_album/id/43', true);
 	}
 
@@ -1027,6 +1036,7 @@ class Admin_AlbumControllerEditAlbumMesBDTest extends Admin_AlbumControllerTestC
 		$this->assertXPath("//input[@name='annexes'][@value='73;93']");
 	}
 
+
 	/** @test */
 	public function tagSelectionAnnexesShouldContainsArchives() {
 		$this->assertXPathContentContains('//div[@id="annexes_saisie"]',
@@ -1046,10 +1056,17 @@ class Admin_AlbumControllerEditAlbumMesBDTest extends Admin_AlbumControllerTestC
 		$this->assertXPath("//input[@name='sections'][@value='42']");
 	}
 
+
 	/** @test */
 	public function pcdm4ShouldDisplayedMusiqueDessin() {
 		$this->assertXPath("//input[@name='pcdm4'][@value='Musique;Dessin']");
 	}
+
+
+	/** @test */
+	public function durationShouldDisplayFiveMinutes() {
+		$this->assertXPath('//input[@name="duration"][@value="00:05:00"]');
+	}
 }
 
 
-- 
GitLab