ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
35  public $senders = array();
36  public $sender_index = NULL;
37  public $receivers = array();
38  public $url = array();
39  public $content_type = array();
40  public $owner = 0;
41 
42  private $receiver_info = array();
43 
44  public function __construct()
45  {
46 
47  }
48 
57  public static function getInstance($a_server_id, $a_econtent_id, $a_resource_type)
58  {
59  global $ilLog;
60 
61  try
62  {
63  include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
64  include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php';
65  $connector = new ilECSConnector(ilECSSetting::getInstanceByServerId($a_server_id));
66  $res = $connector->getResource($a_resource_type, $a_econtent_id, true);
67  if($res->getHTTPCode() == ilECSConnector::HTTP_CODE_NOT_FOUND)
68  {
69  return;
70  }
71  if(!is_object($res->getResult()))
72  {
73  $ilLog->write(__METHOD__ . ': Error parsing result. Expected result of type array.');
74  $ilLog->logStack();
75  throw new ilECSConnectorException('error parsing json');
76  }
77  }
78  catch(ilECSConnectorException $exc)
79  {
80  return;
81  }
82 
83  include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php';
84  $details = new self();
85  $details->loadFromJSON($res->getResult());
86  return $details;
87  }
88 
93  public function getSenders()
94  {
95  return (array) $this->senders;
96  }
97 
101  public function getFirstSender()
102  {
103  return isset($this->senders[0]) ? $this->senders[0] : 0;
104  }
105 
110  public function getMySender()
111  {
112  return $this->senders[$this->sender_index];
113  }
114 
119  public function getReceivers()
120  {
121  return (array) $this->receivers;
122  }
123 
128  public function getFirstReceiver()
129  {
130  foreach ($this->getReceivers() as $mid)
131  {
132  return $mid;
133  }
134  return 0;
135  }
136 
141  public function getReceiverInfo()
142  {
143  return (array) $this->receiver_info;
144  }
145 
150  public function getUrl()
151  {
152  return $this->url;
153  }
154 
155  public function getOwner()
156  {
157  return (int) $this->owner;
158  }
159 
167  public function loadFromJson($json)
168  {
169  global $ilLog;
170 
171  if(!is_object($json))
172  {
173  $ilLog->write(__METHOD__.': Cannot load from JSON. No object given.');
174  throw new ilException('Cannot parse ECS content details.');
175  }
176 
177  foreach((array) $json->senders as $sender)
178  {
179  $this->senders[] = $sender->mid;
180  }
181 
182  $index = 0;
183  foreach((array) $json->receivers as $receiver)
184  {
185  $this->receivers[] = $receiver->mid;
186  if($receiver->itsyou and $this->sender_index === NULL)
187  {
188  $this->sender_index = $index;
189  }
190  ++$index;
191  }
192 
193  // Collect in one array
194  for($i = 0; $i < count($this->getReceivers()); ++$i)
195  {
196  $this->receiver_info[$this->sender[$i]] = $this->receivers[$i];
197  }
198 
199  if(is_object($json->owner))
200  {
201  $this->owner = (int) $json->owner->pid;
202  }
203 
204  $this->url = $json->url;
205  $this->content_type = $json->content_type;
206  return true;
207  }
208 }
209 ?>
Base class for ILIAS Exception handling.
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) ...
Create styles array
The data for the language used.
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.