Commit 2c977634 authored by Ghislain Loas's avatar Ghislain Loas

hotline #71669 refacto to view helper

parent 41f89278
......@@ -42,7 +42,7 @@ class Admin_BatchController extends ZendAfi_Controller_Action {
->save();
$this->_helper->notify('Tâche activée');
$this->_redirectToIndex();
$this->_redirectToReferer();
}
......@@ -55,7 +55,7 @@ class Admin_BatchController extends ZendAfi_Controller_Action {
$batch->delete();
$this->_helper->notify('Tâche désactivée');
$this->_redirectToIndex();
$this->_redirectToReferer();
}
......
<?php
if ($this->config->isEnabled()) {
echo $this->tag('div', $this->_('Activé'), ['class' => 'enabled']);
}
echo $this->tag('h2',$this->_('Paramétrage:'));
?>
<table id="adminvars">
<thead>
<tr class="soustitre">
<th><?php echo $this->_('Clef'); ?></th>
<th><?php echo $this->_('Valeur'); ?></th>
<th><?php echo $this->_('action'); ?></th>
</tr>
</thead>
<tbody>
<?php
$ligne = 0;
foreach ($this->config->getAdminVars() as $key => $var) {
$var = $this->config->getAdminVarInstance($key);
$ligne ++ ;
$edit_url = $this->url([
'module' => 'admin',
'controller' => 'index',
'action' => 'adminvaredit',
'cle' => $var->getClef()],
null,
true);
?>
<tr data-adminvar= "<?php echo $var->getClef(); ?>" class="<?php echo ($ligne & 1) ? "first" : "second";?>">
<td style="vertical-align:top;" >
<?php echo $var->getDescription();?>
<br><sub><a data-popup="true" href="<?php echo $edit_url; ?>">
<?php echo $var->getClef();?></a></sub>
</td>
<td>
<?php
echo ($renderer = $var->getRenderer())
? $renderer($var->getValeur(), $this)
: $this->adminVar($var);
?>
</td>
<td style="width:2%;text-align:center">
<a data-popup="true" href="<?php echo $edit_url; ?>"><?php echo $this->boutonIco("type=edit");?></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
echo $this->tag('h2',$this->_('Gestion des droits'));
$groups = new Storm_Collection(Class_UserGroup::findAll());
//$config = $this->config;
$permitted_group = $groups->select(function ($group){
$permission = $this->config->getPermission();
return $group->hasPermissionOn($permission,$this->config);
});
if ($permitted_group->isEmpty()) {
echo $this->tag('p', $this->_('Aucun groupe n\'a de droits d\'accès à la ressources'), ['class' => 'error']);
return;
}
$usergroup_description = (new Class_TableDescription('usergroups'))
->addColumn($this->_('Groupes qui ont accès à la ressource'), 'libelle')
->addColumn($this->_('Nombre de membres'), function($model) { return $model->formatedCount();});
echo $this->renderTable($usergroup_description, $permitted_group, ['sorter' => true]);
$count_user = 0;
foreach($permitted_group->getArrayCopy() as $group)
$count_user += $group->formatedCount();
if (0 == $count_user) {
echo $this->tag('p', $this->_('Aucun utilisateur de rattaché aux groupes'), ['class' => 'error']);
return;
}
$login = $this->config->getName() . '_test_user';
$user = ($user = Class_users::findFirstBy(['login' => $login]))
? $user
: Class_Users::newInstance(['login' => $login,
'password' => $login]);
if($this->config->getSsoAction()) {
echo $this->tag('h2',$this->_('Diagnostique SSO'));
if($user) {
$user->save();
current($permitted_group->getArrayCopy())->addUser($user);
echo $this->_('Utilisateur créé pour le test : "%s"', $user->getNomComplet());
$url = $this->config->getSsoUrl($user);
echo $this->tag('p', $this->_('Url SSO : ') . $this->tagAnchor($url, $url, ['target' => '_blank']));
}
}
if($this->config->getBatch()
|| $this->config->getHarvesting()) {
echo $this->tag('h2',$this->_('Diagnostique moissonnage'));
echo $this->tag('p',
$this->_('Nombre d\'albums présents : %s', $this->records_count));
$album = Class_Album::findFirstby(['type_doc_id' => $this->config->getDocType()]);
if($album && $user) {
echo $this->tag('p', $this->_('Utilisateur créé pour le test : "%s"', $user->getNomComplet()));
echo $this->tag('p', $this->_('Album utilisé pour le test : "%s"', $album->getTitre()));
$album_url = $this->config->getSsoUrl($user, $album);
echo $this->tag('p', $this->_('Url SSO : ') . $this->tagAnchor($album_url, $album_url, ['target' => '_blank']));
}
}
echo $this->DigitalResource_Dashboard($this->config);
......@@ -20,7 +20,7 @@
*/
class Class_DigitalResource_Batch extends Class_Batch_RessourceNumerique{
class Class_DigitalResource_Batch extends Class_Batch_RessourceNumerique {
protected $_config;
public function __construct($config) {
......
......@@ -75,13 +75,22 @@ class Class_DigitalResource_Config extends Class_Entity {
}
public function getBatchInstance() {
return $this->getDigitalResource()->getBatches()[$this->getBatch()];
}
public function getAdminVar($id) {
return $this->getDigitalResource()->getAdminVar($id);
}
public function getAdminVarInstance($id) {
return $this->getDigitalResource()->getAdminVarInstance($id);
public function getAdminVarsInstances() {
$vars = [];
foreach($this->getAdminVars() as $key => $meta)
$vars [] = $this->getDigitalResource()->getAdminVarInstance($key);
return $vars;
}
......
......@@ -43,7 +43,6 @@ class Class_DigitalResource_Controller extends ZendAfi_Controller_Action {
$this->view->titre = $this->_config->getName();
$this->view->config = $this->_config;
$this->view->records_count = Class_Album::countBy(['type_doc_id' => $this->_config->getDocType()]);
$this->getHelper('ViewRenderer')->renderScript('digital_resources/index.phtml');
}
......
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH 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).
*
* BOKEH 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 BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_View_Helper_DigitalResource_Dashboard extends ZendAfi_View_Helper_BaseHelper {
protected
$_config,
$_permitted_groups;
public function DigitalResource_Dashboard($config) {
$this->_config = $config;
return implode([$this->_renderStatus(),
$this->_renderSettings(),
$this->_renderRights(),
$this->_renderSso(),
$this->_renderHarvest()]);
}
protected function _renderStatus() {
return implode([$this->_globalStatus(),
$this->_harvestStatus()]);
}
protected function _globalStatus() {
$label = $this->_('Désactivé');
$class = 'digital_connectors_status';
if ($this->_config->isEnabled()) {
$label = $this->_('Activé');
$class .= ' enabled';
}
return $this->view->button((new Class_Entity)
->setText($label)
->setAttribs(['disabled' => 'disabled',
'onclick' => 'return;',
'class' => $class]));
}
protected function _harvestStatus() {
if(!$batch = $this->_config->getBatch())
return '';
$label = $this->_('Moissonnage désactivé');
$class = 'digital_connectors_status';
if (Class_Batch::findFirstBy(['type' => $batch])) {
$label = $this->_('Moissonnage activé');
$class .= ' enabled';
}
return $this->view->button((new Class_Entity)
->setText($label)
->setAttribs(['disabled' => 'disabled',
'onclick' => 'return;',
'class' => $class]));
}
protected function _renderSettings() {
$description = (new Class_TableDescription('adminvars'))
->addColumn($this->_('description'), 'description')
->addColumn($this->_('Clef'), 'id')
->addColumn($this->_('valeur'),
function($model)
{
return ($renderer = $model->getRenderer())
? $renderer($model->getValeur(), $this->view)
: $this->view->adminVar($model);
})
->addRowAction(function($model)
{
return $this->view->renderModelActions($model,
[['url' => ['module' => 'admin',
'controller' => 'index',
'action' => 'adminvaredit',
'cle' => $model->getClef()],
'icon' => 'edit',
'anchorOptions' => ['data-popup' => true],
'label' => $this->_('Modifier "%s"', $model->getClef())]]);
});
return
$this->_tag('h3', $this->_('Paramétrage'))
. $this->view->renderTable($description, $this->_config->getAdminVarsInstances(), ['sorter' => true]);
}
protected function _renderRights() {
$html = [$this->_tag('h3',$this->_('Gestion des droits'))];
$groups = new Storm_Collection(Class_UserGroup::findAll());
$this->_permitted_groups = array_filter(
$groups
->select(function ($group)
{
$permission = $this->_config->getPermission();
return $group->hasPermissionOn($permission, $this->_config);
})
->getArrayCopy());
if (empty($this->_permitted_groups)) {
$html [] = $this->_tag('p', $this->_('Aucun groupe n\'a de droits d\'accès à la ressources'), ['class' => 'error']);
return implode($html);
}
$usergroup_description = (new Class_TableDescription('usergroups'))
->addColumn($this->_('Groupes qui ont accès à la ressource'),
'libelle')
->addColumn($this->_('Nombre de membres'),
function($model) { return $model->formatedCount();})
->addRowAction(function($model)
{
return $this->view->renderModelActions($model,
[['url' => ['module' => 'admin',
'controller' => 'usergroup',
'action' => 'edit',
'id' => $model->getId()],
'icon' => 'edit',
'anchorOptions' => ['data-popup' => true],
'label' => $this->_('Modifier "%s"', $model->getLibelle())]]);
});
$html [] = $this->view->renderTable($usergroup_description, $this->_permitted_groups, ['sorter' => true]);
$count_user = 0;
foreach($this->_permitted_groups as $group)
$count_user += $group->formatedCount();
if (0 == $count_user)
$html [] = $this->_tag('p', $this->_('Aucun utilisateur rattaché aux groupes'), ['class' => 'error']);
return implode($html);
}
protected function _renderSso() {
$html = [$this->_tag('h3', $this->_('Diagnostique SSO'))];
if(!$this->_config->getSsoAction()) {
$html [] = $this->_tag('p', $this->_('Pas de connexion SSO pour cette ressource'), ['class' => 'erro']) ;
return implode($html);
}
if(!$this->_permitted_groups) {
$html [] = $this->_tag('p', $this->_('Aucun groupe utilisateur n\'a de droit pour cette ressource'), ['class' => 'erro']);
return implode($html);
}
$login = $this->_config->getName() . '_test_user';
$user = ($user = Class_Users::findFirstBy(['login' => $login]))
? $user
: Class_Users::newInstance(['login' => $login,
'password' => $login]);
$user->save();
if(!$permission = Class_Permission::findFirstBy(['code' => $this->_config->getName()]))
return implode($html);
$group_name = $this->_config->getName() . '_test_group';
$group = ($group = Class_UserGroup::findFirstBy(['libelle' => $group_name]))
? $group
: Class_UserGroup::newInstance(['libelle' => $group_name]);
$group->addUser($user)->save();
$permission->permitTo($group, new Class_Entity());
$html [] = $this->_tag('h5', $this->_('Groupe créé pour ce test'))
. $this->_tag('ul',
$this->_tag('li', $this->_('Nom : %s', $group->getLibelle())));
Class_Users::clearCache();
$user = Class_Users::find($user->getId());
$html [] = $this->_tag('h5', $this->_('Utilisateur créé pour ce test'))
. $this->_tag('ul',
$this->_tag('li', $this->_('Login : %s', $user->getLogin()))
. $this->_tag('li', $this->_('Mot de passe : %s', $user->getLogin()))
. $this->_tag('li', $this->_('Groupes : %s', implode(', ',$user->getUserGroupsLabels()))));
$html [] = $this->view->renderModelActions($user,
[['url' => ['module' => 'admin',
'controller' => 'users',
'action' => 'edit',
'id' => $user->getId()],
'icon' => 'edit',
'anchorOptions' => ['data-popup' => true],
'label' => $this->_('Modifier "%s"',
$user->getLogin())]]);
$url = $this->_config->urlFor($user);
$html [] = $this->_tag('h4', $this->_('URL SSO générée par /modules/%s pour l\'utilisateur "%s"',
$this->_config->getName(),
$user->getLogin()))
. $this->view->tagAnchor($url, $url, ['target' => '_blank']);
if(!$album = Class_Album::findFirstby(['type_doc_id' => $this->_config->getDocType()]))
return implode($html);
$album_url = $this->_config->urlFor($user, $album);
$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($album_url, $album_url, ['target' => '_blank']);
return implode($html);
}
protected function _renderHarvest() {
if(!$batch_name = $this->_config->getBatch())
return '';
$html = [$this->_tag('h3', $this->_('Diagnostique moissonnage'))];
if(!$batch = Class_Batch::findFirstBy(['type' => $batch_name])) {
$html [] = $this->_tag('p', $this->_('Le moissonnage n\'a pas été programmé'), ['class' => 'error'])
. $this->view->button((new Class_Entity())
->setText($this->_('Activer le moissonnage'))
->setUrl($this->view->absoluteUrl(['module' => 'admin',
'controller' => 'batch',
'action' => 'activate',
'id' => $batch_name],
null,
true)));
return implode($html);
}
$description = (new Class_TableDescription('batchs'))
->addColumn($this->_('Batch'), function($model) { return $model->getLabel(); })
->addColumn($this->_('Planification'),
function($model)
{
return (new Class_Repeat_WeekDays())->humanReadable($model->getPickDay());
})
->addColumn($this->_('Dernière exécution'), function($model) { return $model->getLastRun(); })
->addRowAction(function($model)
{
return $this->view->renderModelActions($model,
[
['url' => '/admin/batch/delete/id/%s',
'icon' => 'show',
'label' => $this->_('Désactiver la tâche'),
'condition' => function($model)
{
return $model->isDeletable();
},
'anchorOptions' =>
['onclick' => 'return confirm(\''
. str_replace(['\'', '"'], '\\\'',
$this->_('Etes-vous sur de vouloir désactiver cette tâche ?'))
. '\')']],
['url' => '/admin/batch/plan/id/%s',
'icon' => 'calendar',
'label' => $this->_('Plannifier la tâche'),
'condition' => function($model) {
return Class_Users::isCurrentUserSuperAdmin()
&& $model->isActive();
},
'anchorOptions' => ['data-popup' => 'true']],]);
});
$html [] = $this->view->renderTable($description, [new Class_Batch_Definition($this->_config->getBatchInstance())]);
$html [] = $this->_tag('p',
$this->_('Nombre d\'albums présents : %d', Class_Album::countBy(['type_doc_id' => $this->_config->getDocType()])));
return implode($html);
}
}
\ No newline at end of file
......@@ -36,7 +36,9 @@ body {
}
.redmine_status.redmine_green,
.modules .digital_connectors .digital_connectors_status.enabled {
body .digital_connectors_status.enabled,
body .digital_connectors_status.enabled:focus,
body .digital_connectors_status.enabled:hover {
background-color: var(--success-background);
}
......@@ -587,7 +589,7 @@ table {
.digital_connectors_status {
width: 150px;
min-width: 150px;
}
.pager {
......
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