/** * Apply page restrictions to request object (and fetch total number of objects if * auto_count is set). * OPTIMIZED FOR USING SQL_CALC_FOUND_ROWS. * * @param request RM_Store_iRequest Request * @param query RM_Db_Query Underlying query object * @return RM_Store_iRequest */ public function processRequestOpt(RM_Store_iRequest $request, RM_Db_Query $query) { if ($this->_all) { return $request; } if ($this->_autoCount) { $this->_queryStartCalc($query); } $iter = $request->limit($this->_pageSize)->offset(($this->_page - 1) * $this->_pageSize)->getIterator(); if ($this->_autoCount) { $this->_queryEndCalc($query); } return $iter; }
/** * 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); }
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; }
/** * Sets sort for this list * * @return void **/ public function sort(RM_Store_iRequest $request, $order) { return $request->sort($this->special_sort ? $this->special_sort : $this->varname, $order); }
/** * Apply default sort order * * @param RM_Store_iRequest request * @param string table * @return RM_Store_iRequest **/ public function applySort(RM_Store_iRequest $request, $table = '') { $field = 'order_id'; if ($table) { $field = M('Db')->field($table, $field); } return $request->sort($field, 'ASC'); }
public function getIterator() { #return new IteratorIterator($this->_request); return $this->_request->getIterator(); }