Performs a state transition based on the request action.
177 : void
178 {
179 if (!$this->
ctrl->isAsynch()) {
180 throw new RuntimeException('This action only supports AJAX http requests');
181 }
182
184 throw new RuntimeException('Missing "usr_id" parameter');
185 }
186
188 throw new RuntimeException('Missing "action" parameter');
189 }
190
193
194 try {
195 $usr_id = (
int) $this->
http->request()->getParsedBody()[
'usr_id'];
197
200 'You cannot perform a state transition for the anonymous user (id: %s)',
201 $usr_id
202 ));
203 }
204
206 if ($login === '') {
208 'You cannot perform a state transition for a non existing user (id: %s)',
209 $usr_id
210 ));
211 }
212
213 $relation = $this->buddyList->getRelationByUserId($usr_id);
214
215
216 if (
219 ) {
220 throw new ilException(
'The requested user does not want to get contact requests');
221 }
222
223 try {
227 $response->message = sprintf($this->
lng->txt($e->getMessage()), $login);
228 } catch (Exception) {
229 $response->message = $this->
lng->txt(
'buddy_bs_action_not_possible');
230 }
231
233 $response->state_html = $this->stateFactory->getStateButtonRendererByOwnerAndRelation(
234 $this->buddyList->getOwnerId(),
236 )->getHtml();
237 } catch (Exception) {
238 $response->message = $this->
lng->txt(
'buddy_bs_action_not_possible');
239 }
240
241 $this->
http->saveResponse(
242 $this->
http->response()
243 ->withAddedHeader('Content-Type', 'application/json')
244 ->withBody(
ILIAS\Filesystem\Stream\Streams::ofString(json_encode(
$response, JSON_THROW_ON_ERROR)))
245 );
246 $this->
http->sendResponse();
247 $this->
http->close();
248 }
Class ilBuddySystemException.
isRequestParameterGiven(string $key, int $type)
Class ilBuddySystemRelationStateAlreadyGivenException.
Class ilBuddySystemRelationStateTransitionException.
Base class for ILIAS Exception handling.
static _isAnonymous(int $usr_id)
static _lookupLogin(int $a_user_id)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.