Commit 9eb1138e authored by Ghislain Loas's avatar Ghislain Loas

dev #75742 fix rt comments

parent dd67da14
......@@ -35,7 +35,6 @@ class Admin_ThesauriController extends ZendAfi_Controller_Action {
'page' => $this->_getParam('page', 1),
'order' => $this->_getParam('order', 'libelle')]);
$thesauri = $this->_getParam('parent_id')
? Class_CodifThesaurus::find($this->_getParam('parent_id'))
: Class_CodifThesaurus::root();
......
......@@ -363,7 +363,7 @@ class Class_AdminVarLoader extends Storm_Model_Loader {
'FEATURES_TRACKING_ENABLE' => Class_AdminVar_Meta::newOnOff('Affiche les dernières modifications apportés au logiciel Bokeh', ['value' => 1])->bePrivate(),
'INSPECTOR_GADGET_MARC_XML' => Class_AdminVar_Meta::newOnOff('Affiche le MARC XML de la notice dans Inspector Gadget')->bePrivate(),
'BUSINESS_EMAIL' => Class_AdminVar_Meta::newDefault($this->_('Email utilisé pour les demandes d\'accompagnement de mise en place ou d\'utilisation des fonctionnalités du logiciel'), ['value' => 'cial-bib@afi-sa.fr'])->bePrivate(),
'THESAURI_BROWSER' => Class_AdminVar_Meta::newOnOff($this->_('Activer l\'outil de parcourt des Thesaurus'))
'THESAURI_BROWSER' => Class_AdminVar_Meta::newOnOff($this->_('Activer l\'outil de parcours des Thesaurus'))
->bePrivate()
];
}
......@@ -900,6 +900,11 @@ class Class_AdminVarLoader extends Storm_Model_Loader {
}
public static function isThesauriBrowserEnabled() {
return Class_AdminVar::isModuleEnabled('THESAURI_BROWSER');
}
public function getBabelthequeId() {
$mathes = [];
if (preg_match('/bw_([^\.]+)\.js/', (string)Class_AdminVar::get('BABELTHEQUE_JS'), $matches))
......
......@@ -132,9 +132,23 @@ class CodifThesaurusLoader extends Storm_Model_Loader {
public function countChildrenOf($id_thesaurus) {
return Class_CodifThesaurus::countBy(['where' => 'id_thesaurus like "'.$id_thesaurus.'%" and LENGTH(id_thesaurus)>'.strlen($id_thesaurus)
]);
$where = sprintf('id_thesaurus like "%s%%" and LENGTH(id_thesaurus) > %s',
$id_thesaurus,
strlen($id_thesaurus));
return Class_CodifThesaurus::countBy(['where' => $where]);
}
public function findChildrenOfWith($id_thesaurus, $page, $items_by_page, $order) {
$where = sprintf('id_thesaurus like "%s%%" and LENGTH(id_thesaurus) = %s',
$id_thesaurus,
(strlen($id_thesaurus) + 4));
return Class_CodifThesaurus::findAllBy(['where' => $where,
'limitPage' => [$page,
$items_by_page],
'order' => $order]);
}
......@@ -515,9 +529,12 @@ class Class_CodifThesaurus extends Storm_Model_Abstract {
public function getRulesLabel() {
return ($json = $this->getRules())
? json_decode($json)->label
: '';
if(!$rules = $this->getRules())
return '';
$json = json_decode($rules);
return $json ? $json->label : '';
}
......@@ -555,6 +572,7 @@ class Class_CodifThesaurus extends Storm_Model_Abstract {
public function cleanRecords() {
$facets = [];
foreach($this->getLoader()->findChildrenOf($this) as $child)
$facets[] = $child->getFacetteIndex();
......@@ -604,6 +622,7 @@ class Class_CodifThesaurus extends Storm_Model_Abstract {
});
}
public function getParent() {
return $this->getLoader()->findParent($this->getIdThesaurus());
}
......@@ -620,7 +639,13 @@ class Class_CodifThesaurus extends Storm_Model_Abstract {
return $this->getLibelleFacette();
}
public function numberOfChildrens() {
return $this->getLoader()->countChildrenOf($this->getIdThesaurus());
}
public function isNotRoot() {
return strlen($this->getIdThesaurus()) > Class_CodifThesaurus::ID_KEY_LENGTH;
}
}
\ No newline at end of file
......@@ -66,7 +66,8 @@ class ZendAfi_Acl_AdminControllerGroup {
'i18n' => Class_AdminVar::isTranslationEnabled(),
'stat/piwik' => (new Class_AdminVar_Piwik())->isEnabled(),
'multimedia' => Class_AdminVar::isMultimediaEnabled(),
'search-form' => Class_AdminVar::isCustomSearchFormEnabled()];
'search-form' => Class_AdminVar::isCustomSearchFormEnabled(),
'thesauri' => Class_AdminVar::isThesauriBrowserEnabled()];
}
......
......@@ -94,6 +94,7 @@ class ZendAfi_Acl_AdminControllerRoles extends Zend_Acl {
$this->add(new Zend_Acl_Resource('batch'));
$this->add(new Zend_Acl_Resource('file-manager'));
$this->add(new Zend_Acl_Resource('search-form'));
$this->add(new Zend_Acl_Resource('thesauri'));
//Roles
$this->addRole(new Zend_Acl_Role('invite'));
......@@ -148,6 +149,7 @@ class ZendAfi_Acl_AdminControllerRoles extends Zend_Acl {
$this->allow('admin_bib','menus');
$this->allow('admin_bib','external-agendas');
$this->allow('admin_bib','search-form');
$this->allow('admin_bib','thesauri');
$this->deny('modo_portail','catalogue');
$this->deny('modo_portail','rss');
......
......@@ -42,13 +42,13 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen
public function render($view, $callback) {
return $view->tagModelTable($this->getItems(),
$this->getItemsCols($view),
$this->getItemsAttribs(),
$this->getItemsAttribs(),
[function($model) use ($view)
{
return $view->renderPluginsActions($model);
}],
$this->getItemsId(),
$this->getItemsGroupBy(),
{
return $view->renderPluginsActions($model);
}],
$this->getItemsId(),
$this->getItemsGroupBy(),
$this->isSearching() ? [$this->getItemsLabelAttrib() => $callback] : [], $this->enabledPager(), $this->enabledSorter());
}
......@@ -157,9 +157,21 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen
}
public function getSearchColumns() {
return ['titre'];
}
public function getSearchParams() {
return ['where' => 'titre like ' . Zend_Db_Table::getDefaultAdapter()->quote('%' . $this->getSearch() . '%') ,
'order' => 'titre'];
$search_param = Zend_Db_Table::getDefaultAdapter()->quote('%' . $this->getSearch() . '%');
$columns = $this->getSearchColumns();
$where = [];
foreach ($columns as $col)
$where [] = '('.$col.' like '.$search_param.')';
return ['where' => implode(' or ', $where),
'order' => $this->getOrder()];
}
......@@ -318,7 +330,7 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen
->setText($this->_form_settings->getSearchText())
->setImage($view->tagImg(Class_Admin_Skin::current()
->getIconUrl('actions',
'loupe'),
'loupe'),
['style' => 'filter: invert();']))
->setAttribs(['onclick' => "var form=$(this).parents('form'); if (!form.length) form=$(this).parents('.boutons, .admin-buttons').prevAll('form');if (!form.length) form=$(this).parents('.boutons, .admin-buttons').nextAll('form');form.submit(); return false;",
'type' => 'submit',
......@@ -341,6 +353,11 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen
}
public function getOrder() {
return $this->getParam('order', 'titre');
}
protected function _getSearchForm($view) {
return (new ZendAfi_Form())
->setAction($view->url(array_filter($this->getSearchUrl()), null, true))
......
......@@ -22,6 +22,7 @@
class ZendAfi_Controller_Action_Helper_ThesauriListViewMode extends ZendAfi_Controller_Action_Helper_AbstractListViewMode {
public function thesauriListViewMode($params) {
$this->_params = $params;
return $this;
......@@ -32,10 +33,12 @@ class ZendAfi_Controller_Action_Helper_ThesauriListViewMode extends ZendAfi_Cont
return $this->thesauriListViewMode($params);
}
protected function enabledSorter() {
return false;
}
public function getBaseUrl() {
return ['module' => 'admin',
'controller' => 'thesauri'];
......@@ -74,19 +77,17 @@ class ZendAfi_Controller_Action_Helper_ThesauriListViewMode extends ZendAfi_Cont
public function getItems() {
$model = $this->getModel();
if ($this->isSearching())
return Class_CodifThesaurus::findAllBy($this->getItemsParams());
if($model->isNew())
return [];
$where = sprintf('id_thesaurus like "%s%%" and LENGTH(id_thesaurus) = %s',
$model->getIdThesaurus(), strlen($model->getIdThesaurus()) + 4);
return Class_CodifThesaurus::findAllBy(['where' => $where,
'limitPage' => [$this->getPage(),
$this->_items_by_page],
'order' => $this->getParam('order','libelle')]);
return Class_CodifThesaurus::findChildrenOfWith($model->getIdThesaurus(),
$this->getPage(),
$this->_items_by_page,
$this->getOrder());
}
......@@ -96,17 +97,15 @@ class ZendAfi_Controller_Action_Helper_ThesauriListViewMode extends ZendAfi_Cont
public function countItemsInTreeFrom($model) {
if ($model->isNew())
return 0;
return $model->numberOfChildrens();
return $model->isNew()
? 0
: $model->numberOfChildrens();
}
public function getItemsCols($view) {
$order = $this->getOrder();
$anchor_wrapper = function($key, $label) use ($view, $order) {
xdebug_break();
$order_param = $key;
if((0 === strpos($order, $key)) && (false === strpos($order, 'desc')))
$order_param .= ' desc';
......@@ -127,7 +126,6 @@ class ZendAfi_Controller_Action_Helper_ThesauriListViewMode extends ZendAfi_Cont
$anchor_wrapper('id_thesaurus', $this->_('ID Thesaurus')),
$anchor_wrapper('rules_label', $this->_('Règle'))];
xdebug_break();
return $cols;
}
......@@ -154,20 +152,13 @@ class ZendAfi_Controller_Action_Helper_ThesauriListViewMode extends ZendAfi_Cont
'rules_label'];
}
public function getSearchParams() {
$columns = ['libelle',
'libelle_facette',
'code',
'id_thesaurus',
'rules'
];
$where = [];
$search_param = Zend_Db_Table::getDefaultAdapter()->quote('%' . $this->getSearch() . '%');
foreach ($columns as $col) {
$where [] = '('.$col.' like '.$search_param.')';
}
return ['where' => implode(' or ',$where),
'order' => $this->getOrder()];
public function getSearchColumns() {
return ['libelle',
'libelle_facette',
'code',
'id_thesaurus',
'rules'];
}
......
......@@ -47,6 +47,7 @@ class ZendAfi_Controller_Plugin_Manager_Thesauri extends ZendAfi_Controller_Plug
'id' => '%s'],
'icon' => 'edit',
'label' => $this->_('Modifier le thesaurus')],
['url' => $this->_view->url(['module' => 'opac',
'controller' => 'recherche',
'action' => 'simple',
......@@ -56,10 +57,8 @@ class ZendAfi_Controller_Plugin_Manager_Thesauri extends ZendAfi_Controller_Plug
'label' => $this->_('Voir les documents qui ont la facette "%s"',$model->getFacetteIndex()),
'anchorOptions' => ['target' => '_blank'],
'condition' => function ($model) {
return (strlen($model->getIdThesaurus()) > Class_CodifThesaurus::ID_KEY_LENGTH);
return $model->isNotRoot();
}
],
];
]];
}
}
}
\ No newline at end of file
......@@ -24,31 +24,32 @@ class ZendAfi_Form_Admin_Thesauri extends ZendAfi_Form {
public function init() {
parent::init();
$this->addElement('text',
'libelle',
['label' => $this->_('Libellé'),
'disabled' => 'disabled'])
->addElement('text',
'libelle_facette',
['label' => $this->_('Libellé facette')])
->addElement('text',
'code',
['label' => $this->_('Code'),
'disabled' => 'disabled'])
->addElement('text',
'id_thesaurus',
['label' => $this->_('Identifiant thésaurus'),
'disabled' => 'disabled'])
->addElement('text',
'rules',
['label' => $this->_('Règle'),
'disabled' => 'disabled'])
->addUniqDisplayGroup('thesauri');
$this
->addElement('text',
'libelle',
['label' => $this->_('Libellé'),
'disabled' => 'disabled'])
->addElement('text',
'libelle_facette',
['label' => $this->_('Libellé facette')])
}
->addElement('text',
'code',
['label' => $this->_('Code'),
'disabled' => 'disabled'])
->addElement('text',
'id_thesaurus',
['label' => $this->_('Identifiant thésaurus'),
'disabled' => 'disabled'])
}
?>
\ No newline at end of file
->addElement('text',
'rules',
['label' => $this->_('Règle'),
'disabled' => 'disabled'])
->addUniqDisplayGroup('thesauri');
}
}
\ No newline at end of file
......@@ -170,8 +170,7 @@ class ZendAfi_View_Helper_Admin_ContentNav extends ZendAfi_View_Helper_BaseHelpe
["thesaurus_edit",
$this->_("Parcourir les Thesaurus"), "/admin/thesauri/index",
[],
function($user) { return $user->isAdmin() && Class_AdminVar::getValueOrDefault('THESAURI_BROWSER');}]
[]]
]);
}
......
......@@ -26,6 +26,8 @@ abstract class Thesauri_ThesauriTestCase extends Admin_AbstractControllerTestCas
public function setUp() {
parent::setUp();
Class_AdminVar::set('THESAURI_BROWSER', 1);
$this->fixture('Class_CodifThesaurus',
['id' => 3,
'libelle' => 'Document',
......@@ -163,14 +165,28 @@ class Thesauri_ThesauriEditTest extends Thesauri_ThesauriTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/admin/thesauri/edit/id/3', true);
}
/** @test */
public function inputLibelleShouldContainsDocument() {
$this->dispatch('/admin/thesauri/edit/id/3', true);
$this->assertXpath('//form//input[@value="Document"][@type="text"][@name="libelle"]');
}
/** @test */
public function thesauriShouldHaveBeenUpdated() {
$this->postDispatch('/admin/thesauri/edit/id/3', ['libelle_facette' => 'brave']);
$this->assertEquals('brave', Class_CodifThesaurus::find(3)->getLibelleFacette());
}
/** @test */
public function thesauriShouldNotHaveBeenUpdated() {
$this->postDispatch('/admin/thesauri/edit/id/3', ['rules' => 'brave']);
$this->assertEmpty(Class_CodifThesaurus::find(3)->getRuleslabel());
}
}
......@@ -180,13 +196,12 @@ class Thesauri_ThesauriAdminIndexDispatchTest extends Thesauri_ThesauriTestCase
public function setUp() {
parent::setUp();
Class_AdminVar::set('THESAURI_BROWSER', 1);
$this->dispatch('/admin/index', true);
}
/** @test */
public function thesauriIndexLinkShouldBePresent() {
$this->assertXpath('//a[contains(@href, "/thesauri/index")]');
$this->assertXpathContentContains('//a[contains(@href, "/thesauri/index")]', 'Parcourir les Thesaurus');
}
}
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