Beispiel #1
0
 /**
  * 
  * @return Zend_Db_Select
  */
 protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
 {
     $this->checkIndexes(true);
     $conditions = $this->_getConditions();
     $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR);
     $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION);
     $select = $this->_combineConditions($conditions, $aggregator, $expectation);
     $select->useTemporaryTable($this->getTempTableName());
     $addressId = $query->joinAttribute('customer_id', 'customer/default_billing');
     $query->joinSelect(array('id' => $addressId), $select, 'filter');
     $query->group();
 }
Beispiel #2
0
 protected function _prepareQuery(Mzax_Emarketing_Db_Select $query)
 {
     $firstname = $query->joinAttribute('customer_id', 'customer/firstname');
     $lastname = $query->joinAttribute('customer_id', 'customer/lastname');
     $query->where($this->getWhereSql('name', "CONCAT_WS(' ', {$firstname}, {$lastname})"));
 }
Beispiel #3
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;
     }
 }