Exemple #1
0
 /**
  * This event runs after we have built the query used to fetch a record list in a model. It is used to apply
  * automatic query filters based on model relations.
  *
  * @param   DataModel  &$model  The model which calls this event
  * @param   Query      &$query  The query we are manipulating
  *
  * @return  void
  */
 public function onAfterBuildQuery(&$model, &$query)
 {
     $relationFilters = $model->getRelationFilters();
     foreach ($relationFilters as $filterState) {
         $relationName = $filterState['relation'];
         $subQuery = $model->getRelations()->getCountSubquery($relationName);
         $filter = new DataModel\Filter\Relation($model->getDbo(), $relationName, $subQuery);
         $options = new Registry($filterState);
         $methods = $filter->getSearchMethods();
         $method = $options->get('method', $filter->getDefaultSearchMethod());
         if (!in_array($method, $methods)) {
             $method = 'exact';
         }
         switch ($method) {
             case 'between':
             case 'outside':
                 $sql = $filter->{$method}($options->get('from', null), $options->get('to'));
                 break;
             case 'interval':
                 $sql = $filter->{$method}($options->get('value', null), $options->get('interval'));
                 break;
             case 'search':
                 $sql = $filter->{$method}($options->get('value', null), $options->get('operator', '='));
                 break;
             default:
                 $sql = $filter->{$method}($options->get('value', null));
                 break;
         }
         if ($sql) {
             $query->where($sql);
         }
     }
 }
Exemple #2
0
 /**
  * This event runs after we have built the query used to fetch a record
  * list in a model. It is used to apply automatic query filters.
  *
  * @param   DataModel  &$model  The model which calls this event
  * @param   Query      &$query  The query we are manipulating
  *
  * @return  void
  */
 public function onAfterBuildQuery(&$model, &$query)
 {
     $tableName = $model->getTableName();
     $tableKey = $model->getIdFieldName();
     $db = $model->getDbo();
     $fields = $model->getTableFields();
     foreach ($fields as $fieldname => $fieldmeta) {
         $fieldInfo = (object) array('name' => $fieldname, 'type' => $fieldmeta->Type);
         $filterName = $fieldInfo->name == $tableKey ? 'id' : $fieldInfo->name;
         $filterState = $model->getState($filterName, null);
         $field = DataModel\Filter\AbstractFilter::getField($fieldInfo, array('dbo' => $db));
         if (!is_object($field) || !$field instanceof DataModel\Filter\AbstractFilter) {
             continue;
         }
         if (is_array($filterState) && (array_key_exists('value', $filterState) || array_key_exists('from', $filterState) || array_key_exists('to', $filterState)) || is_object($filterState)) {
             $options = new Registry($filterState);
         } else {
             $options = new Registry();
             $options->set('value', $filterState);
         }
         $methods = $field->getSearchMethods();
         $method = $options->get('method', $field->getDefaultSearchMethod());
         if (!in_array($method, $methods)) {
             $method = 'exact';
         }
         switch ($method) {
             case 'between':
             case 'outside':
                 $sql = $field->{$method}($options->get('from', null), $options->get('to'));
                 break;
             case 'interval':
                 $sql = $field->{$method}($options->get('value', null), $options->get('interval'));
                 break;
             case 'search':
                 $sql = $field->{$method}($options->get('value', null), $options->get('operator', '='));
                 break;
             case 'exact':
             case 'partial':
             default:
                 $sql = $field->{$method}($options->get('value', null));
                 break;
         }
         if ($sql) {
             $query->where($sql);
         }
     }
 }
Exemple #3
0
 /**
  * Public constructor
  *
  * @param Container $container The DI container we belong to
  * @param null      $data      [optional] Data to initialise the application configuration
  */
 public function __construct(Container $container, $data = null)
 {
     parent::__construct($data);
     $this->container = $container;
 }
Exemple #4
0
 /**
  * Merge a Registry object into this one
  *
  * @param   Registry  $source     Source Registry object to merge.
  * @param   boolean   $recursive  True to support recursive merge the children values.
  *
  * @return  Registry  Return this object to support chaining.
  */
 public function merge(Registry $source, $recursive = false)
 {
     $this->bindData($this->data, $source->toArray(), $recursive);
     return $this;
 }