/** * Get the where clause * * @return db_where The where clause */ public function getWhere() { $where = $this->table->getWhere(); foreach ($this->form->getValues() as $name => $val) { $field = strpos($name, '.') === false ? $this->table->getName() . '.' . $name : $name; if (!is_null($val) && ($val || $val === '0')) { if (is_array($val)) { if (array_key_exists('min', $val) || array_key_exists('max', $val)) { $min = array_key_exists('min', $val) && !empty($val['min']) ? $val['min'] : null; $max = array_key_exists('max', $val) && !empty($val['max']) ? $val['max'] : null; if ($min) { $where->add(array('field' => $field, 'val' => $min, 'op' => '>=')); } if ($max) { $where->add(array('field' => $field, 'val' => $max, 'op' => '<=')); } } else { $fieldRel = $this->table->getRelated($name); $where->add(array('field' => $fieldRel ? $fieldRel['tableLink'] . '.' . $fieldRel['fk2']['name'] : $field, 'val' => array_map(array($this->table->getDb(), 'quoteValue'), $val), 'op' => 'IN')); } } else { if (strpos($name, '_file')) { $where->add(array('field' => $field, 'val' => '', 'op' => '<>')); } else { $f = $this->table->getField($name); if (is_array($f) && (!array_key_exists('text', $f) || $f['text'])) { $tmp = explode(' ', $val); array_walk($tmp, create_function('&$v', '$v = trim($v);')); $tmp = array_filter($tmp); foreach ($tmp as $t) { $where->add(array('field' => $field, 'val' => '%' . $t . '%', 'op' => 'LIKE')); } } else { if ($this->table->hasI18n() && db::isI18nName($name) && ($f = $this->table->getI18nTable()->getField(db::unI18nName($name)))) { $tblName = $this->table->getI18nTable()->getName(); $prim = $this->table->getI18nTable()->getPrimary(); $field = $tblName . '.' . db::unI18nName($name); $clause = '(' . $this->table->getName() . '.' . $this->table->getIdent() . ' IN (SELECT ' . $tblName . '.' . $prim[0] . ' FROM ' . $tblName . ' WHERE '; $tmpWhere = $this->table->getI18nTable()->getWhere(array('op' => 'OR')); if (!array_key_exists('text', $f) || $f['text']) { $tmp = explode(' ', $val); array_walk($tmp, create_function('&$v', '$v = trim($v);')); $tmp = array_filter($tmp); foreach ($tmp as $t) { $tmpWhere->add(array('field' => $field, 'val' => '%' . $t . '%', 'op' => 'LIKE')); } } else { $tmpWhere->add(array('field' => $field, 'val' => $val)); } $clause .= $tmpWhere . '))'; $where->add($clause); } else { $where->add(array('field' => $field, 'val' => $val)); } } } } $this->session->set(array('name' => $name, 'val' => $val)); } } if (count($where)) { return $where; } return null; }