149 public static function setSettings(
int $groupId, array $settings = [],
bool $forInitialize =
false): void
151 if (empty($settings) && !$forInitialize)
159 $encodedSettings = array_merge($defaultSettings, $encodedSettings);
162 foreach ($encodedSettings as $name => $value)
165 'GROUP_ID' => $groupId,
171 OptionStateTable::addMulti($rows,
true);
185 OptionUserTable::query()
186 ->addSelect(
'GENERAL_GROUP_ID')
191 $groupId = is_array($result) ? $result[
'GENERAL_GROUP_ID'] :
null;
194 return $defaultSettings;
198 OptionStateTable::query()
199 ->setSelect([
'NAME',
'VALUE'])
200 ->where(
'GROUP_ID', $groupId)
201 ->whereLike(
'NAME', static::ENTITY.
'%')
205 foreach ($query->exec() as $rowSetting)
207 $settings[$rowSetting[
'NAME']] = $rowSetting[
'VALUE'];
212 return $defaultSettings;
215 $settings = static::decodeSettings($settings);
217 return array_replace_recursive($defaultSettings, $settings);
234 if (empty($userList))
239 $settingName = static::getNotifySettingByType($notifyType);
240 if ($settingName ===
'')
245 $encodedSettingName = static::encodeName($settingName);
246 $encodedDefaultSettings = static::encodeSettings(static::getDefaultSettings());
248 if (!array_key_exists($encodedSettingName, $encodedDefaultSettings))
254 if (count($userList) < 1000)
256 $filteredUsers = static::filterChunk($userList, $settingName);
260 $chunkList = array_chunk($userList, static::CHUNK_LENGTH);
261 foreach ($chunkList as $chunk)
263 $filteredUsers = array_merge($filteredUsers, static::filterChunk($chunk, $settingName));
267 return $filteredUsers;
447 if ($settings === [])
456 OptionStateTable::query()
457 ->setSelect([
'NAME',
'VALUE'])
458 ->where(
'GROUP_ID', $groupId)
459 ->whereLike(
'NAME', self::ENTITY.
'%')
462 foreach ($query->exec() as $row)
464 if (array_key_exists($row[
'NAME'], $encodedSettings))
466 if ($row[
'VALUE'] === $encodedSettings[$row[
'NAME']])
468 unset($encodedSettings[$row[
'NAME']]);
471 OptionStateTable::update(
473 'GROUP_ID' => $groupId,
474 'NAME' => $row[
'NAME']
476 [
'VALUE' => $encodedSettings[$row[
'NAME']]]
478 unset($encodedSettings[$row[
'NAME']]);
483 foreach ($encodedSettings as $name => $value)
486 'GROUP_ID' => $groupId,
491 if ($addedSettings !== [])
493 OptionStateTable::addMulti($addedSettings,
true);
507 $encodedSettings = [];
508 foreach ($settings as $name => $value)
510 $encodeName = self::encodeName($name);
512 if (mb_strlen($encodeName) > 64 || mb_strlen($value) > 255)
519 $encodedSettings[$encodeName] =
'Y';
521 elseif ($value ===
false)
523 $encodedSettings[$encodeName] =
'N';
527 $encodedSettings[$encodeName] = $value;
531 return $encodedSettings;
543 $decodedSettings = [];
544 foreach ($rowSettings as $name => $value)
546 $decodedName = self::decodeName($name);
549 $decodedSettings[$decodedName] =
true;
551 elseif ($value ===
'N')
553 $decodedSettings[$decodedName] =
false;
557 $decodedSettings[$decodedName] = $value;
561 return $decodedSettings;
597 $verifiedSettings = [];
600 foreach($settings as $name => $value)
602 if (!array_key_exists($name , $defaultSettings))
610 $verifiedSettings[$name] =
611 in_array($value, [
'online',
'dnd',
'away'])
613 : $defaultSettings[$name]
617 case 'panelPositionHorizontal':
618 $verifiedSettings[$name] =
619 in_array($value, [
'left',
'center',
'right'])
621 : $defaultSettings[$name]
625 case 'panelPositionVertical':
626 $verifiedSettings[$name] =
627 in_array($value, [
'top',
'bottom'])
629 : $defaultSettings[$name]
634 $verifiedSettings[$name] =
635 in_array($value, [
'simple',
'expert'])
637 : $defaultSettings[$name]
641 case 'enableDarkTheme':
642 $verifiedSettings[$name] =
643 in_array($value, [
'auto',
'light',
'dark'])
645 : $defaultSettings[$name]
649 case 'privacyMessage':
652 case 'privacySearch':
653 $verifiedSettings[$name] =
654 in_array($value, [self::PRIVACY_RESULT_ALL, self::PRIVACY_RESULT_CONTACT],
true)
656 : $defaultSettings[$name]
660 case 'privacyProfile':
661 $verifiedSettings[$name] =
665 self::PRIVACY_RESULT_ALL,
666 self::PRIVACY_RESULT_CONTACT,
667 self::PRIVACY_RESULT_NOBODY
672 : $defaultSettings[$name];
675 case 'backgroundImage':
676 $verifiedSettings[$name] = $value;
679 case 'notifySchemeLevel':
680 $verifiedSettings[$name] =
681 in_array($value, [
'normal',
'important'])
683 : $defaultSettings[$name];
687 $status = explode(
',', $value);
688 foreach ($status as $key => $val)
692 $status[$key] = (int)$val;
693 if ($status[$key] === 0)
695 unset($status[$key]);
699 $verifiedSettings[$name] = implode(
',', $status);
702 case 'callAcceptIncomingVideo':
703 $verifiedSettings[$name] =
706 : $defaultSettings[$name]
711 $verifiedSettings[$name] = $value ===
'Y' || $value ===
true;
714 $verifiedSettings[$name] = !($value ===
'N' || $value ===
false);
716 case 'backgroundImageId':
717 $verifiedSettings[$name] = (int)$value > 0 ? (
int)$value : 1;
719 case 'chatAlignment':
720 $verifiedSettings[$name] =
721 in_array($value, [
'left',
'center'])
723 : $defaultSettings[$name]
726 case 'pinnedChatSort':
727 $verifiedSettings[$name] =
728 ($value ===
'byDate')
730 : $defaultSettings[$name]
734 if (array_key_exists($name, $defaultSettings))
736 $verifiedSettings[$name] = is_bool($value) ? $value : $defaultSettings[$name];
743 return $verifiedSettings;