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