diff --git a/application/modules/admin/controllers/UsersController.php b/application/modules/admin/controllers/UsersController.php index 16bd6ea43a63617027b3b9715e598a013925233c..1fd6270452e21b5aed310323df4968329f3c94ab 100644 --- a/application/modules/admin/controllers/UsersController.php +++ b/application/modules/admin/controllers/UsersController.php @@ -38,17 +38,16 @@ class Admin_UsersController extends ZendAfi_Controller_Action { } - public function pageAction() {$this->_forward('index');} - - public function indexAction() { $this->view->titre = $this->_('Gestion des utilisateurs'); $this->view->page = $this->_getParam('page', 1); - $id_site = $this->_getParam('search_by_id_site', null); - $role_level = $this->_getParam('search_by_role_level', ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB); + + $id_site = $this->_getParam('by_id_site', null); + $role_level = $this->_getParam('by_role_level', ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB); $search_value = $this->_getParam('search_for', null); - $valide_subscription = $this->_getParam('search_by_valide_subscription', null); - $limit = ['limitPage' => [$this->view->page, 30]]; + $valide_subscription = $this->_getParam('by_valide_subscription', null); + + $limit = ['limitPage' => [$this->view->page, 20]]; $params = ['id_site' => $id_site, 'role_level' => $role_level]; $where = array_fill_keys(['login', @@ -57,9 +56,16 @@ class Admin_UsersController extends ZendAfi_Controller_Action { 'mail', 'idabon'], $search_value); + + $this->view->params = ['by_id_site' => $id_site, + 'by_role_level' => $role_level, + 'search_for' => $search_value, + 'by_valide_subscription' => $valide_subscription, + 'page' => $this->view->page]; + $this->view->users = Class_Users::findSearched($params, $where, $valide_subscription, $limit); $this->view->total = Class_Users::countSearched($params, $where, $valide_subscription, $limit); - $this->view->form = ZendAfi_Form_Admin_SearchUsers::newWith($this->_request->getParams()); + $this->view->form = ZendAfi_Form_Admin_SearchUsers::newWith($this->view->params); } diff --git a/application/modules/admin/views/scripts/users/index.phtml b/application/modules/admin/views/scripts/users/index.phtml index a0a4d1465d0abb302c72aa207d0949420f65f685..726ac1ce6b02a13b52609b22ee6954bf1e18021f 100644 --- a/application/modules/admin/views/scripts/users/index.phtml +++ b/application/modules/admin/views/scripts/users/index.phtml @@ -1,3 +1,3 @@ <?php -echo $this->Admin_SearchUsers($this->users, $this->total, $this->form, $this->page); +echo $this->Admin_SearchUsers($this->users, $this->total, $this->form, $this->page, $this->params); ?> diff --git a/library/Class/Users.php b/library/Class/Users.php index 4f1db85f9ef987977ab9f5265c6586417d1d0631..365d30831d509c6ed3f306c6d585632c35d193cc 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -245,22 +245,22 @@ class UsersLoader extends Storm_Model_Loader { $sql = []; foreach($or as $column => $value) - $tab_or[] = sprintf('%s LIKE "%%%s%%"', $column, $value); + $table_or[] = sprintf('%s LIKE "%%%s%%"', $column, $value); $sql_or = implode(' OR ', $table_or); $sql_subscription = ''; - if($valide_subscription && $default['role_level'] == ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB) { + if($valide_subscription && ($default['role_level'] == ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB)) { $sql_subscription = 'STR_TO_DATE(date_fin, \'%Y-%m-%d\') >= CURDATE()'; } if('' === $sql_subscription) return ['where' => $sql_or]; - if(empty($storm_where)) - return ['where' => $valide_subscription]; + if(empty($sql_or)) + return ['where' => $sql_subscription]; - return ['where' => '(' . $sql_or . ') AND ' . $valide_subscription]; + return ['where' => '(' . $sql_or . ') AND ' . $sql_subscription]; } diff --git a/library/ZendAfi/Form/Admin/SearchUsers.php b/library/ZendAfi/Form/Admin/SearchUsers.php index 01a8db9fc9c4efe2b2f595532a5748b47a8ffb40..cb381cd71faca6252195c126ae2ec470878af9c4 100644 --- a/library/ZendAfi/Form/Admin/SearchUsers.php +++ b/library/ZendAfi/Form/Admin/SearchUsers.php @@ -38,7 +38,8 @@ class ZendAfi_Form_Admin_SearchUsers extends ZendAfi_Form { return $this ->setAction(Class_Url::absolute(['module' => 'admin', 'controller' => 'users', - 'action' => 'index'],null ,true)) + 'action' => 'index'], null, true)) + ->setAttrib('style', 'position: relative') ->setMethod('get'); } @@ -66,7 +67,8 @@ class ZendAfi_Form_Admin_SearchUsers extends ZendAfi_Form { ->addDisplayGroup(['by_id_site', 'by_role_level', 'by_valide_subscription', - 'search_for'], + 'search_for', + 'submit_form'], 'search_group', ['legend' => $this->_('Recherche')]); } diff --git a/library/ZendAfi/View/Helper/Admin/SearchUsers.php b/library/ZendAfi/View/Helper/Admin/SearchUsers.php index 6ba3203bc4d5e3cfcf396cf3244563773dedf500..f520826712242a373f3fc4b3821ae8fd1d4343ee 100644 --- a/library/ZendAfi/View/Helper/Admin/SearchUsers.php +++ b/library/ZendAfi/View/Helper/Admin/SearchUsers.php @@ -22,22 +22,16 @@ class ZendAfi_View_Helper_Admin_SearchUsers extends ZendAfi_View_Helper_BaseHelper { - public function admin_searchUsers($users, $total, $form, $page) { - $html = $this->view->renderForm($form, [$this->view->bouton('id=19', - 'picto=show.gif', - 'texte='.$this->view->_('Rechercher'), - 'url='. $this->view->url(['action'=> 'index']), - 'largeur=100%')]); - - $html .= $this->_addButton(); - + public function admin_searchUsers($users, $total, $form, $page, $params) { + $html = $this->_addButton(); + $html .= $this->view->renderForm($form); $html .= $this->view->tag('p', $this->view->_plural($total, - 'Auncun utilisateur', - '%d utilisateur correspondant à votre recherche', - '%d utilisateurs correspondant à votre recherche', + 'Auncun utilisateur trouvé', + '%d utilisateur trouvé', + '%d utilisateurs trouvés', $total)); - $html .= $this->_getUsersTable($users, $total, $page); + $html .= $this->_getUsersTable($users, $total, $page, $params); return $html; } @@ -55,12 +49,12 @@ class ZendAfi_View_Helper_Admin_SearchUsers extends ZendAfi_View_Helper_BaseHelp } - protected function _getUsersTable($users, $total, $page) { + protected function _getUsersTable($users, $total, $page, $params) { $acl = new ZendAfi_Acl_AdminControllerRoles(); $pager = $this->view->Pager($total, - 30, + 20, $page, - $this->view->url()); + array_merge($params, ['page' => null])); $role_renderer = function($model) use($acl){ return $acl->getLibelleRole($model->getRoleLevel()); @@ -70,18 +64,18 @@ class ZendAfi_View_Helper_Admin_SearchUsers extends ZendAfi_View_Helper_BaseHelp return $model->getLibelleBib(); }; - $actions = function($user) { - return $this->view->tagAnchor($this->view->url(['module' => 'admin', - 'controller' => 'users', - 'action' => 'edit', - 'id' => $user->getid()]), + $actions = function($user) use($params){ + return $this->view->tagAnchor($this->view->url(array_merge(['module' => 'admin', + 'controller' => 'users', + 'action' => 'edit', + 'id' => $user->getid()], $params)), $this->view->boutonIco('type=edit')) . - $this->view->tagAnchor($this->view->url(['module' => 'admin', - 'controller' => 'users', - 'action' => 'delete', - 'id' => $user->getid()]), - $this->view->boutonIco('type=del')); + $this->view->tagAnchor($this->view->url(array_merge(['module' => 'admin', + 'controller' => 'users', + 'action' => 'delete', + 'id' => $user->getid()], $params)), + $this->view->boutonIco('type=del')); }; $table = $this->view->tagModelTable($users, @@ -104,12 +98,11 @@ class ZendAfi_View_Helper_Admin_SearchUsers extends ZendAfi_View_Helper_BaseHelp return $pager . $table . $pager; } - - /* protected function _getPagerParams() { */ - /* return ['search_for' => $this->_getParam('search_for', null), */ - /* 'search_by_id_site' => $this->_getParam('search_by_id_site', null), */ - /* 'search_by_role_level' => $this->_getParam('search_by_role_level', ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB), */ - /* 'search_by_valide_subscription' => $this->_getParam('search_by_valide_subscription', null)]; */ - /* } */ + protected function _getPagerParams() { + return ['search_for' => $this->_getParam('search_for', null), + 'search_by_id_site' => $this->_getParam('search_by_id_site', null), + 'search_by_role_level' => $this->_getParam('search_by_role_level', ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB), + 'search_by_valide_subscription' => $this->_getParam('search_by_valide_subscription', null)]; + } } ?> \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/UsersControllerTest.php b/tests/application/modules/admin/controllers/UsersControllerTest.php index 47b38c9760c47c52f8af7ee3c5f8096e1c0fb08b..4a96645c4a0a91a0448b6aa327afd4ff2b4e3e00 100644 --- a/tests/application/modules/admin/controllers/UsersControllerTest.php +++ b/tests/application/modules/admin/controllers/UsersControllerTest.php @@ -97,19 +97,100 @@ abstract class UsersControllerWithMarcusTestCase extends AbstractControllerTestC class UsersControllerIndexTest extends UsersControllerWithMarcusTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/admin/users', true); + + $user = $this->fixture('Class_Users', + ['id' => 1, + 'login' => 'tom', + 'password' => 'rom', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::SUPER_ADMIN]); + + $francis = $this->fixture('Class_Users', + ['id' => 57, + 'login' => 'francis', + 'password' => 'francis']); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getIdentity') + ->answers($user) + + ->whenCalled('hasIdentity') + ->answers($user) + + ->whenCalled('findSearched') + ->with(['id_site' => 0, + 'role_level' => 2] , + ['login' => 'francis', + 'nom' => 'francis', + 'prenom' => 'francis', + 'mail' => 'francis', + 'idabon' => 'francis'], + '1', + ['limitPage' => [1, 20]]) + ->answers([$francis]) + + ->whenCalled('countSearched') + ->with(['id_site' => 0, + 'role_level' => 2] , + ['login' => 'francis', + 'nom' => 'francis', + 'prenom' => 'francis', + 'mail' => 'francis', + 'idabon' => 'francis'], + '1', + ['limitPage' => [1, 20]]) + ->answers(55) + + ->beStrict(); + + $this->dispatch('/admin/users?by_id_site=0&by_role_level=2&by_valide_subscription=1&search_for=francis', true); } /** @test */ - public function formShouldContainsInputForNom() { - $this->assertXPath('//input[@name="nom"]'); + public function formShouldContainsInputSearch() { + $this->assertXPath('//input[@name="search_for"]'); } /** @test */ public function formShouldContainsRoleSelect() { - $this->assertXPath('//select[@name="role"]',$this->_response->getBody()); + $this->assertXPath('//select[@name="by_role_level"]'); + } + + + /** @test */ + public function libSelectorShouldBePresent() { + $this->assertXPath('//select[@name="by_id_site"]'); + } + + + /** @test */ + public function addUserButtonShouldBePresent() { + $this->assertXPath('//div[contains(@onclick, "admin/users/add")]'); + } + + + /** @test */ + public function totalUsersShouldBeFiftyFive() { + $this->assertXPathContentContains('//p','55 utilisateurs trouvés'); + } + + + /** @test */ + public function linkToEditFrancisShouldBePresent() { + $this->assertXPath('//table//tr//a[contains(@href, "users/edit/id/57/by_id_site/0/by_role_level/2")]'); + } + + + /** @test */ + public function linkToDeleteFrancisShouldBePresent() { + $this->assertXPath('//table//tr//a[contains(@href, "users/delete/id/57/by_id_site/0/by_role_level/2")]'); + } + + + /** @test */ + public function pagerShouldBePresent() { + $this->assertXPath('//div[@class="pager"]//span[1][@class="current"]'); } }