1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 13:47:31 +02:00

comma type fix, media category batch works as expected now

This commit is contained in:
SecretR
2013-01-18 17:31:12 +02:00
parent 15142cf76b
commit 2e15237ab1

View File

@@ -3891,18 +3891,21 @@ class e_admin_ui extends e_admin_controller_ui
$search = array_search($value, $val); $search = array_search($value, $val);
if(false === $search) continue; if(false === $search) continue;
unset($val[$search]); unset($val[$search]);
sort($val);
$val = implode(',', $val); $val = implode(',', $val);
$node->set($field, $val); $node->set($field, $val);
$check = $this->getModel()->setData($node->getData())->save(false, true); $check = $this->getModel()->setData($node->getData())->save(false, true);
if(false === $check) $this->getModel()->setMessages(); if(false === $check) $this->getModel()->setMessages();
else $rcnt++; else $rcnt++;
continue;
} }
// attach it // attach it
if(false === in_array($value, $val)) if(false === in_array($value, $val))
{ {
$val[] = $value; $val[] = $value;
sort($val);
$val = implode(',', array_unique($val)); $val = implode(',', array_unique($val));
$node->set($field, $val); $node->set($field, $val);
$check = $this->getModel()->setData($node->getData())->save(false, true); $check = $this->getModel()->setData($node->getData())->save(false, true);
@@ -3916,14 +3919,18 @@ class e_admin_ui extends e_admin_controller_ui
case 'addAll': case 'addAll':
if(!empty($value)) if(!empty($value))
{ {
if(is_array($value)) $value = implode(',', array_map('trim', $value)); if(is_array($value))
{
sort($value);
$value = implode(',', array_map('trim', $value));
}
$cnt = $this->getTreeModel()->update($field, $value, $selected, true, true); $cnt = $this->getTreeModel()->update($field, $value, $selected, true, true);
} }
else else
{ {
// TODO lan // TODO lan
$this->getTreeModel()->addMessageWarning("Comma list is empty, aborting."); $this->getTreeModel()->addMessageWarning("Comma list is empty, aborting.")->setMessages();
} }
break; break;
@@ -3956,6 +3963,7 @@ class e_admin_ui extends e_admin_controller_ui
} }
} }
sort($val);
$val = !empty($val) ? implode(',', $val) : ''; $val = !empty($val) ? implode(',', $val) : '';
$node->set($field, $val); $node->set($field, $val);
$check = $this->getModel()->setData($node->getData())->save(false, true); $check = $this->getModel()->setData($node->getData())->save(false, true);
@@ -3965,6 +3973,7 @@ class e_admin_ui extends e_admin_controller_ui
} }
$this->_model = null; $this->_model = null;
} }
// format for proper message // format for proper message
$value = implode(',', $allowed); $value = implode(',', $allowed);
break; break;
@@ -4961,7 +4970,8 @@ class e_admin_form_ui extends e_form
case 'comma': case 'comma':
// TODO lan // TODO lan
if(!is_array(varset($parms['__options']))) parse_str($parms['__options'], $parms['__options']); if(!isset($parms['__options'])) $parms['__options'] = array();
if(!is_array($parms['__options'])) parse_str($parms['__options'], $parms['__options']);
$opts = $parms['__options']; $opts = $parms['__options'];
unset($parms['__options']); //remove element options if any unset($parms['__options']); //remove element options if any
@@ -4972,25 +4982,55 @@ class e_admin_form_ui extends e_form
if($type == 'batch') if($type == 'batch')
{ {
$_option = array(); $_option = array();
foreach ($options as $value)
if(isset($options['addAll']))
{ {
$option['attach__'.$key.'__'.$value] = 'Add '.$value; $option['attach_all__'.$key] = vartrue($options['addAll'], '(add all)');
$_option['deattach__'.$key.'__'.$value] = 'Remove '.$value; unset($options['addAll']);
} }
if(isset($parms['addAll'])) $option['attach_all__'.$key] = vartrue($parms['addAll'], '(add all)'); if(isset($options['clearAll']))
if(isset($parms['clearAll']))
{ {
$_option['deattach_all__'.$key] = vartrue($parms['clearAll'], '(clear all)'); $_option['deattach_all__'.$key] = vartrue($options['clearAll'], '(clear all)');
unset($options['clearAll']);
}
if(vartrue($opts['simple']))
{
foreach ($options as $value)
{
$option['attach__'.$key.'__'.$value] = 'Add '.$value;
$_option['deattach__'.$key.'__'.$value] = 'Remove '.$value;
}
}
else
{
foreach ($options as $value => $label)
{
$option['attach__'.$key.'__'.$value] = 'Add '.$label;
$_option['deattach__'.$key.'__'.$value] = 'Remove '.$label;
}
} }
$option = array_merge($option, $_option); $option = array_merge($option, $_option);
unset($_option); unset($_option);
} }
else else
{ {
foreach($parms as $k => $name) unset($options['addAll'], $options['clearAll']);
if(vartrue($opts['simple']))
{ {
$option[$key.'__'.$k] = $name; foreach($options as $k)
{
$option[$key.'__'.$k] = $k;
}
} }
else
{
foreach($options as $k => $name)
{
$option[$key.'__'.$k] = $name;
}
}
} }
break; break;