public function saveToSerializedColumn($Column, $UserID, $Name, $Value = '')
{
// Load the existing values
$UserData = $this->getID($UserID, DATASET_TYPE_OBJECT);
if (!$UserData) {
throw new Exception(sprintf('User %s not found.', $UserID));
}
$Values = val($Column, $UserData);
if (!is_array($Values) && !is_object($Values)) {
$Values = dbdecode($UserData->{$Column});
}
// Throw an exception if the field was not empty but is also not an object or array
if (is_string($Values) && $Values != '') {
throw new Exception(sprintf(t('Serialized column "%s" failed to be unserialized.'), $Column));
}
if (!is_array($Values)) {
$Values = [];
}
// Hook for plugins
$this->EventArguments['CurrentValues'] =& $Values;
$this->EventArguments['Column'] =& $Column;
$this->EventArguments['UserID'] =& $UserID;
$this->EventArguments['Name'] =& $Name;
$this->EventArguments['Value'] =& $Value;
$this->fireEvent('BeforeSaveSerialized');
// Assign the new value(s)
if (!is_array($Name)) {
$Name = [$Name => $Value];
}
$RawValues = array_merge($Values, $Name);
$Values = [];
foreach ($RawValues as $Key => $RawValue) {
if (!is_null($RawValue)) {
$Values[$Key] = $RawValue;
}
}
$Values = dbencode($Values);
// Save the values back to the db
$SaveResult = $this->SQL->put('User', [$Column => $Values], ['UserID' => $UserID]);
$this->clearCache($UserID, ['user']);
return $SaveResult;
}