Exemple #1
0
 /**
  * Makes the search conditions if the normal conditions are
  * not met and if given date is an array,
  * for example when only the year or year-month is given.
  *
  * @param Query $query Query which is given in getSearchCondition
  * @param string $table Table on which the condition must be executed
  * @param array $value Array with values given for the search
  *
  * @return string YYYY-MM or YYYY
  */
 public function _getDateArraySearchCondition($query, $table, $value)
 {
     $db = $this->getDb();
     $fromvalue = $this->_MakeDateForCondition($value['from']);
     $tovalue = $this->_MakeDateForCondition($value['to']);
     $datearraysearchcondition = '';
     if ($fromvalue != '') {
         $field = $db->func_datetochar($table . '.' . $this->fieldName(), $this->_SetDateFormat($value['from']));
         $datearraysearchcondition = $query->greaterthanequalCondition($field, $fromvalue);
         // check if tovalue is set, if so add the AND
         if ($tovalue != '') {
             $datearraysearchcondition .= ' AND ';
         }
     }
     if ($tovalue != '') {
         $field = $db->func_datetochar($table . '.' . $this->fieldName(), $this->_SetDateFormat($value['to']));
         $datearraysearchcondition .= $query->lessthanequalCondition($field, $tovalue);
     }
     return $datearraysearchcondition;
 }
Exemple #2
0
 /**
  * Get the between search condition.
  *
  * @param Query $query The query object where the search condition should be placed on
  * @param string $fieldname The name of the field in the database
  * @param array $value The processed search value
  *
  * @return string query where clause for searching
  */
 public function getBetweenCondition($query, $fieldname, $value)
 {
     if ($value['from'] != '' && $value['to'] != '') {
         if ($value['from'] > $value['to']) {
             // User entered fields in wrong order. Let's fix that.
             $tmp = $value['from'];
             $value['from'] = $value['to'];
             $value['to'] = $tmp;
         }
         return $query->betweenCondition($fieldname, $this->escapeSQL($value['from']), $this->escapeSQL($value['to']));
     } elseif ($value['from'] != '' && $value['to'] == '') {
         return $query->greaterthanequalCondition($fieldname, $value['from']);
     } elseif ($value['from'] == '' && $value['to'] != '') {
         return $query->lessthanequalCondition($fieldname, $value['to']);
     }
     return '';
 }