context = Context::getContext(); $this->module_instance = Module::getInstanceByName('dpdpoland'); $this->child_class_name = get_class($this); } /** * Translates texts * * @param string $text Text * @return string Translated text */ protected function l($text) { $child_class_name = $this->child_class_name; $reflection = new ReflectionClass($child_class_name); $filename = $reflection->hasConstant('FILENAME') ? $reflection->getConstant('FILENAME') : false; return $this->module_instance->l($text, $filename); } /** * Collects and formats lists filter parameters * * @param array $keys_array Filter keys * @param string $table Database table name * @return string Formatted filter query */ protected function getFilterQuery($keys_array = array(), $table) { $sql = ''; foreach ($keys_array as $key) if ($this->context->cookie->__isset($table.'Filter_'.$key)) { $value = $this->context->cookie->{$table.'Filter_'.$key}; if (Validate::isSerializedArray($value)) { $date = $this->module_instance->unSerialize($value); if (!empty($date[0])) $sql .= '`'.bqSQL($key).'` > "'.pSQL($date[0]).'" AND '; if (!empty($date[1])) $sql .= '`'.bqSQL($key).'` < "'.pSQL($date[1]).'" AND '; } else { if ($value != '') $sql .= '`'.bqSQL($key).'` LIKE "%'.pSQL($value).'%" AND '; } } if ($sql) $sql = ' HAVING '.Tools::substr($sql, 0, -4); // remove 'AND ' from the end of query return $sql; } /** * Prepares list data to be displayed in page * * @param array $keys_array Filter keys * @param string $table Database table name * @param string $model Class name * @param string $default_order_by Default sorting value * @param string $default_order_way Default sorting way value * @param string $menu_page Current menu page * @param null $selected_pagination */ public function prepareListData($keys_array, $table, $model, $default_order_by, $default_order_way, $menu_page) { if (Tools::isSubmit('submitFilterButton'.$table)) { foreach ($_POST as $key => $value) { if (strpos($key, $table.'Filter_') !== false) // looking for filter values in $_POST { if (is_array($value)) $this->context->cookie->$key = serialize($value); else $this->context->cookie->$key = $value; } } } if (Tools::isSubmit('submitReset'.$table)) { foreach ($keys_array as $key) { if ($this->context->cookie->__isset($table.'Filter_'.$key)) { $this->context->cookie->__unset($table.'Filter_'.$key); $_POST[$table.'Filter_'.$key] = null; } } } if (version_compare(_PS_VERSION_, '1.6', '>=')) $page = (int)Tools::getValue('submitFilterButton'.$table); else $page = (int)Tools::getValue('submitFilter'.$table); if (!$page) $page = 1; $selected_pagination = (int)Tools::getValue('pagination', $this->default_pagination); $start = ($selected_pagination * $page) - $selected_pagination; $order_by = Tools::getValue($table.'OrderBy', $default_order_by); $order_way = Tools::getValue($table.'OrderWay', $default_order_way); $filter = $this->getFilterQuery($keys_array, $table); $table_data = $model->getList($order_by, $order_way, $filter, $start, $selected_pagination); $list_total = count($model->getList($order_by, $order_way, $filter, null, null)); $total_pages = ceil($list_total / $selected_pagination); if (!$total_pages) $total_pages = 1; $this->context->smarty->assign(array( 'full_url' => $this->module_instance->module_url.'&menu='.$menu_page.'&'.$table.'OrderBy='.$order_by.'&'.$table.'OrderWay='.$order_way, 'table_data' => $table_data, 'page' => $page, 'selected_pagination' => $selected_pagination, 'pagination' => $this->pagination, 'total_pages' => $total_pages, 'list_total' => $list_total, 'filters_has_value' => (bool)$filter, 'order_by' => $order_by, 'order_way' => $order_way, 'order_link' => 'index.php?controller=AdminOrders&vieworder&token='.Tools::getAdminTokenLite('AdminOrders') )); } }