ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  function getComponentId()
34  {
35  return "contact";
36  }
37 
41  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  {
68  return $coll;
69  }
70 
71  if(ilObjUser::_isAnonymous($this->getUserId()) || $this->user->isAnonymous())
72  {
73  return $coll;
74  }
75 
76  require_once 'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
78  $requested_contacts = $buddylist->getRequestRelationsForOwner()->getKeys();
79 
80  if(in_array($a_target_user, $requested_contacts))
81  {
82  require_once 'Services/Utilities/classes/class.ilStr.php';
83  require_once 'Services/Link/classes/class.ilLink.php';
84 
85  $this->lng->loadLanguageModule('buddysystem');
86 
87  $relation = $buddylist->getRelationByUserId($a_target_user);
88  foreach($relation->getCurrentPossibleTargetStates() as $target_state)
89  {
90  $f = new ilUserAction();
91  $f->setText(
92  $this->lng->txt('buddy_bs_act_btn_txt_requested_to_' .
93  ilStr::convertUpperCamelCaseToUnderscoreCase($target_state->getName()))
94  );
95  $f->setType("handle_req");
96  $f->setHref(ilLink::_getStaticLink($a_target_user, 'usr', true, self::$state_to_perm_link_map[get_class($target_state)]));
97  $f->setData(array(
98  'current-state' => get_class($relation->getState()),
99  'target-state' => get_class($target_state),
100  'buddy-id' => $a_target_user,
101  'action' => $target_state->getAction())
102  );
103  $coll->addAction($f);
104  }
105  }
106 
107  return $coll;
108  }
109 }
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.
user()
Definition: user.php:4
Create styles array
The data for the language used.
static _isAnonymous($usr_id)
global $DIC
Action that can be performed on a user.