public function search() { $params = array(); $module = $this->module; $request = $this->getRequest(); $requested_parameters = array(); $columns = $this->config['datagrid']['columns']; // Check if we have a POST request if (!$request->isPost()) { return $this->_helper->redirector('index'); } $post = $this->getRequest()->getParams(); if ($post) { $exclude = array('module' => null, 'controller' => null, 'action' => null, 'item' => null, 'actions' => null); // Get only the fields visible in the search form and not all the fields of the form foreach ($post as $index => $parameter) { // Exclude some form items if (!array_key_exists($index, $exclude)) { // Loop of the datagrid columns foreach ($columns as $column) { // Check if the selected column matches the form item if ($column['alias'] == $index) { // Check if the value is not empty if (!empty($parameter)) { // Check the data types if ($column['type'] == "string") { $params['search'][$index] = array('method' => 'andWhere', 'criteria' => "{$index} like ?", 'value' => '%' . $parameter . '%'); } elseif ($column['type'] == "date") { // Check if the field date value is a range of dates if (is_array($parameter) && !empty($parameter[0]) && !empty($parameter[1])) { // Check if the value is a date if (Shineisp_Commons_Utilities::isDate($parameter[0]) && Shineisp_Commons_Utilities::isDate($parameter[1])) { // Convert the date $date_1 = Shineisp_Commons_Utilities::formatDateIn($parameter[0]); $date_2 = Shineisp_Commons_Utilities::formatDateIn($parameter[1]); // Build the criteria $params['search'][$index] = array('method' => 'andWhere', 'criteria' => "{$index} between ? and ?", 'value' => array($date_1, $date_2)); } // Check if the field date value has only one date } elseif (is_array($parameter) && !empty($parameter[0]) && empty($parameter[1])) { // Check if the value is a date if (Shineisp_Commons_Utilities::isDate($parameter[0])) { // Convert the date $date = Shineisp_Commons_Utilities::formatDateIn($parameter[0]); // Build the criteria $params['search'][$index] = array('method' => 'andWhere', 'criteria' => "{$index} = ?", 'value' => $date); } } } else { $params['search'][$index] = array('method' => 'andWhere', 'criteria' => "{$index} = ?", 'value' => $parameter); } } } } } } $this->session->{$module}->filters = $params; // Check if it is an ajax request if ($this->getRequest()->isXmlHttpRequest()) { die(json_encode(array('reload' => "/admin/" . $this->module . "/list"))); } else { $this->redirector->gotoUrl("/admin/" . $this->module . "/list"); } } }
public static function formatSearchvalue($value) { // If is a numeric if (is_numeric($value)) { return $value; } // If is a date if (Shineisp_Commons_Utilities::isDate($value)) { return Shineisp_Commons_Utilities::formatDateOut($value); } $value = addslashes($value); return $value; }