ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilECSEContentDetails.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 {
34  public $senders = array();
35  public $sender_index = null;
36  public $receivers = array();
37  public $url = array();
38  public $content_type = array();
39  public $owner = 0;
40 
41  private $receiver_info = array();
42 
43  public function __construct()
44  {
45  }
46 
55  public static function getInstance($a_server_id, $a_econtent_id, $a_resource_type)
56  {
57  global $ilLog;
58 
59  try {
60  include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
61  include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php';
62  $connector = new ilECSConnector(ilECSSetting::getInstanceByServerId($a_server_id));
63  $res = $connector->getResource($a_resource_type, $a_econtent_id, true);
64  if ($res->getHTTPCode() == ilECSConnector::HTTP_CODE_NOT_FOUND) {
65  return;
66  }
67  if (!is_object($res->getResult())) {
68  $ilLog->write(__METHOD__ . ': Error parsing result. Expected result of type array.');
69  $ilLog->logStack();
70  throw new ilECSConnectorException('error parsing json');
71  }
72  } catch (ilECSConnectorException $exc) {
73  return;
74  }
75 
76  include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php';
77  $details = new self();
78  $details->loadFromJSON($res->getResult());
79  return $details;
80  }
81 
86  public function getSenders()
87  {
88  return (array) $this->senders;
89  }
90 
94  public function getFirstSender()
95  {
96  return isset($this->senders[0]) ? $this->senders[0] : 0;
97  }
98 
103  public function getMySender()
104  {
105  return $this->senders[$this->sender_index];
106  }
107 
112  public function getReceivers()
113  {
114  return (array) $this->receivers;
115  }
116 
121  public function getFirstReceiver()
122  {
123  foreach ($this->getReceivers() as $mid) {
124  return $mid;
125  }
126  return 0;
127  }
128 
133  public function getReceiverInfo()
134  {
135  return (array) $this->receiver_info;
136  }
137 
142  public function getUrl()
143  {
144  return $this->url;
145  }
146 
147  public function getOwner()
148  {
149  return (int) $this->owner;
150  }
151 
159  public function loadFromJson($json)
160  {
161  global $ilLog;
162 
163  if (!is_object($json)) {
164  $ilLog->write(__METHOD__ . ': Cannot load from JSON. No object given.');
165  throw new ilException('Cannot parse ECS content details.');
166  }
167 
168  foreach ((array) $json->senders as $sender) {
169  $this->senders[] = $sender->mid;
170  }
171 
172  $index = 0;
173  foreach ((array) $json->receivers as $receiver) {
174  $this->receivers[] = $receiver->mid;
175  if ($receiver->itsyou and $this->sender_index === null) {
176  $this->sender_index = $index;
177  }
178  ++$index;
179  }
180 
181  // Collect in one array
182  for ($i = 0; $i < count($this->getReceivers()); ++$i) {
183  $this->receiver_info[$this->sender[$i]] = $this->receivers[$i];
184  }
185 
186  if (is_object($json->owner)) {
187  $this->owner = (int) $json->owner->pid;
188  }
189 
190  $this->url = $json->url;
191  $this->content_type = $json->content_type;
192  return true;
193  }
194 }
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
getMySender()
Get sender from whom we received the ressource According to the documentation the sender and receiver...
getReceiverInfo()
Get receiver info.
Presentation of ecs content details (http://...campusconnect/courselinks/id/details) ...
$index
Definition: metadata.php:60
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
loadFromJson($json)
Load from JSON object.
static getInstance($a_server_id, $a_econtent_id, $a_resource_type)
Get data from server.
getFirstReceiver()
Get first receiver.