ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
58
59 $ilLog = $DIC['ilLog'];
60
61 try {
62 include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
63 include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php';
64 $connector = new ilECSConnector(ilECSSetting::getInstanceByServerId($a_server_id));
65 $res = $connector->getResource($a_resource_type, $a_econtent_id, true);
66 if ($res->getHTTPCode() == ilECSConnector::HTTP_CODE_NOT_FOUND) {
67 return;
68 }
69 if (!is_object($res->getResult())) {
70 $ilLog->write(__METHOD__ . ': Error parsing result. Expected result of type array.');
71 $ilLog->logStack();
72 throw new ilECSConnectorException('error parsing json');
73 }
74 } catch (ilECSConnectorException $exc) {
75 return;
76 }
77
78 include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php';
79 $details = new self();
80 $details->loadFromJSON($res->getResult());
81 return $details;
82 }
83
88 public function getSenders()
89 {
90 return (array) $this->senders;
91 }
92
96 public function getFirstSender()
97 {
98 return isset($this->senders[0]) ? $this->senders[0] : 0;
99 }
100
105 public function getMySender()
106 {
107 return $this->senders[$this->sender_index];
108 }
109
114 public function getReceivers()
115 {
116 return (array) $this->receivers;
117 }
118
123 public function getFirstReceiver()
124 {
125 foreach ($this->getReceivers() as $mid) {
126 return $mid;
127 }
128 return 0;
129 }
130
135 public function getReceiverInfo()
136 {
137 return (array) $this->receiver_info;
138 }
139
144 public function getUrl()
145 {
146 return $this->url;
147 }
148
149 public function getOwner()
150 {
151 return (int) $this->owner;
152 }
153
161 public function loadFromJson($json)
162 {
163 global $DIC;
164
165 $ilLog = $DIC['ilLog'];
166
167 if (!is_object($json)) {
168 $ilLog->write(__METHOD__ . ': Cannot load from JSON. No object given.');
169 throw new ilException('Cannot parse ECS content details.');
170 }
171
172 foreach ((array) $json->senders as $sender) {
173 $this->senders[] = $sender->mid;
174 }
175
176 $index = 0;
177 foreach ((array) $json->receivers as $receiver) {
178 $this->receivers[] = $receiver->mid;
179 if ($receiver->itsyou and $this->sender_index === null) {
180 $this->sender_index = $index;
181 }
182 ++$index;
183 }
184
185 // Collect in one array
186 for ($i = 0; $i < count($this->getReceivers()); ++$i) {
187 $this->receiver_info[$this->sender[$i]] = $this->receivers[$i];
188 }
189
190 if (is_object($json->owner)) {
191 $this->owner = (int) $json->owner->pid;
192 }
193
194 $this->url = $json->url;
195 $this->content_type = $json->content_type;
196 return true;
197 }
198}
An exception for terminatinating execution or to throw for unit testing.
Presentation of ecs content details (http://...campusconnect/courselinks/id/details)
getMySender()
Get sender from whom we received the ressource According to the documentation the sender and receiver...
getFirstReceiver()
Get first receiver.
getReceiverInfo()
Get receiver info.
static getInstance($a_server_id, $a_econtent_id, $a_resource_type)
Get data from server.
loadFromJson($json)
Load from JSON object.
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
Base class for ILIAS Exception handling.
$i
Definition: disco.tpl.php:19
$index
Definition: metadata.php:60
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res