21 if (!Loader::includeModule(
'im'))
30 $this->
addError(
new Error(
"You dont have access to this action"));
45 $result[
'DEFAULT_TITLE'] = \CIMChat::getNextConferenceDefaultTitle();
52 if (!isset($payload->
getData()[
'fields']))
59 $fields = $payload->
getData()[
'fields'];
60 $fields = array_change_key_case($fields, CASE_UPPER);
63 $fields[
'ID'] = isset($fields[
'ID']) ? (int)$fields[
'ID'] : 0;
64 if ($fields[
'ID'] > 0)
66 $updatingResult = $this->updateConference($fields);
67 if (!$updatingResult->isSuccess())
69 $this->
addErrors($updatingResult->getErrors());
74 return $updatingResult;
77 $addingResult = $this->createConference($payload, $fields);
78 if (!$addingResult->isSuccess())
80 $this->
addErrors($addingResult->getErrors());
85 $aliasData = $addingResult->getData()[
'ALIAS_DATA'];
88 'CHAT_ID' => $addingResult->getData()[
'CHAT_ID'],
89 'ALIAS' => $aliasData[
'ALIAS'],
90 'LINK' => $aliasData[
'LINK']
94 private function updateConference(array $fields):
Result
96 $updatingResult =
new Result();
101 return $updatingResult->addError(
new Error(
Loc::getMessage(
'IM_CONFERENCE_EDIT_ERROR_WRONG_ID')));
104 if (!$conference->canUserEdit(CurrentUser::get()->getId()))
106 return $updatingResult->addError(
new Error(
Loc::getMessage(
'IM_CONFERENCE_EDIT_ERROR_CANT_EDIT')));
109 if ($conference->getOwnerId() !== (
int)$this->getCurrentUser()->getId())
111 return $updatingResult->addError(
new Error(
Loc::getMessage(
'IM_CONFERENCE_EDIT_ERROR_CANT_EDIT')));
114 return $conference->update($fields);
117 private function createConference(JsonPayload $payload, array $fields): Result
119 $addingResult =
new Result();
122 if (isset($payload->getData()[
'aliasData']))
124 $fields[
'ALIAS_DATA'] = $payload->getData()[
'aliasData'];
130 private static function recursiveWhiteList(array $fields, $whiteList,
bool $readOnly =
false): array
133 foreach ($fields as $field => $value)
135 if (is_array($value))
137 $data[$field] = self::recursiveWhiteList($value, $whiteList[$field],
true);
139 elseif ((is_array($whiteList) && in_array($field, $whiteList)) || $readOnly)
141 $data[$field] = $value;
static getMessage($code, $replace=null, $language=null)