diff --git a/.gitattributes b/.gitattributes index 743a7992d41493337cfa4b7dff47f377e66f80a7..bc93c0d4cafe05723dd1829dec7851454f01c042 100644 --- a/.gitattributes +++ b/.gitattributes @@ -794,6 +794,7 @@ application/modules/opac/views/scripts/java/protoflow.phtml -text application/modules/opac/views/scripts/java/slide_show.phtml -text application/modules/opac/views/scripts/kiosque-change-data.phtml -text application/modules/opac/views/scripts/module.phtml -text +application/modules/opac/views/scripts/modules-accueil/kiosque-change-data.phtml -text application/modules/opac/views/scripts/noticeajax/notice.phtml -text application/modules/opac/views/scripts/oai/bad-verb.xml.phtml -text application/modules/opac/views/scripts/oai/get-record.xml.phtml -text diff --git a/application/modules/admin/controllers/CatalogueController.php b/application/modules/admin/controllers/CatalogueController.php index ed0767fdd7d3c6f5d33373deaa5c78c867610125..5f73464614c14d8b8788efcf84440ad7cd7a2453 100644 --- a/application/modules/admin/controllers/CatalogueController.php +++ b/application/modules/admin/controllers/CatalogueController.php @@ -23,7 +23,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// class Admin_CatalogueController extends ZendAfi_Controller_Action { - use Trait_Translator; +use Trait_Translator; function indexAction() { if (!$this->view->catalogues = Class_Catalogue::findTopCatalogues()) @@ -243,62 +243,7 @@ class Admin_CatalogueController extends ZendAfi_Controller_Action { ]); } - function domainesPaniersAction() { - $this->_helper->viewRenderer->setNoRender(); - - $data = []; - $data[] = $this->getDomainesDataForJson(); - $data[] = $this->getPaniersDataForJson(); - $JSON = json_encode($data); - - $this->getResponse()->setHeader('Content-Type', 'application/json; charset=utf-8'); - $this->getResponse()->setBody($JSON); - } - - - public function getDomainesDataForJson() { - $domaines = Class_Catalogue::findTopCatalogues(); - foreach($domaines as $domaine) { - $data_domaines [] = $domaine->toDataForJson(); - } - - return $data = ['id' => 'domaines_paniers', - 'label' => $this->view->_('Domaines'), - 'categories' => $data_domaines, - 'items' => [], - 'options' => ['mutlipleSelection' => false]]; - - } - - - public function getPaniersDataForJson() { - $users_paniers = []; - $paniers = Class_PanierNotice::findAllWithNoCatalogueBelongsToAdmin(); - - foreach($paniers as $panier) { - $owner = $panier->getUser(); - $owner_id = $owner->getId(); - - if (!isset($users_paniers[$owner_id])) - $users_paniers[$owner_id] = ['id' => $owner_id, - 'label' => $owner->getNomComplet(), - 'categories' => [], - 'items' => [], - 'options' => ['ico' => URL_ADMIN_IMG.'picto/abonnes.gif', - 'removeCheckbox' => true]]; - $users_paniers[$owner_id]['items'][]= ['id' => $panier->getId(), - 'label' => $panier->getLibelle(), - 'options' => ['ico' => URL_ADMIN_IMG.'picto/paniers_16.png']]; - } - - $data_for_json = ['id' => 'paniers_by_users', - 'label' => $this->view->_('Paniers sans domaine, rattachés au créateur'), - 'categories' => $users_paniers, - 'items' => [], - 'options' => ['multiSelection' => false]]; - - return $data_for_json; - } + } \ No newline at end of file diff --git a/application/modules/opac/controllers/CatalogueController.php b/application/modules/opac/controllers/CatalogueController.php index ade875eb54aaeb088a81a5afec733c39e3f83ade..87b054173a28edfe2ee44b9297fbe0e3ee3ffbdf 100644 --- a/application/modules/opac/controllers/CatalogueController.php +++ b/application/modules/opac/controllers/CatalogueController.php @@ -94,4 +94,84 @@ class CatalogueController extends Zend_Controller_Action else $facette=$this->view->_("aucune"); return $this->view->_("Facettes: %s", $facette); } + + + function domainesPaniersAction() { + xdebug_break(); + $this->_helper->viewRenderer->setNoRender(); + + $data = []; + $data[] = $this->getPaniersForCurrentUserDataForJson(); + $data[] = $this->getDomainesDataForJson(); + $data[] = $this->getPaniersDataForJson(); + $JSON = json_encode($data); + + + $this->getResponse()->setHeader('Content-Type', 'application/json; charset=utf-8'); + $this->getResponse()->setBody($JSON); + } + + public function getPaniersForCurrentUserDataForJson() { + $paniers = Class_Users::getIdentity()->getPaniers(); + $data_items=[]; + foreach($paniers as $panier) { + $data_items[] = $panier->toDataForJson(); + } + return $data_for_json = ['id' => 'panier_for_user', + 'label' => $this->view->_('Vos derniers paniers'), + 'categories' => [], + 'items' => $data_items, + 'options' => ['multiSelection' => false]]; + + } + + + public function getDomainesDataForJson() { + $domaines = Class_Catalogue::findTopCatalogues(); + foreach($domaines as $domaine) { + $data_domaines [] = $domaine->toDataForJson(); + } + + return $data = ['id' => 'domaines_paniers', + 'label' => $this->view->_('Domaines'), + 'categories' => $data_domaines, + 'items' => [], + 'options' => ['mutlipleSelection' => false]]; + + } + + + + + public function getPaniersDataForJson() { + $users_paniers = []; + $paniers = Class_PanierNotice::findAllWithNoCatalogueBelongsToAdmin(); + + foreach($paniers as $panier) { + $owner = $panier->getUser(); + $owner_id = $owner->getId(); + + if (!isset($users_paniers[$owner_id])) + $users_paniers[$owner_id] = ['id' => $owner_id, + 'label' => $owner->getNomComplet(), + 'categories' => [], + 'items' => [], + 'options' => ['ico' => URL_ADMIN_IMG.'picto/abonnes.gif', + 'removeCheckbox' => true]]; + $users_paniers[$owner_id]['items'][]= ['id' => $panier->getId(), + 'label' => $panier->getLibelle(), + 'options' => ['ico' => URL_ADMIN_IMG.'picto/paniers_16.png']]; + } + + + unset($users_paniers[Class_Users::getIdentity()->getId()]); + $data_for_json = ['id' => 'paniers_by_users', + 'label' => $this->view->_('Paniers sans domaine, rattachés au créateur'), + 'categories' => $users_paniers, + 'items' => [], + 'options' => ['multiSelection' => false]]; + + return $data_for_json; + } + } \ No newline at end of file diff --git a/application/modules/opac/controllers/ModulesAccueilController.php b/application/modules/opac/controllers/ModulesAccueilController.php index 82eb878ba7613267c2059751578bd0596ec92164..b6d8b414fc5a8bae699d1c32ab0a93f2e0898065 100644 --- a/application/modules/opac/controllers/ModulesAccueilController.php +++ b/application/modules/opac/controllers/ModulesAccueilController.php @@ -48,7 +48,7 @@ class ModulesAccueilController extends ZendAfi_Controller_Action { public function kiosqueChangeDataAction() { - + xdebug_break(); $this->id_module = $this->_getParam('id_module'); $module_config = $this->profil->getModuleAccueilConfig($this->_getParam('id_module')); @@ -71,9 +71,9 @@ class ModulesAccueilController extends ZendAfi_Controller_Action { // Class_ScriptLoader::getInstance()->addInlineScript("initializeAjaxFormSubmit($('input[type=\"submit\"][name=\"kiosque-change-data\"]').closest('form'))"); - $this->renderPopupResult($this->view->_('Selectionner le kiosque ou le panier à afficher dans le kiosque'), + /* $this->renderPopupResult($this->view->_('Selectionner le kiosque ou le panier à afficher dans le kiosque'), $this->view->render('kiosque-change-data.phtml'). - Class_ScriptLoader::getInstance()->html()); + Class_ScriptLoader::getInstance()->html());*/ } diff --git a/application/modules/opac/views/scripts/modules-accueil/kiosque-change-data.phtml b/application/modules/opac/views/scripts/modules-accueil/kiosque-change-data.phtml new file mode 100644 index 0000000000000000000000000000000000000000..36cd24ea141a0c709608d526c5f0c5ffee6e02ed --- /dev/null +++ b/application/modules/opac/views/scripts/modules-accueil/kiosque-change-data.phtml @@ -0,0 +1,21 @@ +<form class="kiosque" method="post" action="<?php echo $this->url() ?>"> + <fieldset> + <legend>Sélection</legend> + <div id="table_selection"> + <?php + echo $this->getHelper('TreeSelect') + ->disableMultipleSelection()->treeSelect($this->id_panier, + $this->id_catalogue, + true, + $this->url(['module' => 'opac', + 'controller' => 'catalogue', + 'action' => 'domaines-paniers']), + 'form.kiosque', + 'id_catalogue', + 'id_panier'); + ?></div> + </fieldset> + <?php + echo $this->formSubmit("kiosque-change-data","Valider",["class" => "bouton"]); + ?> +</form> diff --git a/library/Class/PanierNotice.php b/library/Class/PanierNotice.php index 8add08bf7233043a25a402d5f79cbe7b9f952555..3ac44fced56702e9fc64bc7302b26adf197929d9 100644 --- a/library/Class/PanierNotice.php +++ b/library/Class/PanierNotice.php @@ -47,13 +47,6 @@ class PanierNoticeLoader extends Storm_Model_Loader { } - public function maxIdPanierForUser($user) { - $select = $this->getTable()->select(); - $select->from($this->getTable(),['max(ID_PANIER) as max_id']); - return $this->getTable()->fetchRow($select)->max_id; - } - - public function findAllWithCatalogue() { $this->user = Class_Users::getIdentity(); if ($this->user->hasRightToAccess(Class_UserGroup::RIGHT_USER_PANIERS_VIEWALL) || $this->user->isAdmin()) @@ -102,12 +95,16 @@ class Class_PanierNotice extends Storm_Model_Abstract { } public function initializeForUser($user){ - $id_panier = Class_PanierNotice::getLoader()->maxIdPanierForUser($user) + 1; + xdebug_break(); $panier = (new Class_PanierNotice()) - ->setUser($user) - ->setLibelle($this->_('Panier no %d', $id_panier)) - ->setIdPanier($id_panier); - + ->setLibelle('Nouveau panier') + ->setUser($user); + $panier->save(); + + $panier + ->setLibelle($this->_('Panier no %d', $panier->getId())) + ->setIdPanier($panier->getId()); + $panier->save(); return $panier; } diff --git a/library/Class/Users.php b/library/Class/Users.php index 9327ae30b60ebf1097b361b2b0e1ea9930452ba2..16f0380170b82e2186dc0fb5c9fdb2438881ff3c 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -211,7 +211,8 @@ class Class_Users extends Storm_Model_Abstract { 'order' => 'date_avis desc'], 'paniers' => ['model' => 'Class_PanierNotice', - 'role' => 'user'], + 'role' => 'user', + 'order' => 'date_maj desc'], 'suggestion_achat' => ['model' => 'Class_SuggestionAchat', 'role' => 'user', diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php index 910e314317d9b665cdd9fe84c9210996ce09aa5d..79a458d2b576d7bdd4fa3d6c885aeb53f48c6ff5 100644 --- a/library/ZendAfi/Controller/Action.php +++ b/library/ZendAfi/Controller/Action.php @@ -24,6 +24,7 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { protected $_after_add_closure; public function init() { + xdebug_break(); $this->_helper->redirector->setExit(false); $this->_definitions = new ZendAfi_Controller_Action_RessourceDefinitions($this->getRessourceDefinitions()); } diff --git a/public/admin/js/treeselect/treeselect.js b/public/admin/js/treeselect/treeselect.js index b9b47d83015239d3270a6db75a45f61bb1d12329..d99a0b842857911ce39262d40052b626cb5ddc03 100644 --- a/public/admin/js/treeselect/treeselect.js +++ b/public/admin/js/treeselect/treeselect.js @@ -14,6 +14,7 @@ _create: function(){ var self=this; + this.multiple_selection = true; this.element.addClass('ui-widget ui-helper-reset'); this.container = $("<div class='ui-treeselect ui-widget-content ui-corner-all'></div>"). @@ -64,33 +65,48 @@ return (null!=catOrItem.options.ico) ? "<img src='"+catOrItem.options.ico+"' />" : "<span class='ui-treeselect-icon' />"; }, + + _addItemsTo: function(items, parent) { + var self = this; + + if (items == undefined) return; + + var self = this; + $.each(items, function(index, item) { + var item_li=self.mkli(item, parent, 'item'). + children('a'); + var item_ul = $("<ul></ul>").appendTo(item_li); + }); + + }, + + mkli: function(catOrItem, parent, type){ + return $("<li class='ui-treeselect-"+type+"'>"+ + this._addCheckbox(catOrItem)+ + "<a class='ui-state-default' href='#'>" + + this._addIco(catOrItem)+ + catOrItem.label+ + "</a>" + + "</li>"). + data("label", catOrItem.label). + data("type", type). + data("elid", catOrItem.id). + appendTo(parent). + children('a').hover( + function (event) { + self._onMouseEntersLI($(event.target).parent()); + }, + function (event) { + self._onMouseExitsLI($(event.target).parent()); + }).end(); + }, + + _addCategoriesTo: function(categories, parent) { var self = this; if (categories == undefined) return; - if (this.mkli == undefined) - this.mkli = function(catOrItem, parent, type){ - return $("<li class='ui-treeselect-"+type+"'>"+ - this._addCheckbox(catOrItem)+ - "<a class='ui-state-default' href='#'>" + - this._addIco(catOrItem)+ - catOrItem.label+ - "</a>" + - "</li>"). - data("label", catOrItem.label). - data("type", type). - data("elid", catOrItem.id). - appendTo(parent). - children('a').hover( - function (event) { - self._onMouseEntersLI($(event.target).parent()); - }, - function (event) { - self._onMouseExitsLI($(event.target).parent()); - }).end(); - }; - var self = this; $.each(categories, function(index, cat) { var cat_li = self.mkli(cat, parent, 'category'); @@ -103,6 +119,7 @@ var cat_ul = $("<ul></ul>").appendTo(cat_li); self._addCategoriesTo(cat.categories, cat_ul); + $.each(cat.items, function(index, item){ self.mkli(item, cat_ul, 'item'). @@ -170,6 +187,8 @@ children()[0]; self._addCategoriesTo(cat.categories, ul); + self._addItemsTo(cat.items,ul); + }); }, diff --git a/tests/application/modules/admin/controllers/CatalogueControllerTest.php b/tests/application/modules/admin/controllers/CatalogueControllerTest.php index 7baeeb841f7e2be111ac8a52d47fc1de3678fdfe..783f4e40870d5a64150edee162d9465e4abc54c8 100644 --- a/tests/application/modules/admin/controllers/CatalogueControllerTest.php +++ b/tests/application/modules/admin/controllers/CatalogueControllerTest.php @@ -204,15 +204,27 @@ class CatalogueControllerWithReferentIndexTest extends AdminCatalogueControllerT } - /** @disabled test */ + /** @test */ function withDomainesPaniersTreeShouldRenderArtJSON() { - $this->dispatch('admin/catalogue/domaines-paniers',true); + $this->dispatch('opac/catalogue/domaines-paniers',true); $icone_domaine = BASE_URL."/public/admin/images/picto/domaines_16.png"; $icone_panier = BASE_URL."/public/admin/images/picto/paniers_16.png"; $icone_abonne = BASE_URL."/public/admin/images/picto/abonnes.gif"; $expectedJSON = - [["id" => "domaines_paniers", + [ + ["id" => "paniers_user", + "label" => "Vos derniers paniers ", + "categories" => [], + "items" => [["id" => 3, + "label" => "selection jeunesse", + "options" => ["ico" => $icone_panier]], + ["id" => 8, + "label" => "selection adulte", + "options" => ["ico" => $icone_panier]], + "options" => ["multiSelection" => false]]], + +["id" => "domaines_paniers", "label" => "Domaines", "categories" => [["id" => 6, "label" => "Adultes", diff --git a/tests/application/modules/opac/controllers/PanierControllerTest.php b/tests/application/modules/opac/controllers/PanierControllerTest.php index af83d8a8b222cc737515beceb7c5c6cbab4ef9a4..e895829d8ccad84dc8effa0f9ac09b58bd8ebef8 100644 --- a/tests/application/modules/opac/controllers/PanierControllerTest.php +++ b/tests/application/modules/opac/controllers/PanierControllerTest.php @@ -27,6 +27,7 @@ abstract class PanierControllerTestCase extends AbstractControllerTestCase { Class_UserGroup::beVolatile(); Class_Notice::beVolatile(); + Class_PanierNotice::beVolatile(); $this->manon = Class_Users::newInstanceWithId(23, ['pseudo' => 'ManonL', 'nom' => 'Afond', @@ -50,14 +51,14 @@ abstract class PanierControllerTestCase extends AbstractControllerTestCase { 'date_maj' => '10/02/2011', 'notices' => 'COMBAT ORDINAIRE;BLACKSAD', 'user' => $this->manon]); - + $this->panier_bd->save(); $this->panier_romans = Class_PanierNotice::newInstanceWithId(15, ['id_panier' => 2, 'libelle' => 'Mes Romans', 'date_maj' => '25/05/2010', 'notices' => 'MONTESPAN', 'user' => $this->manon]); - + $this->panier_romans->save(); $montespan = Class_Notice::newInstanceWithId(4, ['titre_principal' => 'Le Montespan', 'auteur_principal' => 'Jean Teulé', @@ -89,6 +90,7 @@ abstract class PanierControllerTestCase extends AbstractControllerTestCase { ->with(['role' => 'user', 'model' => $this->manon]) ->answers([$this->panier_bd, $this->panier_romans]); + $panier_domaine_histoire = Class_PanierNoticeCatalogue::newInstanceWithId(71); @@ -1080,30 +1082,43 @@ class PanierControllerSupprimerNoticeBlacksadFromBDAndRedirectToRefererTest exte -class PanierControllerAjouterNoticeDansBoitePanierTest extends PanierControllerTestCase { +class PanierControllerAjouterNoticeDansBoitePanierTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); + Class_Users::beVolatile(); + + Class_UserGroup::beVolatile(); + Class_Notice::beVolatile(); + Class_PanierNotice::beVolatile(); + $this->manon = Class_Users::newInstanceWithId(2377, ['pseudo' => 'ManonL', + 'nom' => 'Afond', + 'login' => 'man', + 'password' => '123']); + $this->manon->changeRoleTo(ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL); + $this->manon->save(); + + ZendAfi_Auth::getInstance()->logUser($this->manon); $_SERVER['HTTP_REFERER'] = '/index'; $cfg_accueil = ['modules' => ['1' => ['division' => 1, 'type_module' => 'PANIER', 'preferences' => ['titre' => 'Mon panier']]]]; - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_PanierNotice') + /* Storm_Test_ObjectWrapper::onLoaderOfModel('Class_PanierNotice') ->whenCalled('save') ->willDo(function($panier){ $panier->setId(5)->cache(); }); - + */ Class_Profil::getCurrentProfil()->setCfgAccueil($cfg_accueil); - Class_Notice::newInstanceWithId(4, + $notice = Class_Notice::newInstanceWithId(4, ['titre_principal' => 'Le Montespan', 'auteur_principal' => 'Jean Teulé', 'clef_alpha' => 'MONTESPAN', 'unimarc' => '00445nam0 2200181 450 0010008000000100028000081000041000361010008000771020007000851050018000922000032001102100026001422150038001687000022002068010022002289020007002509030006002570507356 a978-2-260-01723-3d22 ? a20080612d|||| uuuy0frey0103 ba| afre aFR ay|||||||000|y1 aMontespan (Le)fJean Teulé aPariscJulliardd2008 a333 p.cjaq. ill. en coul.d21 cm 1aTeulébJean4070 0aFRbBMVc20080612 arh aG']); - + $notice->save(); $this->postDispatch('/panier/ajout-ajax/id_notice/4', ['id_panier' => '0']); } @@ -1111,7 +1126,7 @@ class PanierControllerAjouterNoticeDansBoitePanierTest extends PanierControllerT /** @test */ public function panierShouldHaveBeenSaveWithNotice4() { - $this->assertTrue(Class_PanierNotice::methodHasBeenCalled('save')); + $this->assertEquals(1,count(Class_PanierNotice::getLoader()->findAll())); } /** @disabled test */