ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSEContentDetails.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 private array $senders = [];
29 private ?int $sender_index = null;
30 private array $receivers = [];
31 private string $url = "";
32 private int $owner = 0;
33
34 private array $receiver_info = [];
36
37 public function __construct()
38 {
39 global $DIC;
40
41 $this->logger = $DIC->logger()->wsrv();
42 }
43
47 public static function getInstanceFromServer(int $a_server_id, int $a_econtent_id, string $a_resource_type): ilECSEContentDetails
48 {
49 $instance = new self();
50 $detailsOnServer = $instance->loadFromServer($a_server_id, $a_econtent_id, $a_resource_type);
51 if ($detailsOnServer) {
52 $instance->loadFromJson($detailsOnServer);
53 }
54 return $instance;
55 }
56
57
58 private function loadFromServer(int $a_server_id, int $a_econtent_id, string $a_resource_type): ?object
59 {
60 try {
61 $connector = new ilECSConnector(ilECSSetting::getInstanceByServerId($a_server_id));
62 $res = $connector->getResource($a_resource_type, $a_econtent_id, true);
63 if ($res->getHTTPCode() === ilECSConnector::HTTP_CODE_NOT_FOUND) {
64 return null;
65 }
66 if (!is_object($res->getResult())) {
67 $this->logger->error(__METHOD__ . ': Error parsing result. Expected result of type array.');
68 $this->logger->logStack();
69 throw new ilECSConnectorException('error parsing json');
70 }
71 } catch (ilECSConnectorException $exc) {
72 return null;
73 }
74 return $res->getResult();
75 }
79 public function getSenders(): array
80 {
81 return $this->senders;
82 }
83
87 public function getFirstSender(): int
88 {
89 return $this->senders[0] ?? 0;
90 }
91
96 public function getMySender(): int
97 {
98 return $this->senders[$this->sender_index];
99 }
100
104 public function getReceivers(): array
105 {
106 return $this->receivers;
107 }
108
112 public function getFirstReceiver(): int
113 {
114 return count($this->receivers) ? $this->receivers[0] : 0;
115 }
116
120 public function getReceiverInfo(): array
121 {
123 }
124
128 public function getUrl(): string
129 {
130 return $this->url;
131 }
132
133 public function getOwner(): int
134 {
135 return $this->owner;
136 }
137
144 public function loadFromJson(object $json): bool
145 {
146 $this->logger->info(print_r($json, true));
147 foreach ((array) $json->senders as $sender) {
148 $this->senders[] = $sender->mid;
149 }
150
151 $index = 0;
152 foreach ((array) $json->receivers as $receiver) {
153 $this->receivers[] = $receiver->mid;
154 if ($receiver->itsyou && $this->sender_index === null) {
155 $this->sender_index = $index;
156 }
157 ++$index;
158 }
159
160 // Collect in one array
161 for ($i = 0, $iMax = count($this->getReceivers()); $i < $iMax; ++$i) {
162 $this->receiver_info[$this->senders[$i]] = $this->receivers[$i];
163 }
164
165 if (is_object($json->owner)) {
166 $this->owner = (int) $json->owner->pid;
167 }
168
169 $this->url = $json->url;
170 return true;
171 }
172}
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.
loadFromJson(object $json)
Load from JSON object.
static getInstanceFromServer(int $a_server_id, int $a_econtent_id, string $a_resource_type)
Get data from server.
loadFromServer(int $a_server_id, int $a_econtent_id, string $a_resource_type)
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
Component logger with individual log levels by component id.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26