41 $this->table = $this->cfg->table;
42 if (!$this->cfg->sessionName)
43 $this->cfg->sessionName = $this->table->getName();
46 'nameSpace'=>
'filterTable_'.$this->cfg->sessionName
49 if (!$this->cfg->check(
'clearPrm'))
50 $this->cfg->clearPrm =
'clearFilter'.ucfirst($this->table->getName());
51 $this->cfg->setinArray(
'actionPrmClear', $this->cfg->clearPrm,
true);
60 $this->
form =
factory::get(
'form_db', array_merge($this->cfg->formOpts, array(
62 'table'=>$this->table,
63 'sectionName'=>$this->cfg->formName,
64 'action'=>
request::uriDef(array(
'paramA'=>array_merge(array_diff_key(
request::get(
'paramA'), $this->cfg->actionPrmClear), $this->cfg->actionPrmForce)))
68 $this->
form->setSubmitplus(
'<a href="'.$this->
clearLink().
'">'.$this->cfg->clearText.
'</a>');
70 if (!empty($this->cfg->fields)) {
71 foreach($this->cfg->fields as $field) {
72 if (
$f = $this->table->getField($field)) {
74 $f[
'link'] = $this->table->getLinked(
$f[
'name']);
75 $this->
form->addFromFieldFilter(
$f);
76 }
else if ($r = $this->table->getRelated($field)) {
77 $r[
'label'] = $this->
getLabel($r[
'table']);
78 $r[
'name'] = $r[
'tableLink'];
79 $this->
form->addFromRelatedFilter($r);
84 $f[
'link'] = $this->table->getI18nTable()->getLinked($name);
85 $this->
form->addFromFieldFilter(
$f);
90 foreach($this->table->getField() as
$f) {
92 $f[
'link'] = $this->table->getLinked(
$f[
'name']);
93 $this->
form->addFromFieldFilter(
$f);
96 foreach($this->table->getRelated() as $t=>$r) {
97 $r[
'name'] = $r[
'tableLink'];
98 $r[
'label'] = $this->
getLabel($r[
'table']);
99 $this->
form->addFromRelated($r);
115 if ($this->
session->check($name))
116 $this->
form->
setValue($name, $this->session->get($name));
121 if ($v != $defValues[$k])
150 $where = $this->table->getWhere();
152 $field = strpos($name,
'.') ===
false ? $this->table->getName().
'.'.$name : $name;
153 if (!is_null($val) && ($val || $val ===
'0')) {
154 if (is_array($val)) {
155 if (array_key_exists(
'min', $val) || array_key_exists(
'max', $val)) {
156 $min = array_key_exists(
'min', $val) && !empty($val[
'min'])?$val[
'min'] : null;
157 $max = array_key_exists(
'max', $val) && !empty($val[
'max'])?$val[
'max'] : null;
171 $fieldRel = $this->table->getRelated($name);
173 'field'=>$fieldRel ? $fieldRel[
'tableLink'].
'.'.$fieldRel[
'fk2'][
'name'] : $field,
174 'val'=>array_map(array($this->table->getDb(),
'quoteValue'), $val),
178 }
else if(strpos($name,
'_file')) {
185 $f = $this->table->getField($name);
186 if (is_array(
$f) && (!array_key_exists(
'text',
$f) ||
$f[
'text'])) {
187 $tmp = explode(
' ', $val);
188 array_walk($tmp, create_function(
'&$v',
'$v = trim($v);'));
189 $tmp = array_filter($tmp);
190 foreach($tmp as $t) {
198 $tblName = $this->table->getI18nTable()->getName();
199 $prim = $this->table->getI18nTable()->getPrimary();
201 $clause =
'('.$this->table->getName().
'.'.$this->table->getIdent().
' IN (SELECT '.$tblName.
'.'.$prim[0].
' FROM '.$tblName.
' WHERE ';
203 $tmpWhere = $this->table->getI18nTable()->getWhere(array(
'op'=>
'OR'));
205 if (!array_key_exists(
'text',
$f) ||
$f[
'text']) {
206 $tmp = explode(
' ', $val);
207 array_walk($tmp, create_function(
'&$v',
'$v = trim($v);'));
208 $tmp = array_filter($tmp);
209 foreach($tmp as $t) {
210 $tmpWhere->add(array(
217 $tmpWhere->add(array(
222 $clause.= $tmpWhere.
'))';
223 $where->add($clause);
250 return array_key_exists($name, $this->cfg->label) ?
251 $this->cfg->getInArray(
'label', $name) :
252 $this->table->getLabel($name);
261 $prmA = array_merge(array_diff_key(
request::get(
'paramA'), $this->cfg->actionPrmClear), $this->cfg->actionPrmForce);
262 $prmA[$this->cfg->clearPrm] = 1;
272 public function to($type) {
273 return $this->
form->
to($type);
282 return $this->
to(
'html');
static getInstance(array $cfg=array())
static getPrm($key, $default=null)
static unI18nName($field)
static isI18nName($field)
static uriDef(array $prm=array(), array $use=array('lang', 'module', 'action', 'param', 'out'))
static get($className, array $cfg=array())