Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 2.86 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. class AppController extends Controller
  4. {
  5.  
  6.     var $helpers = array('Html', 'Form', 'Session', 'Recording', 'Taggable', 'Time', 'Javascript', 'Text', 'Persiandate', 'Website', 'Rss');
  7.     var $components = array('Session', 'Redirect', 'Auth', 'Email', 'RequestHandler');
  8.     var $userId = null;
  9.  
  10.     function beforeFilter()
  11.     {
  12.         if (isset($this->params['admin']) && $this->params['admin'])
  13.             $this->layout = 'admin';
  14.  
  15.         $this->userId = $this->Auth->user('id');
  16.         //$this->Auth->allow('*');
  17.         $this->Auth->authError = "Sorry, you are lacking access.";
  18.         $this->Auth->loginError = 'نام کاربري يا رمز عبور شما اشتباه است.';
  19.         $this->Auth->fields = array('username' => 'email', 'password' => 'password');
  20.  
  21.                  
  22.         $this->Auth->loginAction = array(
  23.             'controller' => 'users',
  24.             'action' => 'login',
  25.             'admin' => true
  26.         );
  27.                
  28.         //$this->Auth->autoRedirect = false;  
  29.         $this->Auth->loginRedirect = array('controller' => 'dashboard', 'action' => 'index');    
  30.     }
  31.     function userId()
  32.     {
  33.         $this->userId = $this->Auth->user('id');
  34.     }
  35.     function searchConditions($params = null)
  36.     {
  37.         $conditions = array();
  38.         $statuses = array('published' => '1', 'drafts' => '2');
  39.         if (isset($params['named']['q']))
  40.         {
  41.             $conditions["MATCH({$this->postType}.title, {$this->postType}.body) AGAINST(? IN BOOLEAN MODE)"] =
  42.                 $params['named']['q'];
  43.         }
  44.         if (isset($params['named']['status']) && isset($statuses[$params['named']['status']]))
  45.         {
  46.             $conditions["{$this->postType}.status_id"] = $statuses[$params['named']['status']];
  47.         }
  48.         return $conditions;
  49.     }
  50.  
  51.     function habtmConditions($param, $model, $habtm)
  52.     {
  53.         $conditions = array();
  54.         $assocModel = $this->{$model}->hasAndBelongsToMany[$habtm];
  55.         $assocHabtm = $this->{$model}->{$habtm}->hasAndBelongsToMany[$model];
  56.         if (isset($param))
  57.         {
  58.             $conditions['joins'][] = array('table' => $assocModel['joinTable'], 'alias' => $assocModel['with'],
  59.                 'type' => 'inner', 'foreignKey' => false, 'conditions' => array("{$assocModel['with']}.{$assocModel['foreignKey']} = {$this->{$model}->alias}.{$this->{$model}->primaryKey}"));
  60.             $conditions['joins'][] = array('table' => $this->{$model}->{$habtm}->table,
  61.                 'alias' => $habtm, 'type' => 'inner', 'foreignKey' => false, 'conditions' =>
  62.                 array("{$habtm}.{$this->{$model}->{$habtm}->primaryKey} = {$assocHabtm['with']}.{$assocHabtm['foreignKey']}",
  63.                 "{$habtm}.name" => explode(',', $param)));
  64.         }
  65.         $conditions['group'] = "{$model}.{$this->{$model}->primaryKey}";
  66.         return $conditions;
  67.     }
  68.  
  69.  
  70. }
  71.  
  72. ?>