Skip to content
Snippets Groups Projects
Commit 9cc5025f authored by Laurent's avatar Laurent
Browse files

rel #32494 album website wizard

parent f83205fe
Branches
Tags
6 merge requests!1553Master,!1502Master,!1501Stable,!1289Master,!1286Dev#32494 sitotheque utiliser l interface album pour creer une sitotheque,!1269Dev#32494 sitotheque utiliser l interface album pour creer une sitotheque
......@@ -45,6 +45,54 @@ class Admin_SitoController extends ZendAfi_Controller_Action {
}
public function createAction() {
$import_form = $this->view
->newForm(['id' => 'import', 'class' => 'form'])
->setMethod('post')
->addElement('url', 'url', ['label' => $this->view->_('URL du site web'),
'required' => true,
'allowEmpty' => false])
->addDisplayGroup(['url'], 'website', ['legend' => $this->view->_('Site web')])
->addElement('submit', 'submit', ['label' => $this->view->_('Importer')]);
if ($this->getRequest()->isPost() && $import_form->isValid($this->getRequest()->getPost())) {
$album = $this->createAlbumFromUrl($this->getRequest()->getPost('url'));
if ($album && $album->save()) {
$this->_redirect('/admin/album/edit_album/id/'.$album->getId());
return;
}
}
$this->view->import_form = $import_form;
}
protected function createAlbumFromUrl($url) {
$html = (new Class_WebService_SimpleWebClient())->open_url($url);
$dom = new Zend_Dom_Query($html);
$album = Class_Album::newInstance(['type_doc_id' => Class_TypeDoc::WEBSITE]);
$album->setTitre($dom->queryXpath('//head/title')->current()->textContent);
$description_node = $dom->queryXpath('//head/meta[@name="description"]')->current();
$album->setDescription($description_node->getAttribute('content'));
$resource = Class_AlbumRessource::newInstance(['url' => $url,
'titre' => $album->getTitre()]);
$album->addRessource($resource);
$album->save();
$thumbnailer = (new Class_WebService_WebSiteThumbnail());
$poster_name = $thumbnailer->fileNameFromUrl($url);
$poster_path = $resource->getThumbnailPath();
$resource->getFolderManager()->ensure($poster_path);
$thumbnailer->getThumbnailer()->fetchUrlToFile($url, $poster_path . $poster_name);
$resource->setPoster($poster_name);
return $album;
}
protected function _updateNewModel($sitotheque) {
if (!$category = Class_SitothequeCategorie::find($this->_getParam('id_cat'))) {
$this->_redirect('admin/sito');
......
......@@ -101,7 +101,7 @@ class Class_WebService_WebSiteThumbnail {
return $this->getThumbsDir().$thumbnail;
}
protected function fileNameFromUrl($url) {
public function fileNameFromUrl($url) {
$decoded = urldecode($url);
$wo_http = preg_replace('/^.*:\/\//', '', $decoded);
$filename = preg_replace('/[^\w\-]/', '_', $wo_http);
......
......@@ -130,6 +130,9 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdmin extends ZendAfi_View_Helper_Base
.$this->addMenu("jamendo_16.png", $this->translate()->_("Jamendo"), "/admin/harvest/jamendo-browse",
Class_AdminVar::isJamendoEnabled())
.$this->addMenu("sitotheque_16.png", $this->translate()->_("Sitothèque"), "/admin/sito/create",
$this->filterAdmin($this->user) || $this->user->hasRightToAccess(Class_UserGroup::RIGHT_USER_SITOTHEQUE))
/* disabled until interactive harvesting is implemented
.$this->addMenu("oai_16.png", $this->translate()->_("Cyberlibris"), "/admin/harvest/cyberlibris-browse",
Class_AdminVar::isCyberlibrisEnabled()
......
......@@ -605,4 +605,59 @@ class SitothequeControllerDeleteCategorieInformationsTest extends SitothequeCont
}
class SitothequeControllerImportFromUrlTest extends AbstractControllerTestCase {
protected
$_storm_default_to_volatile = true,
$_cned;
public function setUp() {
parent::setUp();
$this->postDispatch('/admin/sito/create',
['url' => 'http://www.cned.fr']);
$this->_cned = Class_Album::find(1);
}
/** @test */
public function titleShouldBeFormationToutAuLongDeLaVie() {
$this->assertEquals('Formation tout au long de la vie - CNED',
$this->_cned->getTitre());
}
/** @test */
public function albumShouldBeWebSite() {
$this->assertTrue($this->_cned->isWebSite());
}
/** @test */
public function albumShouldHaveOneResourceWithUrlCnedDotFr() {
$this->assertNotNull($resource = $this->_cned->getRessources()[0]);
$this->assertEquals('http://www.cned.fr', $resource->getUrl());
return $resource;
}
/**
* @depends albumShouldHaveOneResourceWithUrlCnedDotFr
* @test
*/
public function resourceTitleShouldBeFormationToutAuLongDeLaVie($resource) {
$this->assertEquals('Formation tout au long de la vie - CNED',
$resource->getTitre());
}
/** @test */
public function albumDescriptionShouldBeFormationsEnLigne() {
$this->assertContains('Formations en ligne et cours', $this->_cned->getDescription());
}
}
?>
\ No newline at end of file
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