Skip to content
Snippets Groups Projects
Commit 827e8abf authored by Jared Hancock's avatar Jared Hancock
Browse files

lists: Remove (some of the) magic from properties

parent 4dccaf3f
No related branches found
No related tags found
No related merge requests found
...@@ -66,7 +66,7 @@ interface CustomListItem { ...@@ -66,7 +66,7 @@ interface CustomListItem {
function getSortOrder(); function getSortOrder();
function getConfiguration(); function getConfiguration();
function getConfigurationForm(); function getConfigurationForm($source=null);
function isEnabled(); function isEnabled();
...@@ -538,9 +538,8 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { ...@@ -538,9 +538,8 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem {
function setConfiguration(&$errors=array()) { function setConfiguration(&$errors=array()) {
$config = array(); $config = array();
foreach ($this->getConfigurationForm()->getFields() as $field) { foreach ($this->getConfigurationForm($_POST)->getFields() as $field) {
$val = $field->to_database($field->getClean()); $config[$field->get('id')] = $field->to_php($field->getClean());
$config[$field->get('id')] = is_array($val) ? $val[1] : $val;
$errors = array_merge($errors, $field->errors()); $errors = array_merge($errors, $field->errors());
} }
if (count($errors) === 0) if (count($errors) === 0)
...@@ -549,10 +548,20 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { ...@@ -549,10 +548,20 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem {
return count($errors) === 0; return count($errors) === 0;
} }
function getConfigurationForm() { function getConfigurationForm($source=null) {
if (!$this->_form) { if (!$this->_form) {
$config = $this->getConfiguration();
$this->_form = DynamicForm::lookup( $this->_form = DynamicForm::lookup(
array('type'=>'L'.$this->get('list_id'))); array('type'=>'L'.$this->get('list_id')))->getForm($source);
if (!$source && $config) {
foreach ($this->_form->getFields() as $f) {
$name = $f->get('id');
if (isset($config[$name]))
$f->value = $f->to_php($config[$name]);
else if ($f->get('default'))
$f->value = $f->get('default');
}
}
} }
return $this->_form; return $this->_form;
} }
...@@ -788,19 +797,31 @@ class TicketStatus extends VerySimpleModel implements CustomListItem { ...@@ -788,19 +797,31 @@ class TicketStatus extends VerySimpleModel implements CustomListItem {
} }
function getForm() { function getForm() {
return $this->getConfigurationForm();
}
function getConfigurationForm() {
if (!$this->_form && $this->_list) { if (!$this->_form && $this->_list) {
$this->_form = DynamicForm::lookup( $this->_form = DynamicForm::lookup(
array('type'=>'L'.$this->_list->getId())); array('type'=>'L'.$this->_list->getId()));
} }
return $this->_form; return $this->_form;
} }
function getConfigurationForm($source=null) {
if ($form = $this->getForm()) {
$config = $this->getConfiguration();
$form = $form->getForm($source);
if (!$source && $config) {
foreach ($form->getFields() as $f) {
$name = $f->get('id');
if (isset($config[$name]))
$f->value = $f->to_php($config[$name]);
else if ($f->get('default'))
$f->value = $f->get('default');
}
}
}
return $form;
}
function isEnabled() { function isEnabled() {
return $this->hasFlag('mode', self::ENABLED); return $this->hasFlag('mode', self::ENABLED);
} }
...@@ -896,8 +917,8 @@ class TicketStatus extends VerySimpleModel implements CustomListItem { ...@@ -896,8 +917,8 @@ class TicketStatus extends VerySimpleModel implements CustomListItem {
if (!$this->_settings) if (!$this->_settings)
$this->_settings = array(); $this->_settings = array();
if ($this->getConfigurationForm()) { if ($this->getForm()) {
foreach ($this->getConfigurationForm()->getFields() as $f) { foreach ($this->getForm()->getFields() as $f) {
$name = mb_strtolower($f->get('name')); $name = mb_strtolower($f->get('name'));
$id = $f->get('id'); $id = $f->get('id');
switch($name) { switch($name) {
...@@ -922,7 +943,7 @@ class TicketStatus extends VerySimpleModel implements CustomListItem { ...@@ -922,7 +943,7 @@ class TicketStatus extends VerySimpleModel implements CustomListItem {
function setConfiguration(&$errors=array()) { function setConfiguration(&$errors=array()) {
$properties = array(); $properties = array();
foreach ($this->getConfigurationForm()->getFields() as $f) { foreach ($this->getConfigurationForm($_POST)->getFields() as $f) {
if ($this->isInternal() //Item is internal. if ($this->isInternal() //Item is internal.
&& !$f->isEditable()) && !$f->isEditable())
continue; continue;
......
...@@ -8,13 +8,9 @@ ...@@ -8,13 +8,9 @@
echo csrf_token(); echo csrf_token();
$config = $item->getConfiguration(); $config = $item->getConfiguration();
$internal = $item->isInternal(); $internal = $item->isInternal();
foreach ($item->getConfigurationForm()->getFields() as $f) { $form = $item->getConfigurationForm();
$name = $f->get('id'); echo $form->getMedia();
if (isset($config[$name])) foreach ($form->getFields() as $f) { ?>
$f->value = $f->to_php($config[$name]);
else if ($f->get('default'))
$f->value = $f->get('default');
?>
<div class="custom-field"> <div class="custom-field">
<div class="field-label"> <div class="field-label">
<label for="<?php echo $f->getWidget()->name; ?>" <label for="<?php echo $f->getWidget()->name; ?>"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment