ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilContactUserActionProvider.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/User/Actions/classes/class.ilUserActionProvider.php';
5 
12 {
16  protected $user;
17 
21  public function __construct()
22  {
23  global $DIC;
24 
25  parent::__construct();
26 
27  $this->user = $DIC['ilUser'];
28  }
29 
33  public function getComponentId()
34  {
35  return "contact";
36  }
37 
41  public function getActionTypes()
42  {
43  $this->lng->loadLanguageModule('buddysystem');
44  return array(
45  "handle_req" => $this->lng->txt("buddy_handle_contact_request")
46  );
47  }
48 
52  private static $state_to_perm_link_map = array(
53  'ilBuddySystemLinkedRelationState' => '_contact_approved',
54  'ilBuddySystemIgnoredRequestRelationState' => '_contact_ignored'
55  );
56 
60  public function collectActionsForTargetUser($a_target_user)
61  {
62  require_once 'Services/User/Actions/classes/class.ilUserAction.php';
64 
65  require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystem.php';
66  if (!ilBuddySystem::getInstance()->isEnabled()) {
67  return $coll;
68  }
69 
70  if (ilObjUser::_isAnonymous($this->getUserId()) || $this->user->isAnonymous()) {
71  return $coll;
72  }
73 
74  require_once 'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
76  $requested_contacts = $buddylist->getRequestRelationsForOwner()->getKeys();
77 
78  if (in_array($a_target_user, $requested_contacts)) {
79  require_once 'Services/Utilities/classes/class.ilStr.php';
80  require_once 'Services/Link/classes/class.ilLink.php';
81 
82  $this->lng->loadLanguageModule('buddysystem');
83 
84  $relation = $buddylist->getRelationByUserId($a_target_user);
85  foreach ($relation->getCurrentPossibleTargetStates() as $target_state) {
86  $f = new ilUserAction();
87  $f->setText(
88  $this->lng->txt('buddy_bs_act_btn_txt_requested_to_' .
89  ilStr::convertUpperCamelCaseToUnderscoreCase($target_state->getName()))
90  );
91  $f->setType("handle_req");
92  $f->setHref(ilLink::_getStaticLink($a_target_user, 'usr', true, self::$state_to_perm_link_map[get_class($target_state)]));
93  $f->setData(
94  array(
95  'current-state' => get_class($relation->getState()),
96  'target-state' => get_class($target_state),
97  'buddy-id' => $a_target_user,
98  'action' => $target_state->getAction())
99  );
100  $coll->addAction($f);
101  }
102  }
103 
104  return $coll;
105  }
106 }
A class that provides a collection of actions on users.
static convertUpperCamelCaseToUnderscoreCase($value)
Convert a value given in camel case conversion to underscore case conversion (e.g.
static getInstanceByGlobalUser()
static getInstance()
Get instance.
global $DIC
Definition: saml.php:7
user()
Definition: user.php:4
static _isAnonymous($usr_id)
Action that can be performed on a user.