Ejemplo n.º 1
0
 /**
  * Before Render hook function
  * @see AppHelper::beforeRender
  */
 function beforeRender()
 {
     if (!isset($this->model)) {
         $this->model = Common::getModel('Action');
         // initialize model or get it back
     }
 }
Ejemplo n.º 2
0
 /**
  * Before filter function redefinition
  * @see Controller::beforeFilter
  */
 function beforeFilter()
 {
     parent::beforeFilter();
     $this->models = array_keys(Configure::read('App.favorites.models'), true);
     foreach ($this->models as $model) {
         $this->{$model} = Common::getModel($model);
         $this->Favorite->bindModel(array('belongsTo' => array($model => array('foreignKey' => 'foreign_id'))));
     }
 }
Ejemplo n.º 3
0
 /**
  * Get the last n user log entries grouped by location
  * @param int $limit
  * @return array $results
  */
 static function get($limit = 5)
 {
     $_this = Common::getModel('UserLog');
     $results = $_this->find('all', array('fields' => array('resource', 'resource_id', 'get_data_url', 'get_data_named', 'action', 'user_id', 'MAX(UserLog.created) as created'), 'conditions' => array('user_id' => User::get('id'), 'resource_type' => 'controller'), 'group' => array('resource_type', 'action', 'get_data_url'), 'order' => 'created DESC', 'limit' => $limit));
     foreach ($results as $i => $value) {
         $results[$i]['UserLog']['created'] = $results[$i][0]['created'];
         unset($results[$i][0]);
     }
     //pr($results);
     return $results;
 }
Ejemplo n.º 4
0
 /**
  * Generate a link with the proper stared/unstared picture
  * @param $model
  * @param $uuid
  * @return string link
  */
 function link($uuid, $model, $isFavorited = null)
 {
     if (is_null($isFavorited)) {
         $isFavorited = Common::getModel('Favorite')->isFavorited($uuid, $model);
     }
     if (!$isFavorited) {
         $img = $this->Html->image($this->config['icons']['unfav'], array('alt' => __('unmark as favorite', true)));
         return $this->Html->link($img, array('controller' => 'favorites', 'action' => 'add', $uuid, $model), array('class' => 'star', 'escape' => false));
     } else {
         $img = $this->Html->image($this->config['icons']['fav'], array('alt' => __('mark as favorite', true)));
         return $this->Html->link($img, array('controller' => 'favorites', 'action' => 'delete', $uuid, $model), array('class' => 'star', 'escape' => false));
     }
 }
Ejemplo n.º 5
0
 /**
  * STATIC - Prepare static find
  * Bind models and define default find conditions
  * @param $_this instance of Favorites model
  * @param $conditions find conditions
  * @access private
  * @TODO move in archivable behavior?
  */
 static function __bindArchivableModels(&$_this, &$models, &$conditions, $archived)
 {
     $softDeleteModels = @array_keys(Configure::read('App.softdelete.models'), true);
     $softDeleteFields = Configure::read('App.softdelete.fields');
     $models = array_intersect($models, $softDeleteModels);
     $options = $hasManyOptions = array();
     //$conditions = array('Favorite.user_id' => User::get('id'));
     foreach ($models as $i => $model) {
         $options[$model] = array('foreignKey' => 'foreign_id');
         $Model = Common::getModel($model);
         $Model->bindModel(array('hasMany' => array('Favorite' => array('dependent' => true, 'foreignKey' => 'foreign_id'))), false);
         // dont retrieve archived records unless required
         foreach ($softDeleteFields as $field) {
             if (array_key_exists($field, $Model->_schema)) {
                 $alias = $Model->alias;
                 $value = $archived ? '1' : '0';
                 $conditions['conditions'][] = '(' . $alias . '.' . $field . '=' . $value . ' || ' . $alias . '.id IS NULL)';
             }
         }
     }
     $conditions['contain'] = $models;
     $_this->bindModel(array('belongsTo' => $options), false);
 }
Ejemplo n.º 6
0
 /**
  * Initiate behavior for the model using settings.
  *
  * @param object $Model Model using the behaviour
  * @param array $settings Settings to override for model.
  * @access public
  */
 function setup(&$Model, $settings = array())
 {
     $this->__UserLog = Common::getModel('UserLog');
 }
Ejemplo n.º 7
0
 /**
  * Initialize
  * @param object $controller Controller using this component
  * @param array $settings
  * @return void
  * @access public
  */
 function initialize(&$controller, $settings = array())
 {
     $this->Controller =& $controller;
     $this->__UserLog = Common::getModel('UserLog');
     $this->Controller->UserLog =& $this->__UserLog;
 }
Ejemplo n.º 8
0
 /**
  * Before Render hook function
  * @see AppHelper::beforeRender
  */
 function beforeRender()
 {
     if (!isset($this->model)) {
         $this->model = Common::getModel('Sidebar');
     }
 }
Ejemplo n.º 9
0
 /**
  * Set the user as current
  * @param array $user
  * @param bool $updateSession
  * @param bool $generateAuthCookie
  */
 static function setActive($user = null, $find = true)
 {
     $_this = Common::getModel('User');
     //@TODO only fetch if $user is incomplete compared to find conditions
     if ($find) {
         if ($user != 'guest' && isset($user['User']['id']) && Common::isUuid($user['User']['id'])) {
             $user = $_this->find('first', $_this->getFindOptions('userActivation', $user));
         }
         if ($user == 'guest' || is_null($user) || empty($user)) {
             $user = $_this->find('first', $_this->getFindOptions('guestActivation'));
         }
     }
     if (isset($user['User']['password'])) {
         unset($user['User']['password']);
         // just to make sure
     }
     Configure::write('User', $user);
     $Session = Common::getComponent('Session');
     $Session->write('User', $user);
     return $user;
 }
Ejemplo n.º 10
0
 /**
  * undocumented function
  *
  * @param unknown $key 
  * @param unknown $auth_key_type_id 
  * @return void
  * @access public
  */
 static function findUserId($key, $auth_key_type_id = null)
 {
     $_this = Common::getModel('AuthKey');
     if (!empty($auth_key_type_id) && !ctype_digit($auth_key_type_id)) {
         $auth_key_type_id = $_this->AuthKeyType->lookup($auth_key_type_id, 'id', false);
     }
     if (!empty($auth_key_type_id) && !ctype_digit($auth_key_type_id)) {
         return false;
     }
     $conditions = compact('key');
     $recursive = -1;
     if (!empty($auth_key_type_id)) {
         $conditions['auth_key_type_id'] = $auth_key_type_id;
     }
     $authKey = $_this->find('first', compact('conditions', 'recursive'));
     if (empty($authKey)) {
         return false;
     }
     return $authKey['AuthKey']['user_id'];
 }
Ejemplo n.º 11
0
 /**
  * Validate auth related data and return a user if any
  * @param string $context such as login, reset password, ect.
  * @param array $data from the form
  * @return array $user
  * @access private
  */
 function __validateInputAndGetUser($context, $data)
 {
     $user = null;
     $this->User = Common::getModel('User');
     // validate the input data
     $this->User->data = $data;
     $rules = $this->User->getValidationRules($context);
     if (empty($rules) || $this->User->validates($rules)) {
         // build search conditions
         $options = User::getFindOptions($context, $data);
         // find a user or die trying
         $user = $this->User->find('first', $options);
     }
     return $user;
 }