public function filter(RM_Store_iRequest $request, $value) { $from = $this->_convertDate($value[0]); $to = $this->_convertDate($value[2], TRUE); if (@$value[1]) { if ($from) { $request->filter($this->_column->filterVariable() . '>=?', M('Tools')->date()->dbDate($from)); } if ($to) { $request->filter($this->_column->filterVariable() . '<=?', M('Tools')->date()->dbDate($to) . ' 23:59:59'); } return $request; } elseif ($from) { return $request->filter('date(' . $this->_column->filterVariable() . ')=?', M('Tools')->date()->dbDate($from)); } return $request; }
/** * Get node path (apply it to request) * * @return list<RM_Tree_iNode> */ public function getPath(RM_Store_iRequest $request, RM_Tree_iNode $node) { $path = array(); foreach ($this->_dbh->query("SELECT ancestor_id FROM {$this->_table} WHERE descendent_id = ? AND ancestor_id<>0 AND level>0 ORDER BY level DESC", $node->id()) as $a) { $path[$a['ancestor_id']] = 0; } if (count($path)) { foreach ($request->filter('id IN(' . sqlBinds($path) . ')', array_keys($path)) as $i) { $path[$i->id()] = $i; } } $path[] = $node; return array_values($path); }
/** * Sets filter for request * * @param RM_Store_iRequest $request * @param mixed $value */ public function filter(RM_Store_iRequest $request, $value) { $prefix = $postfix = ''; $begin_signs = array('>=', '<=', '>', '<', '!r:', '!', '%', '=', 'w:', 'r:'); $end_signs = array('%'); $field = $this->_column->filterVariable(); if (preg_match("/^(" . join('|', $begin_signs) . ")?([^" . join('|', $end_signs) . "]*)(" . join('|', $begin_signs) . ")?\$/", $value, $q)) { if ($q[1] == '!') { if (@$q[3] == '%') { $condition = "match({$field}) against (? in boolean mode)=0"; $postfix = '*'; } } else { if ($q[1] == '%' && @$q[3] == '%') { $condition = "match({$field}) against (? in boolean mode)"; $postfix = $prefix = '*'; } else { if (@$q[3] == '%') { $condition = "match({$field}) against (? in boolean mode)"; $postfix = '*'; } else { if ($q[1] == '%') { $condition = "match({$field}) against (? in boolean mode)"; $prefix = '*'; } else { if ($q[1] == 'w:') { $condition = "match({$field}) against (?)"; } else { if ($q[1] == '!r:') { $condition = "not match({$field}) against (? in boolean mode)"; } else { if ($q[1] == 'r:') { $condition = "match({$field}) against (? in boolean mode)"; } } } } } } } for ($i = 1; $i < 4; $i += 2) { if (isset($q[$i])) { $value = preg_replace('/' . $q[$i] . '/i', '', $value); } } } if (isset($condition)) { return $request->filter($condition, $prefix . $value . $postfix); } return $this->_mainStrategy->filter($request, $value); }
/** * Apply default active codition * * @param RM_Store_iRequest request * @param string table * @return RM_Store_iRequest **/ public function applyActive(RM_Store_iRequest $request, $table = '') { $field = 'active'; if ($table) { $field = M('Db')->field($table, $field); } return $request->filter($field . ' = 1'); }