Add show query, fix save extra field value see BT#12861

- Add option to saveFieldValues to only update params added in the array
pull/2487/head
jmontoyaa 7 years ago
parent 7987556e21
commit 254b263a04
  1. 2
      main/cron/import_csv.php
  2. 19
      main/inc/lib/extra_field_value.lib.php
  3. 7
      main/inc/lib/model.lib.php

@ -2567,7 +2567,7 @@ class ImportCsv
'extra_'.$careerDiagramExtraFieldName => serialize($graph),
'extra_'.$extraFieldName => $id,
];
$extraFieldValue->saveFieldValues($params);
$extraFieldValue->saveFieldValues($params, true);
}
}
}

@ -76,11 +76,12 @@ class ExtraFieldValue extends Model
* In order to save this function needs a item_id (user id, course id, etc)
* This function is used with $extraField->addElements()
* @param array $params array for the insertion into the *_field_values table
* @param bool $onlySubmittedFields Only save parameters in the $param array
* @param bool $showQuery
* @return mixed false on empty params, void otherwise
* @assert (array()) === false
*/
public function saveFieldValues($params, $showQuery = false)
public function saveFieldValues($params, $onlySubmittedFields = false, $showQuery = false)
{
foreach ($params as $key => $value) {
$found = strpos($key, '__persist__');
@ -119,6 +120,10 @@ class ExtraFieldValue extends Model
}
}
if ($onlySubmittedFields && !isset($params['extra_'.$field_variable])) {
continue;
}
if (isset($params['extra_'.$field_variable])) {
$value = $params['extra_'.$field_variable];
} else {
@ -332,11 +337,11 @@ class ExtraFieldValue extends Model
/**
* Save values in the *_field_values table
* @param array $params Structured array with the values to save
* @param boolean $show_query Whether to show the insert query (passed to the parent save() method)
* @param boolean $showQuery Whether to show the insert query (passed to the parent save() method)
* @return mixed The result sent from the parent method
* @assert (array()) === false
*/
public function save($params, $show_query = false)
public function save($params, $showQuery = false)
{
$extra_field = $this->getExtraField();
@ -421,7 +426,7 @@ class ExtraFieldValue extends Model
}
$params['value'] = $value_to_insert;
$params['author_id'] = api_get_user_id();
//$params['author_id'] = api_get_user_id();
// Insert
if (empty($field_values)) {
@ -478,10 +483,10 @@ class ExtraFieldValue extends Model
$params['value'] = $optionId;
if ($optionId) {
return parent::save($params, $show_query);
return parent::save($params, $showQuery);
}
} else {
return parent::save($params, $show_query);
return parent::save($params, $showQuery);
}
}
} else {
@ -537,7 +542,7 @@ class ExtraFieldValue extends Model
} else {
$params['id'] = $field_values['id'];
return parent::update($params, $show_query);
return parent::update($params, $showQuery);
}
}
}

@ -214,11 +214,11 @@ class Model
/**
* Updates the obj in the database. The $params['id'] must exist in order to update a record
* @param array $params
*
* @param bool $showQuery
* @return bool
*
*/
public function update($params)
public function update($params, $showQuery = false)
{
$params = $this->clean_parameters($params);
@ -244,7 +244,8 @@ class Model
$result = Database::update(
$this->table,
$params,
array('id = ?' => $id)
array('id = ?' => $id),
$showQuery
);
if ($result) {
return true;

Loading…
Cancel
Save