Example #1
0
 /**
  * @return string
  */
 public function calculateSubQuery()
 {
     if (!$this->model) {
         $this->getModel();
         //$this->model=$this->add($this->model_name);
     }
     /** @type SQL_Model $this->model */
     if ($this->display_field) {
         $title = $this->model->dsql()->del('fields');
         $this->model->getElement($this->display_field)->updateSelectQuery($title);
     } elseif ($this->model->hasMethod('titleQuery')) {
         $title = $this->model->titleQuery();
     } else {
         // possibly references non-sql model, so just display field value
         return $this->owner->dsql()->bt($this->short_name);
     }
     $title->del('order')->where($this, $title->getField($this->model->id_field));
     return $title;
 }
 protected function _meetsCondition(Model $model, $value, $operator, $parameters)
 {
     switch ($operator) {
         case '=':
         case '':
             $operator = 'equal';
             break;
         case '!=':
             $operator = 'notequal';
             break;
         case '>=':
             $operator = 'greaterorequal';
             break;
         case '<=':
             $operator = 'lessorequal';
             break;
         case '>':
             $operator = 'greater';
             break;
         case '<':
             $operator = 'less';
             break;
     }
     // remove everything except A-z a-z 0-9 - _
     $operator = preg_replace('/[^a-z0-9\\-_]/i', '', $operator);
     $operator = strtolower($operator);
     $methodName = '_operator' . ucfirst($operator);
     if ($model->hasMethod($methodName)) {
         if (TRUE === $model->{$methodName}($value, $parameters)) {
             return TRUE;
         } else {
             return FALSE;
         }
     }
     if (TRUE === $this->{$methodName}($value, $parameters)) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
 /**
 * Executed after a model is deleted.
 *
 * @param 	$Model
 * @return	void
 */
 public function afterDelete(Model $Model)
 {
     /*
      * If a currentUser() method exists in the model class (or, of
      * course, in a superclass) the call that method to pull all user
      * data. Assume than an id field exists.
      */
     $source = array();
     if ($Model->hasMethod('currentUser')) {
         $source = $Model->currentUser();
     } else {
         if ($Model->hasMethod('current_user')) {
             $source = $Model->current_user();
         }
     }
     $audit = array($Model->alias => $this->_original[$Model->alias]);
     $data = array('Audit' => array('event' => 'DELETE', 'model' => $Model->alias, 'entity_id' => $Model->id, 'json_object' => json_encode($audit), 'source_id' => isset($source['id']) ? $source['id'] : null, 'description' => isset($source['description']) ? $source['description'] : null));
     $this->Audit = ClassRegistry::init('Audit');
     $this->Audit->useDbConfig = Configure::read('auditable.name');
     $this->Audit->create();
     $this->Audit->save($data);
 }
 /**
  * Executed after a model is deleted.
  *
  * @param 	$Model
  * @return	void
  */
 public function afterDelete(Model $Model)
 {
     /*
      * If a currentUser() method exists in the model class (or, of
      * course, in a superclass) the call that method to pull all user
      * data. Assume than an id field exists.
      */
     $source = array();
     if ($Model->hasMethod('currentUser')) {
         $source = $Model->currentUser();
     } else {
         if ($Model->hasMethod('current_user')) {
             $source = $Model->current_user();
         }
     }
     $audit = array($Model->alias => $this->_original[$Model->alias]);
     $data = array('Audit' => array('event' => 'DELETE', 'model' => $Model->alias, 'entity_id' => $Model->id, 'json_object' => json_encode($audit), 'source_id' => isset($source) ? $source['id'] : 0, 'description' => isset($source) ? $source['nombre'] . " " . $source['paterno'] . " " . $source['materno'] : null, 'ip' => $_SERVER['REMOTE_ADDR'], 'browserOS' => $this->getBrowser(), 'OS' => $this->getOS(), 'URL_referrer' => $_SERVER['HTTP_REFERER']));
     $this->Audit = ClassRegistry::init('Audit');
     $this->Audit->create();
     $this->Audit->save($data);
 }
 /**
  * Sifter config for foreign keys
  *
  * @param Model $Model the model being used
  * @param string $field the field being used
  *
  * @return array
  */
 protected function _fieldTypeForeignKey(Model $Model, $field)
 {
     $method = 'sifter' . Inflector::camelize(Inflector::pluralize(self::_stripId($field)));
     if (array_key_exists($method, $Model->findMethods) && $Model->findMethods[$method] === true) {
         $methodType = 'customFind';
     } elseif ($Model->hasMethod($method)) {
         $methodType = 'method';
     } else {
         $method = 'list';
         $methodType = 'customFind';
     }
     return array('input' => array('label' => __d('sifter', 'Filter by %s', __d('sifter', self::_friendlyName($field))), 'type' => 'select', 'multiple' => true, 'empty' => false, 'options' => array('className' => $this->_relatedModelName($Model, $field), 'method' => $method, 'methodType' => $methodType)), 'operator' => 'IN');
 }
Example #6
0
 /**
  * Executed after a model is deleted.
  *
  * @param	$Model
  * @return	void
  */
 public function afterDelete(Model $Model)
 {
     // If a currentUser() method exists in the model class (or, of
     // course, in a superclass) the call that method to pull all user
     // data. Assume than an id field exists.
     $source = array();
     if ($Model->hasMethod('currentUser')) {
         $source = $Model->currentUser();
     } else {
         if ($Model->hasMethod('current_user')) {
             $source = $Model->current_user();
         } else {
             $source = AuthComponent::user();
         }
     }
     $audit = array($Model->alias => $this->_original[$Model->alias]);
     $data = array('Audit' => array('event' => 'DELETE', 'model' => $Model->alias, 'entity_id' => $Model->id, 'json_object' => json_encode($audit), 'source_id' => isset($source['id']) ? $source['id'] : null));
     $this->Audit = ClassRegistry::init('Audit');
     $this->Audit->create();
     $this->Audit->save($data);
 }
 /**
  * Search for a list of records that match the query.
  *
  * @param Model $model
  * @param array $query
  * @return array
  */
 public function searchTypeAhead(Model $model, array $query)
 {
     if ($model->hasMethod('searchTypeAhead')) {
         return $model->searchTypeAhead($query);
     }
     $keyword = $query['term'];
     unset($query['term']);
     $results = $model->find('all', array('conditions' => array($model->alias . '.' . $model->displayField . ' LIKE' => '%' . $keyword . '%') + $query, 'order' => array($model->alias . '.' . $model->displayField => 'ASC'), 'contain' => false));
     $data = array();
     foreach ($results as $result) {
         $data[] = array('id' => $result[$model->alias][$model->primaryKey], 'title' => $result[$model->alias][$model->displayField]);
     }
     return $data;
 }