/**
  * @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()));
 }
Example #2
1
 /**
  * Set the language for the user.
  *
  * @return void
  */
 public function setLanguage()
 {
     if ($this->_controller->Auth->user()) {
         //The user has already a valid language defined in the database.
         if ($this->_session->read('Auth.User.language') && isset($this->_locales[$this->_session->read('Auth.User.language')])) {
             //If the user has not the cookie, we set the cookie.
             if (!$this->_cookie->check('language') || $this->_cookie->read('language') != $this->_session->read('Auth.User.language')) {
                 $this->_cookie->write('language', $this->_session->read('Auth.User.language'));
             }
             //Stock the locale of the user.
             $this->_locale = $this->_session->read('Auth.User.language');
         }
     } else {
         //The user has a valid cookie.
         if ($this->_cookie->check('language') && isset($this->_locales[$this->_cookie->read('language')])) {
             $this->_locale = $this->_cookie->read('language');
         }
     }
     //The user want to change his language.
     if (isset($this->_controller->request->params['lang']) && isset($this->_locales[$this->_controller->request->params['lang']])) {
         //If the user is connected, we need to save the new language in the database and refresh his session.
         if ($this->_controller->Auth->user()) {
             $this->_controller->loadModel('Users');
             $user = $this->_controller->Users->find()->where(['id' => $this->_session->read('Auth.User.id')])->first();
             $user->language = $this->_controller->request->params['lang'];
             $this->_controller->Users->save($user);
             $this->_session->write('Auth.User.language', $this->_controller->request->params['lang']);
         }
         //Save the new language in the cookie.
         $this->_cookie->write('language', $this->_controller->request->params['lang']);
         $this->_locale = $this->_controller->request->params['lang'];
     }
     //Set the locale.
     I18n::locale($this->_locale);
 }
Example #3
0
 /**
  * Check if the currency match with the offer currency.
  *
  * @param array $custom The custom data passed to Paypal.
  * @param string $mcCurrency The currency to check.
  *
  * @return bool
  */
 protected function _isCurrencyValid(array $custom, $mcCurrency)
 {
     $this->_controller->loadModel('PremiumOffers');
     $offer = $this->_controller->PremiumOffers->find('offerByIdAndPeriod', ['id' => $custom['offer_id'], 'period' => $custom['period']]);
     if ($offer->currency_code != $mcCurrency) {
         Log::error(__('The currency offer {0} does not match with the Paypal currency {1}.', $offer->currency, $mcCurrency), 'paypal');
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * testLoadModel method
  *
  * @return void
  */
 public function testLoadModel()
 {
     $request = new Request('controller_posts/index');
     $response = $this->getMockBuilder('Cake\\Network\\Response')->getMock();
     $Controller = new Controller($request, $response);
     $this->assertFalse(isset($Controller->Articles));
     $result = $Controller->loadModel('Articles');
     $this->assertInstanceOf('TestApp\\Model\\Table\\ArticlesTable', $result);
     $this->assertInstanceOf('TestApp\\Model\\Table\\ArticlesTable', $Controller->Articles);
 }
Example #5
0
 /**
  * Sets the model class to be used during the action execution.
  *
  * @param string $modelName The name of the model to load.
  * @return void
  */
 public function useModel($modelName)
 {
     $this->_controller->loadModel($modelName);
     $this->_modelName = $this->_model->name;
 }
Example #6
0
 /**
  * Sets the model class to be used during the action execution.
  *
  * @param string $modelName The name of the model to load.
  * @return void
  */
 public function useModel($modelName)
 {
     $this->_controller->loadModel($modelName);
     list(, $this->_modelName) = pluginSplit($modelName);
 }
 /**
  * Creates a validation object on the fly.
  *
  * @return \Cake\Validation\Validator
  */
 protected function _createValidator()
 {
     $config = $this->config();
     if ($config['validator'] instanceof Validator) {
         return $config['validator'];
     }
     $this->_controller->loadModel('Comment.Comments');
     if ($this->_controller->request->is('userLoggedIn')) {
         // logged user posting
         $validator = $this->_controller->Comments->validationDefault(new Validator());
         $validator->requirePresence('user_id')->notEmpty('user_id', __d('comment', 'Invalid user.'))->add('user_id', 'checkUserId', ['rule' => function ($value, $context) {
             if (!empty($value)) {
                 $valid = TableRegistry::get('User.Users')->find()->where(['Users.id' => $value, 'Users.status' => 1])->count() === 1;
                 return $valid;
             }
             return false;
         }, 'message' => __d('comment', 'Invalid user, please try again.'), 'provider' => 'table']);
     } elseif ($this->config('settings.allow_anonymous')) {
         // anonymous user posting
         $validator = $this->_controller->Comments->validator('anonymous');
     } else {
         // other case
         $validator = new Validator();
     }
     if ($this->config('settings.use_captcha')) {
         $validator->add('body', 'humanCheck', ['rule' => function ($value, $context) {
             return CaptchaManager::adapter()->validate($this->_controller->request);
         }, 'message' => __d('comment', 'We were not able to verify you as human. Please try again.'), 'provider' => 'table']);
     }
     return $validator;
 }