Commit f10dee5f authored by Ghislain Loas's avatar Ghislain Loas

hotline #71669 upgrade modules/sso to digital_resources API

parent 1c66741b
......@@ -76,20 +76,21 @@ class ModulesController extends ZendAfi_Controller_Action {
public function ssoAction() {
if (!$record = Class_Notice::find($this->_getParam('id', 0))) {
$this->_helper->notify($this->_('Document non trouvé'));
$this->_helper->notify($this->_('L\'identifiant du document demandé n\'existe pas'));
$this->_redirectToReferer();
return;
}
$sso_record = new Class_Notice_Sso($record);
if(!$module_menu = $sso_record->getModuleMenu()) {
$this->_helper->notify($this->_('Oups, l\'adresse de consultation de ce document est indeterminée'));
$this->_redirectToReferer();
return;
if(!$digital_resource_config = $sso_record->getConfig()) {
$this->_helper->notify($this->_('Ce document ne possède pas de configuration permettant d\'utiliser cette URL.'));
return $this->_redirectToReferer();
}
$module_menu->setRecord($sso_record);
$this->simple($module_menu);
$this->_forward('sso',
'index',
$digital_resource_config->getModuleName(),
$this->_request->getParams());
}
......
......@@ -191,7 +191,7 @@ class Class_DigitalResource_Config extends Class_Entity {
}
public function urlFor($user, $album = null) {
public function urlFor($user, $album = null, $record = null) {
if(!$user)
return;
......@@ -201,9 +201,13 @@ class Class_DigitalResource_Config extends Class_Entity {
if(!$this->isEnabled())
return;
return $album
? $this->getAlbumSsoUrl($user, $album)
: $this->getSsoUrl($user);
if($record)
return $this->getRecordSsoUrl($user, $record);
if($album)
return $this->getAlbumSsoUrl($user, $album);
return $this->getSsoUrl($user);
}
......@@ -213,6 +217,14 @@ class Class_DigitalResource_Config extends Class_Entity {
public function getAlbumSsoUrl($user, $album) {
if(!$album)
return '';
return $album->getExternalUri();
}
public function getRecordSsoUrl($user, $record) {
return $this->getAlbumSsoUrl($suer, $record->getAlbum());
}
}
\ No newline at end of file
......@@ -53,7 +53,8 @@ class Class_DigitalResource_Controller extends ZendAfi_Controller_Action {
$this->_('Vous devez vous connecter pour accéder à cette page'));
$url = $this->_config->urlFor($user,
Class_Album::find($this->_getParam('album_id', 0)));
Class_Album::find($this->_getParam('album_id', 0)),
Class_Notice::find($this->_getParam('id', 0)));
return $url
? $this->_javascriptRedirectTo($url)
......
......@@ -49,11 +49,11 @@ class Class_Notice_Sso extends Class_Entity {
}
public function getModuleMenu() {
public function getConfig() {
if (!$this->isValid())
return null;
return Class_DigitalResource::getInstance()
->getModuleMenuFor($this->getFirstCatalogAgency());
->configFor($this->getFirstCatalogAgency());
}
}
......@@ -237,12 +237,12 @@ class ZendAfi_View_Helper_DigitalResource_Dashboard extends ZendAfi_View_Helper_
$html [] = $this->_tag('h4', $this->_('URL SSO générée pour l\'utilisateur "%s" et l\'album "%s"',
$user->getLogin(),
$album->getTitre())
. $this->view->tagAnchor(['module' => 'admin',
'controller' => 'album',
'action' => 'edit_album',
'id' => $album->getId()], $this->_('Voir l\'album'),
['style' => 'margin-left: 1em',
'data-popup' => 'true']))
. $this->view->tagAnchor(['module' => 'admin',
'controller' => 'album',
'action' => 'edit_album',
'id' => $album->getId()], $this->_('Voir l\'album'),
['style' => 'margin-left: 1em',
'data-popup' => 'true']))
. $this->view->tagAnchor($album_url, $album_url, ['target' => '_blank']);
return implode($html);
......@@ -250,13 +250,13 @@ class ZendAfi_View_Helper_DigitalResource_Dashboard extends ZendAfi_View_Helper_
protected function _renderHarvest() {
$html = [$this->_tag('h3', $this->_('Diagnostique moissonnage'))];
if(!$batch_name = $this->_config->getBatch()) {
$html [] = $this->_tag('p', $this->_('Cette ressource ne prend pas en charge le moissonnage'), ['class' => 'error']) ;
return implode($html);
}
$html = [$this->_tag('h3', $this->_('Diagnostique moissonnage'))];
if (!$this->_config->isEnabled()) {
$html [] = $this->_tag('p', $this->_('Veuillez activer la ressource pour pouvoir gérer le moissonage'), ['class' => 'error']);
return implode($html);
......
......@@ -50,6 +50,18 @@ class Bibliondemand_Config extends Class_DigitalResource_Config {
}
public function getRecordSsoUrl($user, $record) {
if(!$record)
return;
$url = Class_AdminVar::getValueOrDefault($this->withNameSpace('SSO_URL'));
return ($record_url = (new Class_Notice_Sso($record))->getFirstPrivateUrl())
? $url . '&' . http_build_query(['returnUrl' => $record_url])
: $url;
}
public function isEnabled() {
return '' != $this->getAdminVar('SSO_URL');
}
......
......@@ -50,7 +50,7 @@ class Skilleos_Config extends Class_DigitalResource_Config {
public function getSsoUrl($user) {
return $this->_getSsoUrl($url);
return $this->_getSsoUrl($user, null);
}
......
Markdown is supported
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