Пример #1
0
 protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
 {
     /* @var $adapter Zend_Db_Adapter_Abstract */
     $adapter = $query->getAdapter();
     $operator = $this->getDataSetDefault('operator', $this->helper()->getDefaultOperatorByType($this->_inputType));
     $value = $this->getData(self::VALUE_KEY);
     if ($this->_inputType === 'boolean') {
         $value = '1';
     }
     switch ($operator) {
         case '!=':
         case '>=':
         case '<=':
         case '>':
         case '<':
             return $query->where("{{$this->_requireBinding}} {$operator} ?", $value);
             break;
         case '{}':
             return $query->where("{{$this->_requireBinding}} LIKE ?", "%{$value}%");
             break;
         case '!{}':
             return $query->where("{{$this->_requireBinding}} NOT LIKE ?", "%{$value}%");
             break;
         case '()':
             return $query->where("{{$this->_requireBinding}} IN (?)", $this->_explode($value));
             break;
         case '!()':
             return $query->where("{{$this->_requireBinding}} NOT IN (?)", $this->_explode($value));
             break;
         default:
             return $query->where("{{$this->_requireBinding}} = ?", $value);
             break;
     }
 }
Пример #2
0
 protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
 {
     $attribute = $this->getAttribute();
     $adapter = $query->getAdapter();
     $field = $query->joinAttribute($this->_requireBinding, $attribute);
     $query->addBinding('attribute_value', $field);
     $operator = $this->getDataSetDefault('operator', $this->helper()->getDefaultOperatorByType($this->getInputType()));
     $value = $this->getData(self::VALUE_KEY);
     /*
      * Relative data attributes
      */
     if ($this->getData('relative')) {
         $future = $this->getDirection() == 'future';
         $usesLocalTime = (bool) $this->getAttributeConfig($attribute, 'uses_local_time', false);
         if ($this->getAnniversary()) {
             $query->where($this->getAnniversaryTimeExpr('{attribute_value}', self::VALUE_KEY, $future, $usesLocalTime));
         } else {
             $query->where($this->getTimeRangeExpr('{attribute_value}', self::VALUE_KEY, $future, $usesLocalTime));
         }
         return;
     }
     /*
      * Multi select attributes are saved as list in varchar
      * (e.g. 123,1457,124,21)
      * 
      * @todo can we use an index?
      */
     if ($attribute->getFrontendInput() === 'multiselect') {
         $value = (array) $value;
         $where = array();
         foreach ($value as $v) {
             $where[] = $adapter->quoteInto("FIND_IN_SET(?, {attribute_value})", $v);
         }
         if (strpos($operator, '()') !== false) {
             $where = implode(' OR ', $where);
         } else {
             $where = implode(' AND ', $where);
         }
         if (strpos($operator, '!') === 0) {
             $where = "!({$where})";
         }
         $query->where($where);
         return;
     }
     switch ($operator) {
         case '!=':
         case '>=':
         case '<=':
         case '>':
         case '<':
             return $query->where("{attribute_value} {$operator} ?", $this->_implode($value));
             break;
         case '{}':
             return $query->where("{attribute_value} LIKE ?", "%{$value}%");
             break;
         case '!{}':
             return $query->where("{attribute_value} NOT LIKE ?", "%{$value}%");
             break;
         case '()':
             return $query->where("{attribute_value} IN (?)", $this->_explode($value));
             break;
         case '!()':
             return $query->where("{attribute_value} NOT IN (?)", $this->_explode($value));
             break;
         default:
             return $query->where("{attribute_value} = ?", $this->_implode($value));
             break;
     }
 }
Пример #3
0
 /**
  * Set Query
  * 
  * @param Mzax_Emarketing_Db_Select $query
  * @return Mzax_Emarketing_Model_Object_Collection
  */
 public function setQuery(Mzax_Emarketing_Db_Select $query)
 {
     $this->_conn = $query->getAdapter();
     $this->_select = $query;
     return $this;
 }
Пример #4
0
 /**
  * 
  * (non-PHPdoc)
  * @see Mzax_Emarketing_Model_Object_Filter_Component::_prepareQuery()
  */
 protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
 {
     /* @var $adapter Zend_Db_Adapter_Abstract */
     $column = $this->getTableColumn();
     $adapter = $query->getAdapter();
     if (!$column) {
         throw new Exception("No valid table column defined");
     }
     if ($this->_tableIdFieldName) {
         $bind = array($this->_tableIdFieldName => $this->_requireBinding);
     } else {
         $bind = $this->_requireBinding;
     }
     $query->joinTable($bind, $this->_table, $this->_tableAlias);
     $query->addBinding('column_value', $column->name, $this->_tableAlias);
     $operator = $this->getDataSetDefault('operator', $this->helper()->getDefaultOperatorByType($this->getInputType()));
     $value = $this->getData(self::VALUE_KEY);
     // relative date
     if ($this->getData('relative')) {
         $future = $this->getDirection() == 'future';
         if ($this->getAnniversary()) {
             $query->where($this->getAnniversaryTimeExpr('{column_value}', self::VALUE_KEY, $future, $column->applyGmtOffset));
         } else {
             $query->where($this->getTimeRangeExpr('{column_value}', self::VALUE_KEY, $future));
         }
         return;
     }
     if ($column->type === 'boolean') {
         $value = '1';
     }
     switch ($operator) {
         case '!=':
         case '>=':
         case '<=':
         case '>':
         case '<':
             return $query->where("{column_value} {$operator} ?", $value);
             break;
         case '{}':
             return $query->where("{column_value} LIKE ?", "%{$value}%");
             break;
         case '!{}':
             return $query->where("{column_value} NOT LIKE ?", "%{$value}%");
             break;
         case '()':
             return $query->where("{column_value} IN (?)", $this->_explode($value));
             break;
         case '!()':
             return $query->where("{column_value} NOT IN (?)", $this->_explode($value));
             break;
         default:
             return $query->where("{column_value} = ?", $value);
             break;
     }
 }