From 4b1f16d8016a5c82035fa61db7eecd1d6d208664 Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Fri, 23 Oct 2009 04:25:19 +0000 Subject: [PATCH] Updated e_model with nextprev and column ordering --- e107_handlers/form_handler.php | 28 +++++++++++++++++++-------- e107_handlers/model_class.php | 22 +++++++++++++++------ e107_plugins/release/admin_config.php | 6 +++--- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index bc2644202..d54f41bdf 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -9,8 +9,8 @@ * Form Handler * * $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $ - * $Revision: 1.53 $ - * $Date: 2009-10-22 23:46:49 $ + * $Revision: 1.54 $ + * $Date: 2009-10-23 04:25:13 $ * $Author: e107coders $ * */ @@ -713,12 +713,21 @@ class e_form { $text = ""; - // FIXME - Temporary solution, we really need to add parse_str() support - $tmp = explode(".", ($requeststr ? $requeststr : e_QUERY)); - $etmp = explode(".", $querypattern); + // Recommended pattern: ?mode=list&fld=[FIELD]&asc=[ASC]&frm=[FROM] + + if(strpos($querypattern,'&')!==FALSE) + { + $tmp = $_GET; // we can assume it's always $_GET since that's what it will generate + $etmp = array(); + parse_str($querypattern,$etmp); + } + else // Legacy Queries. eg. main.[FIELD].[ASC].[FROM] + { + $tmp = explode(".", ($requeststr ? $requeststr : e_QUERY)); + $etmp = explode(".", $querypattern); + } + - // Note: this function should probably be adapted to ALSO deal with $_GET. eg. ?mode=main&field=user_name&asc=desc&from=100 - // or as a pattern: ?mode=main&field=[FIELD]&asc=[ASC]&from=[FROM] foreach($etmp as $key => $val) // I'm sure there's a more efficient way to do this, but too tired to see it right now!. { @@ -737,6 +746,9 @@ class e_form $fromval = $tmp[$key]; } } + + + if(!varset($fromval)){ $fromval = 0; } @@ -757,7 +769,7 @@ class e_form $val['url'] = e_SELF."?".str_replace($srch,$repl,$querypattern); } - $text .= (varset($val['url'])) ? "" : ""; // Really this column-sorting link should be auto-generated, or be autocreated via unobtrusive js. + $text .= (varset($val['url'])) ? "" : ""; // Really this column-sorting link should be auto-generated, or be autocreated via unobtrusive js. $text .= $val['title']; $text .= ($val['url']) ? "" : ""; $text .= ($key == "options") ? $this->columnSelector($fieldarray,$columnPref) : ""; diff --git a/e107_handlers/model_class.php b/e107_handlers/model_class.php index 97ac2bd69..419934da8 100644 --- a/e107_handlers/model_class.php +++ b/e107_handlers/model_class.php @@ -9,9 +9,9 @@ * e107 Base Model * * $Source: /cvs_backup/e107_0.8/e107_handlers/model_class.php,v $ - * $Revision: 1.20 $ - * $Date: 2009-10-22 14:18:18 $ - * $Author: secretr $ + * $Revision: 1.21 $ + * $Date: 2009-10-23 04:25:13 $ + * $Author: e107coders $ */ if (!defined('e107_INIT')) { exit; } @@ -1716,24 +1716,32 @@ class e_model_interface $frm = e107::getForm(); $mes = e107::getMessage(); $pref = e107::getConfig()->getPref(); - + $tp = e107::getParser(); + + $amount = 20; // do we hardcode or let the plugin developer decide.. OR - a pref in admin? + $from = vartrue($_GET['frm']) ? $_GET['frm'] : 0; //TODO sanitize?. $text = "
".$this->pluginTitle." ". $frm->colGroup($this->fields,$this->fieldpref). - $frm->thead($this->fields,$this->fieldpref). + $frm->thead($this->fields,$this->fieldpref, 'mode='.$this->mode.'&fld=[FIELD]&asc=[ASC]&frm=[FROM]'). ""; - if(!$sql->db_Select_gen($this->listQry)) + if(!$total = $sql->db_Select_gen($this->listQry)) { $text .= "\n\n"; } else { + $query = $this->listQry; + $query .= ($_GET['fld'] && $_GET['asc']) ? " ORDER BY ".$_GET['fld']." ".$_GET['asc'] : ""; + $query .= " LIMIT ".$from.",".$amount; + + $sql->db_Select_gen($query); $row = $sql->db_getList('ALL', FALSE, FALSE); foreach($row as $field) @@ -1756,6 +1764,8 @@ class e_model_interface "; //TODO Auto next/prev + $parms = $total.",".$amount.",".$from.",".e_SELF.'?action='.$this->mode.'&frm=[FROM]'; + $text .= $tp->parseTemplate("{NEXTPREV={$parms}}"); $ns->tablerender($this->pluginTitle." :: ".$this->adminMenu['list']['caption'], $mes->render().$text); } diff --git a/e107_plugins/release/admin_config.php b/e107_plugins/release/admin_config.php index ce79ab8ad..4859b03a9 100644 --- a/e107_plugins/release/admin_config.php +++ b/e107_plugins/release/admin_config.php @@ -9,8 +9,8 @@ * e107 Release Plugin * * $Source: /cvs_backup/e107_0.8/e107_plugins/release/admin_config.php,v $ - * $Revision: 1.6 $ - * $Date: 2009-10-22 07:52:13 $ + * $Revision: 1.7 $ + * $Date: 2009-10-23 04:25:19 $ * $Author: e107coders $ * */ @@ -46,7 +46,7 @@ class releasePlugin extends e_model_interface 'pref_name' => array('title'=> 'name', 'type' => 'text') ); - $this->listQry = "SELECT * FROM #release ORDER BY release_id DESC"; + $this->listQry = "SELECT * FROM #release"; // without any Order or Limit. $this->editQry = "SELECT * FROM #release WHERE release_id = {ID}"; $this->table = "release"; $this->primary = "release_id";
".LAN_NO_RECORDS."