ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 getReceiverInfo()
129  {
130  return (array) $this->receiver_info;
131  }
132 
137  public function getUrl()
138  {
139  return $this->url;
140  }
141 
142  public function getOwner()
143  {
144  return (int) $this->owner;
145  }
146 
154  public function loadFromJson($json)
155  {
156  global $ilLog;
157 
158  if(!is_object($json))
159  {
160  $ilLog->write(__METHOD__.': Cannot load from JSON. No object given.');
161  throw new ilException('Cannot parse ECS content details.');
162  }
163 
164  foreach((array) $json->senders as $sender)
165  {
166  $this->senders[] = $sender->mid;
167  }
168 
169  $index = 0;
170  foreach((array) $json->receivers as $receiver)
171  {
172  $this->receivers[] = $receiver->mid;
173  if($receiver->itsyou and $this->sender_index === NULL)
174  {
175  $this->sender_index = $index;
176  }
177  ++$index;
178  }
179 
180  // Collect in one array
181  for($i = 0; $i < count($this->getReceivers()); ++$i)
182  {
183  $this->receiver_info[$this->sender[$i]] = $this->receivers[$i];
184  }
185 
186  if(is_object($json->owner))
187  {
188  $this->owner = (int) $json->owner->pid;
189  }
190 
191  $this->url = $json->url;
192  $this->content_type = $json->content_type;
193  return true;
194  }
195 }
196 ?>