Skip to content

Commit

Permalink
Fixed new update_col feature, wherewe allow both preset updates and user
Browse files Browse the repository at this point in the history
select updates.  User selected ones need to take priority (otherwise not
much point allowing them to set a value, if the preset has priority).
  • Loading branch information
cheesegrits committed Jul 1, 2015
1 parent a4f95ea commit 864c7b6
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions plugins/fabrik_list/update_col/update_col.php
Expand Up @@ -119,7 +119,9 @@ public function canSelectRows()

/**
* Get the values to update the list with.
* If user select the get them from the app's input else take from plug-in parameters
* Can be either/or preset values from plugin params, or user selected from popup form.
* If both are specified, values from user selects override those from plug-in parameters,
* so the plugin parameter pre-sets basically become defaults.
*
* @param JParameters $params Plugin parameters
*
Expand All @@ -132,10 +134,13 @@ protected function getUpdateCols($params)
{
$model = $this->getModel();

// get the pre-set updates
$update = json_decode($params->get('update_col_updates'));

// if we allow user selected updates ...
if ($params->get('update_user_select', 0))
{
// get the values from the form inputs
$formModel = $model->getFormModel();
$app = JFactory::getApplication();
$qs = $app->input->get('fabrik_update_col', '', 'string');
Expand All @@ -150,12 +155,23 @@ protected function getUpdateCols($params)
$id = $values['elementid'][$i];
$elementModel = $formModel->getElement($id, true);
$elementName = $elementModel->getFullName(false, false);
if (!in_array($elementName, $update->coltoupdate))

// Was this element already pre-set? Use array_search() rather than in_array() as we'll need the index if it exists.
$index = array_search($elementName, $update->coltoupdate);

if ($index === false)
{
// nope, wasn't preset, so just add it to the updates
$update->coltoupdate[] = $elementName;
$update->update_value[] = $values['value'][$i];
$update->udate_eval[] = '0';
}
else
{
// yes it was preset, so use the $index to modify the existing value
$update->update_value[$index] = $values['value'][$i];
$update->udate_eval[$index] = '0';
}
}
}

Expand Down

0 comments on commit 864c7b6

Please sign in to comment.