- <?php
- class AppController extends Controller
- {
- var $helpers = array('Html', 'Form', 'Session', 'Recording', 'Taggable', 'Time', 'Javascript', 'Text', 'Persiandate', 'Website', 'Rss');
- var $components = array('Session', 'Redirect', 'Auth', 'Email', 'RequestHandler');
- var $userId = null;
- function beforeFilter()
- {
- if (isset($this->params['admin']) && $this->params['admin'])
- $this->layout = 'admin';
- $this->userId = $this->Auth->user('id');
- //$this->Auth->allow('*');
- $this->Auth->authError = "Sorry, you are lacking access.";
- $this->Auth->loginError = 'نام کاربري يا رمز عبور شما اشتباه است.';
- $this->Auth->fields = array('username' => 'email', 'password' => 'password');
- $this->Auth->loginAction = array(
- 'controller' => 'users',
- 'action' => 'login',
- 'admin' => true
- );
- //$this->Auth->autoRedirect = false;
- $this->Auth->loginRedirect = array('controller' => 'dashboard', 'action' => 'index');
- }
- function userId()
- {
- $this->userId = $this->Auth->user('id');
- }
- function searchConditions($params = null)
- {
- $conditions = array();
- $statuses = array('published' => '1', 'drafts' => '2');
- if (isset($params['named']['q']))
- {
- $conditions["MATCH({$this->postType}.title, {$this->postType}.body) AGAINST(? IN BOOLEAN MODE)"] =
- $params['named']['q'];
- }
- if (isset($params['named']['status']) && isset($statuses[$params['named']['status']]))
- {
- $conditions["{$this->postType}.status_id"] = $statuses[$params['named']['status']];
- }
- return $conditions;
- }
- function habtmConditions($param, $model, $habtm)
- {
- $conditions = array();
- $assocModel = $this->{$model}->hasAndBelongsToMany[$habtm];
- $assocHabtm = $this->{$model}->{$habtm}->hasAndBelongsToMany[$model];
- if (isset($param))
- {
- $conditions['joins'][] = array('table' => $assocModel['joinTable'], 'alias' => $assocModel['with'],
- 'type' => 'inner', 'foreignKey' => false, 'conditions' => array("{$assocModel['with']}.{$assocModel['foreignKey']} = {$this->{$model}->alias}.{$this->{$model}->primaryKey}"));
- $conditions['joins'][] = array('table' => $this->{$model}->{$habtm}->table,
- 'alias' => $habtm, 'type' => 'inner', 'foreignKey' => false, 'conditions' =>
- array("{$habtm}.{$this->{$model}->{$habtm}->primaryKey} = {$assocHabtm['with']}.{$assocHabtm['foreignKey']}",
- "{$habtm}.name" => explode(',', $param)));
- }
- $conditions['group'] = "{$model}.{$this->{$model}->primaryKey}";
- return $conditions;
- }
- }
- ?>