public function filter_before($chain, $controller, $method, $args, $request) { // Get the form name from the form field $form = \Clips\context('form'); if ($form) { // Try to get form name from the request parameter $form_name = $request->param(\Clips\Form::FORM_FIELD); // If not found, try to find the form configuration as the first one if (!$form_name) { $form_name = $form->defaultFormName(); } // Get the current form config $config = $form->config($form_name); $params = $request->param(); if (!$params) { $params = array(); } if ($config) { $ret = $this->validator->validate($params, $config); if ($ret) { $chain->succeed = false; \Clips\clips_error('form_validation', array_map(function ($item) { return $item[0]; }, $ret)); return false; } } } }
protected function _pagi($p, $count = false) { if (\Clips\valid_obj($p, 'Clips\\Pagination')) { // For fields if ($count) { $this->select(array_merge(array('count(*) as count'), $p->fields())); } else { $this->select($p->fields()); } // Check for the table first if (isset($p->from) && $p->from) { $this->from($p->from); } else { \Clips\clips_error("No table to select from!"); return false; } // For where if (isset($p->where) && $p->where) { $this->where($p->where); } // For joins if (isset($p->join) && $p->join) { if (is_array($p->join)) { if (!is_array($p->join[0])) { $p->join = array($p->join); } } foreach ($p->join as $j) { switch (count($j)) { case 0: case 1: \Clips\clips_error("Too few arguments for join!", array($j)); break; case 2: $this->join($j[0], (array) $j[1]); break; default: $this->join($j[0], (array) $j[1], $j[2]); break; } } } // For group bys if (isset($p->groupBy) && $p->groupBy) { $this->groupBy($p->groupBy); } // For order bys if (isset($p->orderBy) && $p->orderBy) { $this->orderBy($p->orderBy); } // For limits if (!$count) { $this->limit($p->offset, $p->length); } return $this->sql(); } return false; }