/** * Update configuration key and value into database (automatically insert if key does not exist) * * @param string $key Key * @param mixed $values $values is an array if the configuration is multilingual, a single string else. * @param boolean $html Specify if html is authorized in value * @param int $id_shop_group * @param int $id_shop * @return boolean Update result */ public static function updateValue($key, $values, $html = false) { if (!JeproshopTools::isSettingName($key)) { die(sprintf(Tools::displayError('[%s] is not a valid configuration key'), $key)); } if (!is_array($values)) { $values = array($values); } $db = JFactory::getDBO(); $result = true; foreach ($values as $lang => $value) { $stored_value = JeproshopSettingModelSetting::getValue($key); // if there isn't a $stored_value, we must insert $value if (!is_numeric($value) && $value === $stored_value || is_numeric($value) && $value == $stored_value && JeproshopSettingModelSetting::hasKey($key, $lang)) { continue; } // If key already exists, update value if (JeproshopSettingModelSetting::hasKey($key)) { // Update config not linked to lang $query = "UPDATE " . $db->quoteName('#__jeproshop_setting') . " SET " . $db->quoteName('value') . " = "; $query .= $db->quoteName('date_upd') . " = " . $db->quote(date('Y-m-d H:i:s')) . " WHERE " . $db->quoteName('name') . " = " . $db->quote($key); $db->setQuery($query); $result &= $db->query(); } else { // If key does not exists, create it $configID = JeproshopSettingModelSetting::getIdByName($key); if (!$configID) { $newConfig = new JeproshopSettingModelSetting(); $newConfig->name = $key; $newConfig->value = $value; $result &= $newConfig->add(true, true); $configID = $newConfig->setting_id; } } } JeproshopSettingModelSetting::setValue($key, $values); return $result; }