ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilContactUserActionProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 private readonly ilObjUser $user;
29 private array $stateToPermLinkMap = [
30 'ilBuddySystemLinkedRelationState' => '_contact_approved',
31 'ilBuddySystemIgnoredRequestRelationState' => '_contact_ignored',
32 ];
33
34 public function __construct()
35 {
36 global $DIC;
37
39
40 $this->user = $DIC['ilUser'];
41 }
42
46 public function getComponentId(): string
47 {
48 return 'contact';
49 }
50
54 public function getActionTypes(): array
55 {
56 $this->lng->loadLanguageModule('buddysystem');
57 return [
58 'handle_req' => $this->lng->txt('buddy_handle_contact_request'),
59 ];
60 }
61
65 public function collectActionsForTargetUser(int $a_target_user): ilUserActionCollection
66 {
67 $coll = new ilUserActionCollection();
68
69 if (!ilBuddySystem::getInstance()->isEnabled()) {
70 return $coll;
71 }
72
73 if ($this->user->isAnonymous() || ilObjUser::_isAnonymous($this->getUserId())) {
74 return $coll;
75 }
76
78 $requested_contacts = $buddyList->getRequestRelationsForOwner()->getKeys();
79
80 if (in_array($a_target_user, $requested_contacts)) {
81 $this->lng->loadLanguageModule('buddysystem');
82
83 $relation = $buddyList->getRelationByUserId($a_target_user);
84 foreach ($relation->getCurrentPossibleTargetStates() as $target_state) {
85 $f = new ilUserAction();
86 $f->setText(
87 $this->lng->txt(
88 'buddy_bs_act_btn_txt_requested_to_' .
89 ilStr::convertUpperCamelCaseToUnderscoreCase($target_state->getName())
90 )
91 );
92 $f->setType('handle_req');
93 $f->setHref(
95 $a_target_user,
96 'usr',
97 true,
98 $this->stateToPermLinkMap[$target_state::class]
99 )
100 );
101 $f->setData([
102 'current-state' => $relation->getState()::class,
103 'target-state' => $target_state::class,
104 'buddy-id' => $a_target_user,
105 'action' => $target_state->getAction()
106 ]);
107 $coll->addAction($f);
108 }
109 }
110
111 return $coll;
112 }
113}
$relation
static getInstanceByGlobalUser(?ilObjUser $user=null)
Class ilContactUserActionProvider.
collectActionsForTargetUser(int $a_target_user)
@inheritDoc
User class.
static _isAnonymous(int $usr_id)
static convertUpperCamelCaseToUnderscoreCase(string $value)
Convert a value given in camel case conversion to underscore case conversion (e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A class that provides a collection of actions on users.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26