/** * @return void */ public function testPaginate() { Configure::write('Paginator.limit', 2); $ToolsUser = TableRegistry::get('ToolsUsers'); $count = $ToolsUser->find('count'); $this->assertTrue($count > 3); $this->Controller->loadModel('ToolsUsers'); $result = $this->Controller->paginate('ToolsUsers'); $this->assertSame(2, count($result->toArray())); }
/** * Formats and enriches field configs * * @return array */ public function getFilters() { if (method_exists($this->_controller, 'getListFilters')) { $filters = $this->_controller->getListFilters($this->_controller->request->action); } elseif (!empty($this->_controller->listFilters[$this->_controller->request->action])) { $filters = $this->_controller->listFilters[$this->_controller->request->action]; } if (empty($filters)) { return []; } foreach ($filters['fields'] as $field => &$fieldConfig) { if (isset($fieldConfig['type']) && $fieldConfig['type'] == 'select' && !isset($fieldConfig['searchType'])) { $fieldConfig['searchType'] = 'select'; $fieldConfig['inputOptions']['type'] = 'select'; unset($fieldConfig['type']); } // backwards compatibility if (isset($fieldConfig['type'])) { $fieldConfig['inputOptions']['type'] = $fieldConfig['type']; unset($fieldConfig['type']); } if (isset($fieldConfig['label'])) { $fieldConfig['inputOptions']['label'] = $fieldConfig['label']; unset($fieldConfig['label']); } if (isset($fieldConfig['searchType']) && in_array($fieldConfig['searchType'], ['select', 'multipleselect'])) { if (!isset($fieldConfig['inputOptions']['type'])) { $fieldConfig['inputOptions']['type'] = 'select'; } if (!isset($fieldConfig['inputOptions']['empty'])) { $fieldConfig['inputOptions']['empty'] = true; } } $fieldConfig = Hash::merge($this->defaultListFilter, $fieldConfig); } return $filters; }
/** * Used to configure authentication * * @return void */ protected function _setupAuth() { $this->_controller->loadComponent('Auth'); $authConfig = ['authenticate' => ['FOC/Authenticate.MultiColumn' => ['fields' => ['username' => 'username', 'password' => 'password'], 'columns' => Configure::read('App++.Authentication.identificationColumns'), 'userModel' => 'Users']], 'logoutRedirect' => ['plugin' => false, 'admin' => false, 'controller' => 'Pages', 'action' => 'display', 'home'], 'loginRedirect' => ['plugin' => false, 'admin' => false, 'controller' => 'Users', 'action' => 'index'], 'loginAction' => ['plugin' => false, 'admin' => false, 'prefix' => false, 'controller' => 'Accounts', 'action' => 'login'], 'unauthorizedRedirect' => ['plugin' => false, 'admin' => false, 'prefix' => false, 'controller' => 'Pages', 'action' => 'display', 'unauthorized']]; // Optionally enable JSON Web Token (JWT) authentication and set it as // the primary authentication mechanism, FoC used as fallback. if (Configure::read('App++.Authentication.jwt')) { $authConfig['authenticate'] = array_merge(['ADmad/JwtAuth.Jwt' => ['parameter' => '_token', 'userModel' => 'Users', 'fields' => ['id' => 'id']]], $authConfig['authenticate']); } // Enable Authorization using app_custom.php setting if (Configure::read('App++.Authorization.enabled')) { $authConfig['authorize'] = ['TinyAuth.Tiny' => ['autoClearCache' => true, 'allowUser' => false, 'allowAdmin' => false, 'adminRole' => 'admin', 'superAdminRole' => null, 'rolesTable' => Configure::read('App++.Authorization.rolesTable')]]; // Use non-default role column using app_custom.php setting (single-role only) if (Configure::read('App++.Authorization.roleColumn')) { $authConfig['authorize']['TinyAuth.Tiny']['roleColumn'] = Configure::read('App++.Authorization.roleColumn'); } // Enable multirole using app_custom.php setting if (Configure::read('App++.Authorization.multiRole')) { $authConfig['authorize']['TinyAuth.Tiny']['multiRole'] = true; } } // Load Auth and/or Authorize $this->_controller->loadComponent('Auth', $authConfig); }