function getPageFromRequest() {
$criteria = new Criteria();
$sql_connect = $this->inline_model_class->connect();
$criteria->fromRequestWithPrefix($this->inline_model_class,"bin");
$criteria->setAllColumns('document',$this->inline_model_class);
if ($criteria->isRequest()) {
$sql_result = mysql_query($this->table->doSearch($criteria,$this->inline_model_class),
$sql_connect);
$sql_row = mysql_fetch_assoc($sql_result);
return $sql_row;
} else
return $false;
}
Obviously, Request contains expected fields previously setup with your displayers which produces a cycle between your Request and the previous Request. In another word, this is how you program the synchronization of your system. The dynamic system is the opposite to a stateless RESTful API. For your information, the function fromRequest can configure the whole SQL Request.
/**
* function set Criteria with Http Request values.
*
* @param object dbmodel
* @param string prefix
**/
function fromRequestWithPrefix($model_class,$prefix) {
if ($prefix != "")
$prefix .= "_";
// GET Search Criteria
$tables_array = $model_class->getTables();
foreach ($tables_array as $table_name => $table_class) {
$fields_array = $table_class->getFields();
foreach ($fields_array as $field_name => $field_class) {
$field_string = $table_class->getPrettyName() . "_" . $field_class->getPrettyName();
$prefix_field_string = $prefix . $field_string;
if ($_GET[$prefix_field_string]) {
$this->add ($field_string,$_GET[$prefix_field_string]);
$this->isRequest = true;
}
if ($_POST[$prefix_field_string]) {
$this->add ($field_string,$_POST[$prefix_field_string]);
$this->isRequest = true;
}
$field_types = $field_class->getTypes ();
foreach ($field_types as $type) {
if ($_GET[$prefix_field_string . "_" . $type]) {
$this->add ($field_string . "_" . $type,$_GET[$prefix_field_string . "_" . $type]);
$this->isRequest = true;
}
if ($_POST[$prefix_field_string . "_" . $type]) {
$this->add ($field_string . "_" . $type,$_POST[$prefix_field_string . "_" . $type]);
$this->isRequest = true;
}
}
}
}
// GET COLUMNS FROM REQUEST
if (isset($_GET[$prefix . 'search_columns']))
$this->setColumns ($_GET[$prefix . 'search_columns']);
if (isset($_POST[$prefix . 'search_columns']))
$this->setColumns ($_POST[$prefix . 'search_columns']);
if (isset($_GET[$prefix . 'search_columns_multiple']) || isset($_POST[$prefix . 'search_columns_multiple'])) {
if (isset($_GET[$prefix . 'search_columns_multiple']))
$str_search_columns = $_GET[$prefix . 'search_columns_multiple'];
if (isset($_POST[$prefix . 'search_columns_multiple']))
$str_search_columns = $_POST[$prefix . 'search_columns_multiple'];
$search_column_array = preg_split("/;/",$str_search_columns);
$count = 0;
foreach ($search_column_array as $search_column) {
$search_columns_multiple[$count] = $search_column;
$count++;
}
$this->setColumns ($search_columns_multiple);
}
//GET SEARCH FIELD : Use for default displayer
if (isset($_GET[$prefix . 'search_fields']) || isset($_POST[$prefix . 'search_fields'])) {
if (isset($_GET[$prefix . 'search_fields']))
$str_search_fields = $_GET[$prefix . 'search_fields'];
if (isset($_POST[$prefix . 'search_fields']))
$str_search_fields = $_POST[$prefix . 'search_fields'];
$search_field_array = preg_split("/;/",$str_search_fields);
$count = 0;
foreach ($search_field_array as $search_field) {
$search_fields[$count] = $search_field;
$count++;
}
$this->setSearchFields ($search_fields);
}
// GET JOIN FIELDS CONFIGURATION : Use for default displayer
$count = 0;
foreach ($tables_array as $table_name => $table_class) {
$join_fields_array = $table_class->getJoinFields();
if ($join_fields_array) {
foreach ($join_fields_array as $join_field) {
if (isset ($_GET[$prefix . $join_field['name'] . "_join"]) || isset ($_POST[$prefix . $join_field['name'] . "_join"])) {
if (($_GET[$prefix . $join_field['name'] . "_join"] != 0)|| ($_POST[$prefix . $join_field['name'] . "_join"] != 0)) {
$join_fields[$count] = $table_name . "_" . $join_field['name'];
$count++;
}
}
}
}
}
$this->join_fields = $join_fields;
//GET START ROW
if (isset($_GET[$prefix . 'start_row']))
$this->setStartRow ($_GET[$prefix . 'start_row']);
if (isset($_POST[$prefix . 'start_row']))
$this->setStartRow ($_POST[$prefix . 'start_row']);
//GET NB ROWS
if (isset($_GET[$prefix . 'nb_rows']))
$this->setNbRows ($_GET[$prefix . 'nb_rows']);
if (isset($_POST[$prefix . 'nb_rows']))
$this->setNbRows ($_POST[$prefix . 'nb_rows']);
//Get Orders
if (isset($_GET[$prefix . 'order']))
$this->setOrder ($_GET[$prefix . 'order']);
if (isset($_POST[$prefix . 'order']))
$this->setOrder ($_POST[$prefix .'order']);
}
No comments:
Post a Comment