public function generate_query($params, $params_values) { global $class_path; $query = $from = $join = $where = $order = $having = ""; $joins = $group = $select = array(); if (count($params['fields']['content'])) { foreach ($params['fields']['content'] as $field) { $select[] = $this->struct_format[$field]['field']; if ($tmp = $this->struct_format[$field]['before_joins']) { foreach ($tmp as $value) { $joins[] = $value; } } if ($tmp = $this->struct_format[$field]['join']) { $joins[] = $tmp; } if ($tmp = $this->struct_format[$field]['field_group']) { $group[] = $tmp; } } if (count($params['filters']['content'])) { foreach ($params['filters']['content'] as $field) { if ($this->struct_format[$field]['input'] == "list") { require_once $class_path . "/editions_state_filter_list.class.php"; $filter = new editions_state_filter_list($this->struct_format[$field], $params_values['filters'][$field]); } else { $class = "editions_state_filter_" . $this->struct_format[$field]['type']; require_once $class_path . "/" . $class . ".class.php"; $filter = new $class($this->struct_format[$field], $params_values['filters'][$field]); } $condition = $filter->get_sql_filter(); if ($condition != "") { if ($this->struct_format[$field]['field_alias'] && !$this->struct_format[$field]['field_join']) { //Si je filtre sur un alias il me faut le champ avec l'alias dans les résultats $select[] = $this->struct_format[$field]['field']; if ($having) { $having .= " and "; } $having .= $condition; } else { if ($where) { $where .= " and "; } $where .= $condition; } if ($tmp = $this->struct_format[$field]['before_joins']) { foreach ($tmp as $value) { $joins[] = $value; } } if ($this->struct_format[$field]['join']) { $joins[] = $this->struct_format[$field]['join']; } if ($tmp = $this->struct_format[$field]['field_group']) { $group[] = $tmp; } } } if ($where) { $where = " where " . $where; } if ($having) { $having = " HAVING " . $having; } } if (count($params['orders']['content'])) { foreach ($params['orders']['content'] as $field) { if ($order) { $order .= ", "; } $crit = new editions_state_order($this->struct_format[$field], $params_values['orders'][$field]); $order .= $crit->get_sql_filter(); } if ($order) { $order = " order by " . $order; } } } $select = array_unique($select); $joins = array_unique($joins); $group = array_unique($group); $group_by = ""; if (count($group)) { $group_by = " GROUP BY " . implode(",", $group) . " "; } $select_text = "SELECT "; if (count($select)) { $select_text .= implode(", ", $select); } return $select_text . " from " . $this->table . " " . implode(" ", $joins) . " " . $where . $group_by . $having . $order; }
public function gen_tab_content($tab, $draggable = true) { global $class_path; global $msg, $charset; $content = ""; foreach ($this->state_fields_list[$tab]['content'] as $field) { switch ($tab) { case "fields": if ($draggable) { $content .= "<div class='row' id='" . $tab . "_" . $field . "' draggable='yes' dragtype='editionsstate" . $tab . "list' style='cursor: pointer;'>"; } else { $content .= "<div class='row' id='" . $tab . "_" . $field . "'>"; } $content .= "\n\t\t\t\t\t\t\t<input type='hidden' name='editions_state_" . $tab . "_content_fields[]' value='" . $this->fields[$field]['id'] . "' />\n\t\t\t\t\t\t\t" . $this->fields[$field]['label'] . "\n\t\t\t\t\t\t</div>"; break; case "filters": $class = $this->get_filter_class($field); require_once $class_path . "/" . $class . ".class.php"; $filter = new $class($this->fields[$field], $this->state_fields_params['filters'][$field]); $content .= "\n\t\t\t\t\t<div class='row' id='" . $tab . "_" . $field . "'>\n\t\t\t\t\t\t<input type='hidden' name='editions_state_" . $tab . "_content_fields[]' value='" . $this->fields[$field]['id'] . "' />"; $content .= $filter->get_form($draggable); $content .= "\n\t\t\t\t\t</div>"; break; case "orders": $order = new editions_state_order($this->fields[$field], $this->state_fields_params['orders'][$field]); $content .= "\n\t\t\t\t\t<div class='row' id='" . $tab . "_" . $field . "'>\n\t\t\t\t\t\t<input type='hidden' name='editions_state_" . $tab . "_content_fields[]' value='" . $this->fields[$field]['id'] . "' />"; $content .= $order->get_form($draggable); $content .= "\n\t\t\t\t\t</div>"; break; } } return $content; }