From b44f0a2085b69d3587100fe61d1bf1593c5e8467 Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Thu, 2 Aug 2012 02:09:58 +0000 Subject: [PATCH] Quick fix for handling array data and converting to comma separated data including filtering list results. (Admin-UI) --- e107_handlers/admin_ui.php | 42 ++++++++++++++++++++++++++-------- e107_handlers/form_handler.php | 5 ++-- e107_handlers/model_class.php | 11 +++++++-- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/e107_handlers/admin_ui.php b/e107_handlers/admin_ui.php index b3055243d..85e1c9fe8 100644 --- a/e107_handlers/admin_ui.php +++ b/e107_handlers/admin_ui.php @@ -2891,6 +2891,14 @@ class e_admin_controller_ui extends e_admin_controller break; } + + if($attributes['data'] == 'comma') + { + $value = implode(',', $value); + $model->setData($attributes['data'], 'str'); + + } + if(vartrue($attributes['dataPath'])) { $model->setData($attributes['dataPath'], $value); @@ -3117,7 +3125,8 @@ class e_admin_controller_ui extends e_admin_controller { // $fields[$field]['__tableField'] = $this->getJoinData($fields[$field]['table'], '__tablePath').$field; } - /*if($fields[$field]['table']) + /* + if($fields[$field]['table']) { if($fields[$field]['table'] == $this->getIfTableAlias(false)) { @@ -3132,7 +3141,8 @@ class e_admin_controller_ui extends e_admin_controller else { $fields[$field]['__tableField'] = '`'.$this->getTableName(false, true).'`.'.$field; - }*/ + } + */ } @@ -3149,8 +3159,6 @@ class e_admin_controller_ui extends e_admin_controller */ protected function joinAlias() { - //TODO - editQry - // TODO - auto-detect fields that belong to other tables. eg. u.user_id,u.user_name and adjust query to suit. if($this->listQry) { preg_match_all("/`?#([\w-]+)`?\s*(as|AS)\s*([\w-])/im",$this->listQry,$matches); @@ -3171,8 +3179,7 @@ class e_admin_controller_ui extends e_admin_controller foreach($match[1] as $k=>$m) { $this->joinField[$m] = $match[0][$k]; - } - + } } } @@ -3202,15 +3209,25 @@ class e_admin_controller_ui extends e_admin_controller if($searchFilter && is_array($searchFilter)) { + list($filterField, $filterValue) = $searchFilter; - + if($filterField && $filterValue !== '' && isset($this->fields[$filterField])) { - $searchQry[] = $this->fields[$filterField]['__tableField']." = '".$tp->toDB($filterValue)."'"; + if($this->fields[$filterField]['data'] == 'comma') + { + $searchQry[] = "FIND_IN_SET('".$tp->toDB($filterValue)."',".$this->fields[$filterField]['__tableField'].")"; + } + else + { + $searchQry[] = $this->fields[$filterField]['__tableField']." = '".$tp->toDB($filterValue)."'"; + } + } } elseif($searchFilter && is_string($searchFilter)) { + // filter callbacks could add to WHERE clause $searchQry[] = $searchFilter; } @@ -4138,6 +4155,11 @@ class e_admin_ui extends e_admin_controller_ui { $this->dataFields[$key] = vartrue($att['data'], 'str'); } + + if($att['data'] == 'comma') //XXX quick fix so it can be stored. + { + $this->dataFields[$key] = 'str'; + } } } // TODO - do it in one loop, or better - separate method(s) -> convertFields(validate), convertFields(data),... @@ -4735,4 +4757,6 @@ include_once(e107::coreTemplatePath('admin_icons')); * 15. [DONE] multi JOIN table support (optional), aliases * 16. tabs support (create/edit view) * 17. tree list view (should handle cases like Site Links admin page) - */ \ No newline at end of file + */ + +?> \ No newline at end of file diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index b881a85d8..456c0c82d 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -917,9 +917,10 @@ class e_form $option_array = array(1 => LAN_YES, 0 => LAN_NO); } - if($options['multiple'] && strpos($name, '[') === false) + if($options['multiple']) { - $name = $name.'[]'; + $name = (strpos($name, '[') === false) ? $name.'[]' : $name; + $selected = explode(",",$selected); } $text = $this->select_open($name, $options)."\n"; diff --git a/e107_handlers/model_class.php b/e107_handlers/model_class.php index e6c123642..256e450d8 100644 --- a/e107_handlers/model_class.php +++ b/e107_handlers/model_class.php @@ -785,7 +785,7 @@ class e_model extends e_object { return $this->$data_src; } - + $simple = false; if(strpos($key, '//') === 0) { @@ -2397,7 +2397,13 @@ class e_front_model extends e_model { $qry['_FIELD_TYPES'][$key] = $type; //_FIELD_TYPES much more optional now... } + + if($qry['_FIELD_TYPES'][$key] == 'comma') //XXX quick fix. + { + $qry['_FIELD_TYPES'][$key] = 'str'; + } $qry['data'][$key] = $this->getData($key); + } switch($action) @@ -2416,7 +2422,8 @@ class e_front_model extends e_model $qry['WHERE'] = $this->getFieldIdName().'='.$id; break; } - + + $this->addMessageDebug('SQL Qry: '.print_a($qry,true), $session_messages); return $qry; }