Back to InstallerScript class

Method setParams

public bool
setParams
(mixed $paramArray = null, mixed $type = 'edit', mixed $id = 0)
Sets parameter values in the extensions row of the extension table. Note that the this must be called separately for deleting and editing. Note if edit is called as a type then if the param doesn't exist it will be created
Parameters
  • array $paramArray The array of parameters to be added/edited/removed
  • string $type The type of change to be made to the param (edit/remove)
  • int $id The id of the item in the relevant table
Returns
  • bool True on success
Since
  • 3.6

Method setParams - Source code

/**
 * Sets parameter values in the extensions row of the extension table. Note that the
 * this must be called separately for deleting and editing. Note if edit is called as a
 * type then if the param doesn't exist it will be created
 *
 * @param   array    $paramArray  The array of parameters to be added/edited/removed
 * @param   string   $type        The type of change to be made to the param (edit/remove)
 * @param   integer  $id          The id of the item in the relevant table
 *
 * @return  boolean  True on success
 *
 * @since   3.6
 */
public function setParams($paramArray = null, $type = 'edit', $id = 0)
{
    if (!\is_int($id) || $id == 0) {
        // Return false if there is no valid item given
        return false;
    }
    $params = $this->getItemArray('params', $this->paramTable, 'id', $id);
    if ($paramArray) {
        foreach ($paramArray as $name => $value) {
            if ($type === 'edit') {
                // Add or edit the new variable(s) to the existing params
                if (\is_array($value)) {
                    // Convert an array into a json encoded string
                    $params[(string) $name] = array_values($value);
                } else {
                    $params[(string) $name] = (string) $value;
                }
            } elseif ($type === 'remove') {
                // Unset the parameter from the array
                unset($params[(string) $name]);
            }
        }
    }
    // Store the combined new and existing values back as a JSON string
    $paramsString = json_encode($params);
    $db = Factory::getDbo();
    $query = $db->getQuery(true)->update($db->quoteName($this->paramTable))->set('params = :params')->where('id = :id')->bind(':params', $paramsString)->bind(':id', $id, ParameterType::INTEGER);
    // Update table
    $db->setQuery($query)->execute();
    return true;
}