ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAwarenessAct.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 {
17  protected $lng;
18 
19  protected static $instances = array();
20  protected $user_id;
21  protected $ref_id = 0;
22  protected static $collector;
23 
29  protected function __construct($a_user_id)
30  {
31  global $DIC;
32 
33  $this->lng = $DIC->language();
34  $this->user_id = $a_user_id;
35  }
36 
42  public function setRefId($a_val)
43  {
44  $this->ref_id = $a_val;
45  }
46 
52  public function getRefId()
53  {
54  return $this->ref_id;
55  }
56 
63  public static function getInstance($a_user_id)
64  {
65  if (!isset(self::$instances[$a_user_id])) {
66  self::$instances[$a_user_id] = new ilAwarenessAct($a_user_id);
67  }
68 
69  return self::$instances[$a_user_id];
70  }
71 
77  public function getAwarenessData($a_filter)
78  {
79  include_once("./Services/Awareness/classes/class.ilAwarenessData.php");
80  $data = ilAwarenessData::getInstance($this->user_id);
81  $data->setRefId($this->getRefId());
82  $data->setFilter($a_filter);
83  return $data->getData();
84  }
85 
91  public function getAwarenessUserCounter()
92  {
93  include_once("./Services/Awareness/classes/class.ilAwarenessData.php");
94  $data = ilAwarenessData::getInstance($this->user_id);
95  $data->setRefId($this->getRefId());
96  return $data->getUserCounter();
97  }
98 
102  public function notifyOnNewOnlineContacts()
103  {
104  $lng = $this->lng;
105 
106  $awrn_set = new ilSetting("awrn");
107  if (!$awrn_set->get("use_osd", true)) {
108  return;
109  }
110 
111  $ts = ilSession::get("awr_online_user_ts");
112 
113  $data = ilAwarenessData::getInstance($this->user_id);
114  $data->setRefId($this->getRefId());
115  $d = $data->getOnlineUserData($ts);
116 
117  $new_online_users = array();
118  $no_ids = array();
119  foreach ($d as $u) {
120  $uname = "[" . $u->login . "]";
121  if ($u->public_profile) {
122  $uname = "<a href='./goto.php?target=usr_" . $u->id . "'>" . $u->lastname . ", " . $u->firstname . " " . $uname . "</a>";
123  }
124  if (!in_array($u->id, $no_ids)) {
125  $new_online_users[] = $uname;
126  $no_ids[] = $u->id;
127  }
128  }
129 
130  if (count($new_online_users) == 0) {
131  return;
132  }
133  //var_dump($d); exit;
134  $lng->loadLanguageModule('mail');
135 
136  include_once("./Services/Object/classes/class.ilObjectFactory.php");
137  //$recipient = ilObjectFactory::getInstanceByObjId($this->user_id);
138  $bodyParams = array(
139  'online_user_names' => implode("<br />", $new_online_users)
140  );
141  //var_dump($bodyParams); exit;
142  require_once 'Services/Notifications/classes/class.ilNotificationConfig.php';
143  $notification = new ilNotificationConfig('osd_main');
144  $notification->setTitleVar('awareness_now_online', $bodyParams, 'awrn');
145  $notification->setShortDescriptionVar('awareness_now_online_users', $bodyParams, 'awrn');
146  $notification->setLongDescriptionVar('', $bodyParams, '');
147  $notification->setAutoDisable(false);
148  //$notification->setLink();
149  $notification->setIconPath('templates/default/images/icon_usr.svg');
150  $notification->setValidForSeconds(ilNotificationConfig::TTL_SHORT);
151  $notification->setVisibleForSeconds(ilNotificationConfig::DEFAULT_TTS);
152 
153  //$notification->setHandlerParam('mail.sender', $sender_id);
154 
155  ilSession::set("awr_online_user_ts", date("Y-m-d H:i:s", time()));
156 
157  $notification->notifyByUsers(array($this->user_id));
158  }
159 }
static getInstance($a_user_id)
Get instance (for a user)
getRefId()
Get ref id.
global $DIC
Definition: saml.php:7
static get($a_var)
Get a value.
static set($a_var, $a_val)
Set a value.
Describes a notification and provides methods for publishing this notification.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
Create styles array
The data for the language used.
High level business class, interface to front ends.
getAwarenessUserCounter()
Get awareness data.
static getInstance($a_user_id)
Get instance (for a user)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
setRefId($a_val)
Set ref id.
__construct($a_user_id)
Constructor.
notifyOnNewOnlineContacts()
Send OSD notification on new users.
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
getAwarenessData($a_filter)
Get awareness data.