1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-20 20:51:53 +02:00

admin UI tools: field name alias feature added (experimental), lot of improvements, prepared for JS tabs, work in progress

This commit is contained in:
secretr 2009-11-18 19:57:07 +00:00
parent 1ad5400d0b
commit 4043bfa9e1
3 changed files with 119 additions and 57 deletions

View File

@ -9,8 +9,8 @@
* Administration UI handlers, admin helper functions
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/admin_handler.php,v $
* $Revision: 1.33 $
* $Date: 2009-11-18 14:46:27 $
* $Revision: 1.34 $
* $Date: 2009-11-18 19:57:07 $
* $Author: secretr $
*/
@ -1803,7 +1803,6 @@ class e_admin_controller
e107::getMessage()->add('Action '.$actionName.' no found!', E_MESSAGE_ERROR);
return $response;
}
//var_dump(call_user_func(array($this, $actionName)), $this->{$actionName}());
ob_start(); //catch any output
$ret = $this->{$actionName}();
@ -1828,7 +1827,6 @@ class e_admin_controller
{
$response_type = 'text';
$response->getJsHelper()->addResponse($ret)->sendResponse($response_type);
var_dump($response_type, $response->getJsHelper());
}
else
{
@ -2262,6 +2260,16 @@ class e_admin_controller_ui extends e_admin_controller
return ($prefix ? '#' : '').$this->getModel()->getModelTable();
}
public function getIfTableAlias($prefix = false, $quote = false)
{
$alias = $this->getTableName(true);
if($alias)
{
return $alias;
}
return ( !$quote ? $this->getTableName(false, $prefix) : '`'.$this->getTableName(false, $prefix).'`' );
}
/**
* Get join table data
* @param string $table if null all data will be returned
@ -2633,7 +2641,7 @@ class e_admin_controller_ui extends e_admin_controller
{
// Build query
$qry = $this->_modifyListQry(false, true, 0, 20, $listQry);
// Make query
$sql = e107::getDb();
if($qry && $sql->db_Select_gen($qry))
@ -2698,39 +2706,54 @@ class e_admin_controller_ui extends e_admin_controller
}
}
// check for table aliases
// check for table & field aliases
$fields = array(); // preserve order
foreach ($this->fields as $field => $att)
{
// tableAlias.fieldName.fieldAlias
if(strpos($field, '.') !== false)
{
$tmp = explode('.', $field, 2);
$att['alias'] = $tmp[0];
$fields[$tmp[1]] = $att;
$field = $tmp[1];
$tmp = explode('.', $field, 3);
$att['table'] = $tmp[0] ? $tmp[0] : $this->getIfTableAlias(false);
$att['alias'] = vartrue($tmp[2]);
$att['field'] = $tmp[1];
$field = $att['alias'] ? $att['alias'] : $tmp[1];
$fields[$field] = $att;
unset($tmp);
}
else
{
$att['alias'] = $this->getTableName(true);
$att['table'] = $this->getIfTableAlias(false);
$att['alias'] = '';
$att['field'] = $field;
$fields[$field] = $att;
}
if($fields[$field]['alias'])
if($fields[$field]['table'] == $this->getIfTableAlias(false))
{
$fields[$field]['__tableField'] = $att['alias'] ? $att['alias'] : $this->getIfTableAlias(true, true).'.'.$att['field'];
$fields[$field]['__tableFrom'] = $this->getIfTableAlias(true, true).'.'.$att['field'].($att['alias'] ? ' AS '.$att['alias'] : '');
}
else
{
if($fields[$field]['alias'] == $this->getTableName(true))
{
$fields[$field]['__tableField'] = $this->getTableName(true).'.'.$field;
$fields[$field]['__tableField'] = $this->getJoinData($fields[$field]['table'], '__tablePath').$field;
}
/*if($fields[$field]['table'])
{
if($fields[$field]['table'] == $this->getIfTableAlias(false))
{
$fields[$field]['__tableField'] = $att['alias'] ? $att['alias'] : $this->getIfTableAlias(true, true).'.'.$att['field'];
$fields[$field]['__tableFrom'] = $this->getIfTableAlias(true, true).'.'.$att['field'].($att['alias'] ? ' AS '.$att['alias'] : '');
}
else
{
$fields[$field]['__tableField'] = $this->getJoinData($fields[$field]['alias'], '__tablePath').$field;
$fields[$field]['__tableField'] = $this->getJoinData($fields[$field]['table'], '__tablePath').$field;
}
}
else
{
$fields[$field]['__tableField'] = '`'.$this->getTableName(false, true).'`.'.$field;
}
}*/
}
$this->fields = $fields;
@ -2744,16 +2767,11 @@ class e_admin_controller_ui extends e_admin_controller
$filterFrom = array();
$request = $this->getRequest();
$tp = e107::getParser();
$tablePath = '`'.$this->getTableName(false, true).'`.';
$tableFrom = '`'.$this->getTableName(false, true).'`';
$tableSFields = '`'.$this->getTableName(false, true).'`.*';
// check for alias
if($this->getTableName(true))
{
$tablePath = $this->getTableName(true).'.';
$tableFrom = '`'.$this->getTableName(false, true).'` AS '.$this->getTableName(true);
$tableSFields = ''.$this->getTableName(true).'.*';
}
$tablePath = $this->getIfTableAlias(true, true).'.';
$tableFrom = '`'.$this->getTableName(false, true).'`'.($this->getTableName(true) ? ' AS '.$this->getTableName(true) : '');
$tableSFieldsArr = array(); // FROM for main table
$tableSJoinArr = array(); // FROM for join tables
$filter = array();
$searchQuery = $tp->toDB($request->getQuery('searchquery', ''));
$searchFilter = $this->_parseFilterRequest($request->getQuery('filter_options', ''));
@ -2763,19 +2781,26 @@ class e_admin_controller_ui extends e_admin_controller
{
$searchQry[] = $this->fields[$filterField]['__tableField']." = '".$filterValue."'";
}
$filter = array();
// Commented for now - we should search in ALL searchable fields, not only currently active. Discuss.
//foreach($this->fieldpref as $key)
// main table should select everything
$tableSFieldsArr[] = $tablePath.'*';
foreach($this->getFields() as $key => $var)
{
//if(!vartrue($this->fields[$key])) continue;
//$var = $this->fields[$key];
$searchable_types = array('text', 'textearea', 'bbarea', 'user'); //method?
// disabled or system
if(vartrue($var['nolist']) || null === $var['type'])
{
continue;
}
if(trim($searchQuery) !== '' && !vartrue($var['nolist']) && in_array($var['type'], $searchable_types))
// select FROM... for main table
if($var['alias'] && vartrue($var['__tableFrom']))
{
$tableSFieldsArr[] = $var['__tableFrom'];
}
// filter for WHERE and FROM clauses
$searchable_types = array('text', 'textarea', 'bbarea', 'user'); //method?
if(trim($searchQuery) !== '' && in_array($var['type'], $searchable_types))
{
$filter[] = $var['__tableField']." REGEXP ('".$searchQuery."')";
if($isfilter)
@ -2784,36 +2809,41 @@ class e_admin_controller_ui extends e_admin_controller
}
}
}
if($isfilter)
{
if(!$filterFrom) return false;
$tableSFields = implode(', ', $filterFrom);
}
else
{
$tableSFields = $tableSFieldsArr ? implode(', ', $tableSFieldsArr) : $tablePath.'*';
}
$jwhere = array();
$joins = array();
//file_put_contents('e:/www/log', $tableSFields."\n\n", FILE_APPEND);
if($this->getJoinData())
{
$qry = "SELECT SQL_CALC_FOUND_ROWS ".$tableSFields;
foreach ($this->getJoinData() as $jtable => $tparams)
{
// Select fields
if(!$isfilter)
{
$fields = vartrue($tparams['fields']);
if('*' === $fields)
{
$qry .= ", {$tparams['__tablePath']}*";
$tableSJoinArr[] = "{$tparams['__tablePath']}*";
}
else
{
$fields = explode(',', $fields);
$tableSJoinArr[] = $fields;
/*$fields = explode(',', $fields);
foreach ($fields as $field)
{
$qry .= ", {$tparams['__tablePath']}`".trim($field).'`';
}
}*/
}
}
@ -2829,7 +2859,7 @@ class e_admin_controller_ui extends e_admin_controller
}
//From
$qry .= " FROM ".$tableFrom;
$qry .= ', '.implode(', ', $tableSJoinArr)." FROM ".$tableFrom;
// Joins
if(count($joins) > 0)
@ -2845,6 +2875,9 @@ class e_admin_controller_ui extends e_admin_controller
if($raw)
{
$rawData = array('joinWhere' => $jwhere, 'filter' => $filter, 'filterFrom' => $filterFrom, 'search' => $searchQry, 'tableFrom' => $tableFrom);
$rawData['tableFrom'] = $tableSFieldsArr;
$rawData['joinsFrom'] = $tableSJoinArr;
$rawData['joins'] = $joins;
$rawData['orderField'] = isset($this->fields[$orderField]) ? $this->fields[$orderField]['__tableField'] : '';
$rawData['orderType'] = $request->getQuery('asc') == 'desc' ? 'DESC' : 'ASC';
$rawData['limitFrom'] = false === $forceFrom ? intval($request->getQuery('from', 0)) : intval($forceFrom);
@ -2873,7 +2906,7 @@ class e_admin_controller_ui extends e_admin_controller
if(isset($this->fields[$orderField]))
{
// no need of sanitize - it's found in field array
$qry .= ' ORDER BY '.$this->fields[$orderField]['__tableField'].' '.($request->getQuery('asc') == 'desc' ? 'DESC' : 'ASC');
$qry .= ' ORDER BY '.$this->fields[$orderField]['__tableField'].' '.($request->getQuery('asc') == 'desc' ? 'DESC' : 'ASC');
}
if($this->getPerPage() || false !== $forceTo)

View File

@ -9,8 +9,8 @@
* Form Handler
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $
* $Revision: 1.85 $
* $Date: 2009-11-18 14:46:25 $
* $Revision: 1.86 $
* $Date: 2009-11-18 19:57:07 $
* $Author: secretr $
*
*/
@ -168,7 +168,6 @@ class e_form
if ($datestamp)
{
$cal_attrib['value'] = is_numeric($datestamp) ? e107::getDateConvert()->convert_date($datestamp, 'input') : $datestamp; //date("d/m/Y H:i:s", $datestamp);
// var_dump('date picker', $datestamp, $cal_attrib['value'], e107::getDateConvert()->toTime($cal_attrib['value']), e107::getDateConvert()->convert_date(e107::getDateConvert()->toTime($cal_attrib['value']), 'input'));
}
//JS manager to send JS/CSS to header if possible, if not - footer
e107::getJs()// FIXME - no CSS support yet!!! ->tryHeaderFile($cal->calendar_theme_file)
@ -929,6 +928,13 @@ class e_form
foreach ($fieldarray as $field => $data)
{
// shouldn't happen...
if(!isset($fieldvalues[$field]) && $data['alias'])
{
$fieldvalues[$data['alias']] = $fieldvalues[$data['field']];
$field = $data['alias'];
}
//Not found
if((!varset($data['forced']) && !in_array($field, $currentlist)) || varset($data['nolist']))
{
@ -955,6 +961,10 @@ class e_form
{
$data['readParms']['__idval'] = $fieldvalues[$data['readParms']['idField']];
}
if(isset($data['readParms']['nameField']))
{
$data['readParms']['__nameval'] = $fieldvalues[$data['readParms']['nameField']];
}
}
$value = $this->renderValue($field, varset($fieldvalues[$field]), $data, varset($fieldvalues[$pid]));
@ -1153,7 +1163,7 @@ class e_form
elseif($value && is_numeric($value))
{
$id = $value;
$ttl = vartrue($parms['__titleval']);
$ttl = vartrue($parms['__nameval']);
}
}
if($id && $ttl && is_numeric($id))
@ -1514,7 +1524,11 @@ class e_form
foreach($data['fields'] as $key => $att)
{
// convert aliases - not supported in edit mod
if(!$model->has($key) && $att['alias'])
{
$key = $att['field'];
}
$parms = vartrue($att['formparms'], array());
if(!is_array($parms)) parse_str($parms, $parms);
$label = vartrue($att['note']) ? '<div class="label-note">'.deftrue($att['note'], $att['note']).'</div>' : '';
@ -1535,6 +1549,7 @@ class e_form
</tr>
";
}
//if($bckp) $model->remove($bckp);
}

View File

@ -9,9 +9,9 @@
* Release Plugin Administration UI
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/release/includes/admin.php,v $
* $Revision: 1.11 $
* $Date: 2009-11-18 01:06:01 $
* $Author: e107coders $
* $Revision: 1.12 $
* $Date: 2009-11-18 19:57:06 $
* $Author: secretr $
*/
//require_once(e_HANDLER.'admin_handler.php'); - autoloaded - see class2.php __autoload()
@ -138,7 +138,9 @@ class plugin_release_admin_ui extends e_admin_ui
* $fields format (string) $field_name => (array) $attributes
*
* $field_name format:
* 'table_alias.field_name' (if JOIN support is needed) OR just 'field_name'
* 'table_alias_or_name.field_name.field_alias' (if JOIN support is needed) OR just 'field_name'
* NOTE: Keep in mind the count of exploded data can be 1 or 3!!! This means if you wanna give alias
* on main table field you can't omit the table (first key), alternative is just '.' e.g. '.field_name.field_alias'
*
* $attributes format:
* - title (string) Human readable field title, constant name will be accpeted as well (multi-language support
@ -186,7 +188,8 @@ class plugin_release_admin_ui extends e_admin_ui
* - null -> read: n/a
* -> write: n/a
*
* - user -> read: [optional] 'link' => true - create link to user profile, 'idField' => 'author_id' - tells to renderValue() where to search for user id (used when 'link' is true)
* - user -> read: [optional] 'link' => true - create link to user profile, 'idField' => 'author_id' - tells to renderValue() where to search for user id (used when 'link' is true and current field is NOT ID field)
* 'nameField' => 'comment_author_name' - tells to renderValue() where to search for user name (used when 'link' is true and current field is ID field)
* -> write: [optional] 'nameField' => 'comment_author_name' the name of a 'user_name' field; 'currentInit' - use currrent user if no data provided; 'current' - use always current user(editor); '__options' e_form::userpickup() options
*
* - number -> read: (array) [optional] 'point' => '.', [optional] 'sep' => ' ', [optional] 'decimals' => 2, [optional] 'pre' => '&euro; ', [optional] 'post' => 'LAN_CURRENCY'
@ -198,11 +201,16 @@ class plugin_release_admin_ui extends e_admin_ui
* - text -> read: (array) [optional] 'htmltruncate' => 100, [optional] 'truncate' => 100, [optional] 'pre' => '', [optional] 'post' => ' px'
* -> write: (array) [optional] 'pre' => '', [optional] 'post' => ' px', [optional] 'maxlength' => 50 (default - 255), [optional] '__options' => array(...) see e_form class description for __options format
*
* - textarea -> read: (array) 'noparse' => '1' default 0 (disable toHTML text parsing), [optional] 'bb' => '1' (parse bbcode) default 0, [optional] 'parse' => '' modifiers passed to e_parse::toHTML() e.g. 'BODY', [optional] 'htmltruncate' => 100, [optional] 'truncate' => 100, [optional] 'expand' => '[more]' title for expand link, empty - no expand
* - textarea -> read: (array) 'noparse' => '1' default 0 (disable toHTML text parsing), [optional] 'bb' => '1' (parse bbcode) default 0,
* [optional] 'parse' => '' modifiers passed to e_parse::toHTML() e.g. 'BODY', [optional] 'htmltruncate' => 100,
* [optional] 'truncate' => 100, [optional] 'expand' => '[more]' title for expand link, empty - no expand
* -> write: (array) [optional] 'rows' => '' default 15, [optional] 'cols' => '' default 40, [optional] '__options' => array(...) see e_form class description for __options format
* [optional] 'counter' => 0 number of max characters - has only visual effect, doesn't truncate the value (default - false)
*
* - bbarea -> read: same as textarea type
* -> write: (array) [optional] 'pre' => '', [optional] 'post' => ' px', [optional] 'maxlength' => 50 (default - 0), [optional] 'size' => [optional] - medium, small, large - default is medium
* -> write: (array) [optional] 'pre' => '', [optional] 'post' => ' px', [optional] 'maxlength' => 50 (default - 0),
* [optional] 'size' => [optional] - medium, small, large - default is medium,
* [optional] 'counter' => 0 number of max characters - has only visual effect, doesn't truncate the value (default - false)
*
* - image -> read: [optional] 'title' => 'SOME_LAN' (default - LAN_PREVIEW), [optional] 'pre' => '{e_PLUGIN}myplug/images/'
* -> write: (array) [optional] 'label' => '', [optional] '__options' => array(...) see e_form::imagepicker() for allowed options
@ -219,6 +227,12 @@ class plugin_release_admin_ui extends e_admin_ui
* - method -> read: optional, passed to given method (the field name)
* -> write: optional, passed to given method (the field name)
*
* - hidden -> read: 'show' => 1|0 - show hidden value, 'empty' => 'something' - what to be shown if value is empty (only id 'show' is 1)
* -> write: same as readParms
*
* - upload -> read: n/a
* -> write: Under construction
*
* Special attribute types:
* - method (string) field name should be method from the current e_admin_form_ui class (or its extension).
* Example call: field_name($value, $render_action, $parms) where $value is current value,