diff --git a/library/Class/AlbumRessource.php b/library/Class/AlbumRessource.php index 5521bc47ffbb700107828309fe44cffbba3f4c1f..71078d5b16248c35b767f8e9e42e773a4a5a235d 100644 --- a/library/Class/AlbumRessource.php +++ b/library/Class/AlbumRessource.php @@ -816,6 +816,14 @@ class Class_AlbumRessource extends Storm_Model_Abstract { } + /** + * @return string + */ + protected function humanizeFilename() { + return (new Class_File_Info($this->getFichier()))->humanizeFilename(); + } + + /** * @return string */ @@ -1044,12 +1052,19 @@ class Class_AlbumRessource extends Storm_Model_Abstract { } + public function findTitle() { + return + $this->getTitre() + ? $this->getTitre() + : ($this->getFichier() + ? $this->humanizeFilename() + : $this->getFolio()); + } + + public function acceptVisitor($visitor) { $view_helper = (new ZendAfi_Controller_Action_Helper_View()); - if (!$titre = $this->getTitre()) - $titre = $this->getFolio(); - - $visitor->visitRessourceDatas($titre, + $visitor->visitRessourceDatas($this->findTitle(), $this->getDuration(), $this->getAuthorsNames(), $view_helper->album_PlayRessourceUrl($this)); diff --git a/library/Class/File/Info.php b/library/Class/File/Info.php new file mode 100644 index 0000000000000000000000000000000000000000..15f8441ef996ef92b05cb1574e4cd6af3ddd6212 --- /dev/null +++ b/library/Class/File/Info.php @@ -0,0 +1,83 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class Class_File_Info { + protected + $_filepath, + $_path_info; + + /** @param filepath string */ + public function __construct($filepath) { + $this->_filepath = (string)$filepath; + $this->_path_info = $this->_filepath + ? pathinfo($this->_filepath) + : ['dirname' => '', + 'basename' => '', + 'filename' => '', + 'extension' => '']; + } + + + public function humanizeFilename() { + if (!$file = $this->fileNameWithoutExtension()) + return ''; + + $parts = array_filter(preg_split('/[0-9_\*\-\s]+/', $file)); + return ucfirst(implode(' ', array_map('trim',$parts))); + } + + + /** + * @return string + */ + public function fileNameWithoutExtension() { + return $this->_path_info['filename']; + } + + + /** + * @return string + */ + public function fileNameWithExtension() { + return $this->_path_info['basename']; + } + + + /** + * @return string + */ + public function fileExtension() { + return $this->_path_info['extension']; + } + + + /** + * @return string + */ + public function fileSize() { + return file_exists($this->_filepath) + ? filesize($this->_filepath) + : 0; + } +} + + +?> \ No newline at end of file diff --git a/library/Class/Indexation/PseudoNotice.php b/library/Class/Indexation/PseudoNotice.php index c82fff3c9097930a09ad423c242cc6384e7a5282..ca827b5b0703f9fa61e669ee93206377c9da59ea 100644 --- a/library/Class/Indexation/PseudoNotice.php +++ b/library/Class/Indexation/PseudoNotice.php @@ -368,8 +368,9 @@ class Class_Indexation_PseudoNotice_Album extends Class_Indexation_PseudoNotice{ protected function extractTitles() { $titles = [parent::extractTitles()]; - foreach($this->_model->getRessources() as $ressource) - $titles[] = $ressource->getTitre(); + foreach($this->_model->getRessources() as $ressource) { + $titles[] = $ressource->findTitle(); + } return implode(' ', $titles); } diff --git a/library/ZendAfi/View/Helper/Album/RssFeedVisitor.php b/library/ZendAfi/View/Helper/Album/RssFeedVisitor.php index 27dc64870fef612cff9fed473bbaddcb3774be30..ac4aca6cf5217c54a281239c5f10c99f02960e42 100644 --- a/library/ZendAfi/View/Helper/Album/RssFeedVisitor.php +++ b/library/ZendAfi/View/Helper/Album/RssFeedVisitor.php @@ -72,7 +72,7 @@ class ZendAfi_View_Helper_Album_RssFeedVisitor extends Zend_View_Helper_Abstrac $media_url = $this->view->album_PlayRessourceUrl($ressource); $this->appendTags($item = $this->appendTag($this->_channel, 'item'), - ['title' => $ressource->getTitre(), + ['title' => $ressource->findTitle(), 'link' => $media_url, 'itunes:order' => $ressource->getOrdre(), 'guid' => $media_url]); diff --git a/library/ZendAfi/View/Helper/Album/XspfPlaylistVisitor.php b/library/ZendAfi/View/Helper/Album/XspfPlaylistVisitor.php index 6345e86ce8ebcd917f4f1b08f19966f8bd070074..209d621fc63d772b6fdb47b15a8c58fc8f97e1a1 100644 --- a/library/ZendAfi/View/Helper/Album/XspfPlaylistVisitor.php +++ b/library/ZendAfi/View/Helper/Album/XspfPlaylistVisitor.php @@ -40,7 +40,7 @@ class ZendAfi_View_Helper_Album_XspfPlaylistVisitor extends Zend_View_Helper_Ab public function visitRessource($ressource, $index) { $this->_tracks []= $this->_builder->track( - $this->_builder->title($ressource->getTitre()) + $this->_builder->title($ressource->findTitle()) .$this->_builder->image($this->view->absoluteUrl($ressource->getThumbnailUrl())) .$this->_builder->location('<![CDATA['.$this->view->album_PlayRessourceUrl($ressource).']]>') ); diff --git a/library/ZendAfi/View/Helper/AlbumRessourceInfos.php b/library/ZendAfi/View/Helper/AlbumRessourceInfos.php index de47833add7188a83533d55ad3544941d33fb60e..900cab6dc011f560f08617ddf1aefaf854c9b8fd 100644 --- a/library/ZendAfi/View/Helper/AlbumRessourceInfos.php +++ b/library/ZendAfi/View/Helper/AlbumRessourceInfos.php @@ -21,12 +21,15 @@ class ZendAfi_View_Helper_AlbumRessourceInfos extends Zend_View_Helper_HtmlElement { public function albumRessourceInfos($ressource) { - $infos = $this->view->fileInfos($ressource->getOriginalPath()); - - if (!$ressource->hasTitre()) - return $infos; + $file_info = new Class_File_Info($ressource->getOriginalPath()); - return $ressource->getTitre().'<br/>'.$infos; + $description = $file_info->fileExtension(); + if ($size = $file_info->fileSize()) + $description .=', '.$this->view->memoryFormat($size); + + return $ressource->findTitle() + .'<br/>' + .'['.$description.']'; } } diff --git a/library/ZendAfi/View/Helper/FileInfos.php b/library/ZendAfi/View/Helper/FileInfos.php index 36ca529c9cc7379b3694846eaee5d926c3f52b78..d65c97ac7b4fe4b33b84ae35b711b38ec42e4ca9 100644 --- a/library/ZendAfi/View/Helper/FileInfos.php +++ b/library/ZendAfi/View/Helper/FileInfos.php @@ -24,41 +24,12 @@ class ZendAfi_View_Helper_FileInfos extends Zend_View_Helper_Abstract { * @return string */ public function fileInfos($path) { - return $this->fileName($path) . $this->fileSize($path); - } - - - /** - * @param string $path - * @return string - */ - public function fileName($path) { - $parts = explode('/', $path); - return end($parts); - } - - - /** - * @param string $path - * @return string - */ - public function fileExtension($path) { - $parts = explode('.', $path); - return '.' . end($parts); - } - - - /** - * @param string $path - * @return string - */ - public function fileSize($path) { - if (!file_exists($path)) { - return ''; - } - - $size = filesize($path); - return ', ' . $this->view->memoryFormat($size); + $file_info = new Class_File_Info($path); + + $description = $file_info->fileNameWithExtension(); + if ($size = $file_info->fileSize()) + $description .=', '.$this->view->memoryFormat($size); + return $description; } } ?> \ No newline at end of file diff --git a/public/admin/css/global.css b/public/admin/css/global.css index a6af4eaaaf5d24a445c446c99ffa3108d826a1b7..547800e1e9890f9152ecbd98f4636472ff076edf 100644 --- a/public/admin/css/global.css +++ b/public/admin/css/global.css @@ -716,6 +716,7 @@ form#sendparams dd {float: left} .profils li div, .tree li div{ float: left; + text-align: left; } .oldprofils li:hover { diff --git a/tests/application/modules/admin/controllers/AlbumControllerTest.php b/tests/application/modules/admin/controllers/AlbumControllerTest.php index 83c9b64f703676d65420183575fff9c70ad1733c..3ec124b0eb6f8b0b933b8ecec9a7e46cd3f9d92f 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerTest.php @@ -2349,7 +2349,7 @@ class AlbumControllerMultiMediasExportEAD extends ControllerAlbumMultiMediasTest /** @test */ - public function headerShouldContainsContentTypeXspf() { + public function headerShouldContainsContentTypeXml() { $this->assertHeaderContains('Content-Type', 'application/xml'); } diff --git a/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php b/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php index 12093b700312e2758007b17e4a82139970fe1bf5..920efbb55f21cb32b43b7e7b3f92824376b049d9 100644 --- a/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php +++ b/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php @@ -595,7 +595,11 @@ abstract class BibNumeriqueControllerAlbumMultiMediasTestCase extends AbstractCo ->setFichier('moonchild.mpeg') ->setTitre('Iron Maiden: "Moonchild" live') ->setOrdre(6) - ->setPoster('moonchild.jpg')]); + ->setPoster('moonchild.jpg'), + + Class_AlbumRessource::newInstanceWithId(9) + ->setFichier('the_prophecy.mp3') + ->setOrdre(7)]); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AlbumCategorie') ->whenCalled('findAllBy') @@ -701,6 +705,15 @@ class BibNumeriqueControllerAlbumMultiMediasXSPFTest extends BibNumeriqueControl } + /** @test */ + public function seventhTrackTitleShouldBeTheProphecy() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//xspf:playlist/xspf:trackList/xspf:track/xspf:title', + 'The prophecy'); + } + + + /** @test */ public function vimeoTrackLocationShouldBeOriginalUrl() { $this->_xpath->assertXPathContentContains($this->_response->getBody(), @@ -856,6 +869,13 @@ class BibNumeriqueControllerAlbumMultiMediasRSSTest extends BibNumeriqueControll '2'); } + + /** @test */ + public function seventhItemTitleShouldBeTheProphecy() { + $this->_xpath->assertXPathContentContains($this->_response->getBody(), + '//channel/item[7]/title', + 'The prophecy'); + } } diff --git a/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php b/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php index 7794d8dfeadc850c610ea39ead273ec0dfaf20e4..0540887906c68c667ad9e709991be06292589fff 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php @@ -59,6 +59,9 @@ abstract class RechercheControllerAlbumAudioRecordTestCase extends AbstractContr ->addRessource($this->fixture('Class_AlbumRessource', ['id' => 3, 'fichier' => 'unknown.mp3'])) + ->addRessource($this->fixture('Class_AlbumRessource', + ['id' => 4, + 'fichier' => '502_05_the_prophecy.mp3'])) ->assertSave(); $album->index(); @@ -130,13 +133,35 @@ class RechercheControllerAlbumAudioRecordViewNoticeTest extends RechercheControl /** @test */ public function noticeUnknownMorceauTitleShouldBeUnknown() { - $this->assertEquals('unknown', + $this->assertEquals('Unknown', $this->_notice->getMorceaux()['morceaux'][1][3]['titre']); } /** @test */ public function titresFulltextShouldContainsMOONCHILD() { - $this->assertContains('MOONCHILD', $this->_notice->getRawAttributes()['titres']); + $this->assertContains('MOONCHILD', + explode(' ', $this->_notice->getRawAttributes()['titres'])); + } + + + /** @test */ + public function titresFulltextShouldContainsUNKNOWN() { + $this->assertContains('UNKNOWN', + explode(' ', $this->_notice->getRawAttributes()['titres'])); + } + + + /** @test */ + public function titresFulltextShouldContainsPROPHECY() { + $this->assertContains('PROPHECY', + explode(' ', $this->_notice->getRawAttributes()['titres'])); + } + + + /** @test */ + public function titresFulltextShouldNotContains502() { + $this->assertNotContains('502', + explode(' ', $this->_notice->getRawAttributes()['titres'])); } } @@ -206,6 +231,7 @@ class RechercheControllerAlbumAudioRecordViewDetailsTest extends RechercheContro + class RechercheControllerAlbumAudioRecordViewRessourcesNumeriquesTest extends RechercheControllerAlbumAudioRecordTestCase { public function setUp() { parent::setUp(); @@ -226,8 +252,15 @@ class RechercheControllerAlbumAudioRecordViewRessourcesNumeriquesTest extends Re /** @test **/ - public function liShouldBeFileNameUnknown() { - $this->assertXPathContentContains('//ol//li', 'unknown.mp3'); + public function liForUnknownShouldBeFileNameUnknownMp3() { + $this->assertXPathContentContains('//ol//li', 'Unknown'); + $this->assertXPathContentContains('//ol//li', '[mp3]'); + } + + + /** @test **/ + public function liShouldContainsFilenameNameTheProphecy() { + $this->assertXPathContentContains('//ol//li', 'The prophecy'); } @@ -281,8 +314,14 @@ class RechercheControllerAlbumAudioRecordAsTelephoneViewRessourcesNumeriquesTest /** @test **/ - public function liShouldBeFileNameUnknown() { - $this->assertXPathContentContains('//ol//li', 'unknown.mp3'); + public function liShouldContainsFileNameUnknown() { + $this->assertXPathContentContains('//ol//li', 'Unknown'); + } + + + /** @test **/ + public function liShouldContainsFilenameNameTheProphecy() { + $this->assertXPathContentContains('//ol//li', 'The prophecy'); } } ?> \ No newline at end of file diff --git a/tests/library/Class/File/InfoTest.php b/tests/library/Class/File/InfoTest.php new file mode 100644 index 0000000000000000000000000000000000000000..44fbb48aa869694c070a0a89fbc356dad8726a32 --- /dev/null +++ b/tests/library/Class/File/InfoTest.php @@ -0,0 +1,47 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class FileInfoTest extends PHPUnit_Framework_TestCase { + public function fixtures() { + return [ + ['one.mp3', 'One' ], + ['one', 'One'], + ['.mp3', ''], + ['', ''], + [null, ''], + ['dark_vador-the*vilain', 'Dark vador the vilain'], + ['666 beast 111', 'Beast'], + ['le_condamné', 'Le condamné'] + ]; + } + + + /** + * @test + * @dataProvider fixtures + */ + public function humanizeFilenameShouldAnswer($file, $result) { + $this->assertEquals($result, (new Class_File_Info($file))->humanizeFilename()); + } + +} + +?> \ No newline at end of file