Skip to content
Snippets Groups Projects
Commit f5824fab authored by pbarroca's avatar pbarroca
Browse files

OPDS: Affichage des métadonnées sur le flux

parent 9f5a6e3a
Branches
Tags
No related merge requests found
......@@ -20,12 +20,17 @@
*/
class Admin_OpdsController extends Zend_Controller_Action {
public function indexAction() {
public function init() {
$this->view->titre = 'Catalogues OPDS';
$this->view->catalogs = Class_OpdsCatalog::getLoader()->findAllBy(array('order' => 'libelle'));
}
public function indexAction() {
}
public function addAction() {
$this->view->titre = 'Ajouter un catalogue OPDS';
$model = Class_OpdsCatalog::getLoader()->newInstance();
......@@ -85,9 +90,11 @@ class Admin_OpdsController extends Zend_Controller_Action {
if ($entry_url = $this->_getParam('entry'))
$catalog = $catalog->newForEntry($entry_url);
$this->view->titre = sprintf('Parcours du catalogue "%s"', $catalog->getLibelle());
$this->view->entries = $catalog->getEntries();
$this->view->catalogUrl = $catalog->getUrl();
$this->view->subview = $this->view->partial('opds/browse.phtml',
array('titre' => sprintf('Parcours du catalogue "%s"', $catalog->getLibelle()),
'catalog' => $catalog));
$this->render('index');
}
......
<h1><?php echo $this->escape($this->titre);?></h1>
<div class="panel">
<?php if ($metadatas = $this->catalog->getMetadatas()) { ?>
<ul style="list-style:none;">
<?php foreach($metadatas as $k => $v) { ?>
<li><strong><?php echo $this->escape($k);?></strong> : <?php echo $this->escape($v);?></li>
<?php } ?>
</ul>
<?php } ?>
</div>
<ul>
<?php foreach($this->entries as $entry) { ?>
<?php foreach($this->catalog->getEntries() as $entry) { ?>
<li>
<?php if ($entry->isNotice()) { ?>
<?php echo $this->escape($entry->getTitle());?>
<?php if ($entry->getAuthor()) echo '(' . $this->escape($entry->getAuthor()) . ')';?>
- <a href="<?php echo $this->url(array('action' => 'import'));?>?feed=<?php echo urlencode($this->catalogUrl);?>&entry=<?php echo urlencode($entry->getId());?>">Importer</a>
- <a href="<?php echo $this->url(array('action' => 'import'));?>?feed=<?php echo urlencode($this->catalog->getUrl());?>&entry=<?php echo urlencode($entry->getId());?>">Importer</a>
<?php } else { ?>
<a href="<?php echo $this->url();?>?entry=<?php echo urlencode($entry->getLink()); ?>">
<?php echo $this->escape($entry->getTitle());?></a>
......
......@@ -35,4 +35,6 @@ echo $this->bouton('id=add_category',
</tr>
<?php } ?>
</tbody>
</table>
\ No newline at end of file
</table>
<?php echo $this->subview;?>
\ No newline at end of file
......@@ -29,8 +29,21 @@ class Class_OpdsCatalog extends Storm_Model_Abstract {
public function getEntries() {
return $this->getCatalogueReader()->getEntries();
}
public function getCatalogueReader() {
if (isset($this->_catalog_reader))
return $this->_catalog_reader;
$xml = $this->getWebClient()->open_url($this->getUrl());
return Class_WebService_OPDS_CatalogReader::getEntriesFromXml($xml);
return $this->_catalog_reader = Class_WebService_OPDS_CatalogReader::fromXML($xml);
}
public function getMetadatas() {
return $this->getCatalogueReader()->getMetadatas();
}
......
......@@ -22,18 +22,18 @@
class Class_WebService_OPDS_CatalogReader {
protected $_current_entry;
protected $_entries;
protected $_metadatas;
protected $_xml_parser;
public static function getEntriesFromXml($xml) {
$instance = new self();
return $instance
->parse($xml)
->getEntries();
public static function fromXML($xml) {
$instance = new self();
return $instance->parse($xml);
}
public function parse($xml) {
$this->_entries = array();
$this->_metadatas = array();
$this->_xml_parser = Class_WebService_XMLParser::newInstance();
$this->_xml_parser->setElementHandler($this);
$this->_xml_parser->parse($xml);
......@@ -46,6 +46,11 @@ class Class_WebService_OPDS_CatalogReader {
}
public function getMetadatas() {
return $this->_metadatas;
}
public function startEntry() {
$this->_current_entry = new Class_WebService_OPDS_CatalogEntry();
$this->_entries[] = $this->_current_entry;
......@@ -53,8 +58,10 @@ class Class_WebService_OPDS_CatalogReader {
public function endTitle($data) {
if (!$this->_xml_parser->inParents('entry'))
if (!$this->_xml_parser->inParents('entry')) {
$this->_metadatas['Titre'] = $data;
return;
}
$this->_current_entry->setTitle($data);
}
......@@ -80,8 +87,11 @@ class Class_WebService_OPDS_CatalogReader {
public function endName($data) {
if (!$this->_xml_parser->inParents('entry'))
if (!$this->_xml_parser->inParents('entry')
&& $this->_xml_parser->inParents('author')) {
$this->_concatMetadata('Auteur', $data);
return;
}
if (!$this->_xml_parser->inParents('author'))
return;
......@@ -90,11 +100,42 @@ class Class_WebService_OPDS_CatalogReader {
}
public function endUri($data) {
if (!$this->_xml_parser->inParents('entry')
&& $this->_xml_parser->inParents('author')) {
$this->_concatMetadata('Auteur', $data);
}
}
public function endEmail($data) {
if (!$this->_xml_parser->inParents('entry')
&& $this->_xml_parser->inParents('author')) {
$this->_concatMetadata('Auteur', $data);
}
}
public function endId($data) {
if (!$this->_xml_parser->inParents('entry'))
return;
$this->_current_entry->setId($data);
}
public function endUpdated($data) {
if ($this->_xml_parser->inParents('entry'))
return;
$this->_metadatas['Dernière mise à jour'] = Class_Date::humanDate($data);
}
protected function _concatMetadata($name, $value, $separator = ' - ') {
$this->_metadatas[$name] = (isset($this->_metadatas[$name]))
? $this->_metadatas[$name] . $separator . $value
: $value;
}
}
?>
\ No newline at end of file
......@@ -345,12 +345,48 @@ class Admin_OpdsControllerBrowseActionTest extends Admin_OpdsControllerBrowseEbo
}
/** @test */
public function listOfCatalogsShouldBePresent() {
$this->assertXPathContentContains('//h1', 'Catalogues OPDS');
}
/** @test */
public function titleShouldBeParcoursDuCatalogueEbooksGratuits() {
$this->assertXPathContentContains('//h1', 'Parcours du catalogue "Ebooks gratuits"');
}
/** @test */
public function libelleEbookLibresEtGratuitsShouldBePresent() {
$this->assertXPathContentContains('//div[@class="panel"]//li', 'Ebooks libres et gratuits');
}
/** @test */
public function lastUpdateDateShouldBeMayFifteen2012() {
$this->assertXPathContentContains('//div[@class="panel"]//li', '15 mai 2012');
}
/** @test */
public function authorShouldBeEbooksGratuits() {
$this->assertXPathContentContains('//div[@class="panel"]//li', 'Ebooksgratuits');
}
/** @test */
public function authorUriShouldBeEbooksgratuitsDotCom() {
$this->assertXPathContentContains('//div[@class="panel"]//li', 'http://www.ebooksgratuits.com');
}
/** @test */
public function authorMailShouldBeSupportAtBbooksgratuitsDotCom() {
$this->assertXPathContentContains('//div[@class="panel"]//li', 'support@ebooksgratuits.com');
}
/** @test */
public function linkToLastPublishedShouldBePresent() {
$this->assertXPathContentContains('//a[contains(@href, "/browse/id/1?entry=' . urlencode('http://www.ebooksgratuits.com/opds/feed.php') . '")]',
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment