ArticleDAO::updateSetting PHP Method

updateSetting() public method

Add/update an article setting.
public updateSetting ( $articleId, $name, $value, $type, $isLocalized = false )
$articleId int
$name string
$value mixed
$type string Data type of the setting.
$isLocalized boolean
    function updateSetting($articleId, $name, $value, $type, $isLocalized = false)
    {
        // Check and prepare setting data.
        if ($isLocalized) {
            if (is_array($value)) {
                $values = $value;
            } else {
                // We expect localized data to come in as an array.
                assert(false);
                return;
            }
        } else {
            // Normalize non-localized data to an array so that
            // we can treat updates uniformly.
            $values = array('' => $value);
        }
        // Update setting values.
        $keyFields = array('setting_name', 'locale', 'submission_id');
        foreach ($values as $locale => $value) {
            // Locale-specific entries will be deleted when no value exists.
            // Non-localized settings will always be set.
            if ($isLocalized) {
                $this->update('DELETE FROM submission_settings WHERE submission_id = ? AND setting_name = ? AND locale = ?', array((int) $articleId, $name, $locale));
                if (empty($value)) {
                    continue;
                }
            }
            // Convert the new value to the correct type.
            $value = $this->convertToDB($value, $type);
            // Update the database.
            $this->replace('submission_settings', array('submission_id' => $articleId, 'setting_name' => $name, 'setting_value' => $value, 'setting_type' => $type, 'locale' => $locale), $keyFields);
        }
        $this->flushCache();
    }