ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLTIConsumerResult.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30{
34 public int $id;
35
39 public int $obj_id;
40
44 public int $usr_id;
45
49 public ?float $result = null;
50
54 public static function getById(int $a_id): ?ilLTIConsumerResult
55 {
56 global $DIC;
57
58 $query = 'SELECT * FROM lti_consumer_results'
59 . ' WHERE id = ' . $DIC->database()->quote($a_id, 'integer');
60
61 $res = $DIC->database()->query($query);
62 if ($row = $DIC->database()->fetchAssoc($res)) {
63 $resObj = new ilLTIConsumerResult();
64 $resObj->fillData($row);
65 return $resObj;
66 } else {
67 return null;
68 }
69 }
70
75 public static function getByKeys(int $a_obj_id, int $a_usr_id, ?bool $a_create = false): ?ilLTIConsumerResult
76 {
77 global $DIC;
78
79 $logger = $DIC->logger()->root();
80 $logger->info('getByKeys: ' . $a_obj_id . ' ' . $a_usr_id);
81
82 $query = 'SELECT * FROM lti_consumer_results'
83 . ' WHERE obj_id = ' . $DIC->database()->quote($a_obj_id, 'integer')
84 . ' AND usr_id = ' . $DIC->database()->quote($a_usr_id, 'integer');
85
86 $res = $DIC->database()->query($query);
87 if ($row = $DIC->database()->fetchAssoc($res)) {
88 $resObj = new ilLTIConsumerResult();
89 $resObj->fillData($row);
90 return $resObj;
91 } elseif ($a_create) {
92 $resObj = new ilLTIConsumerResult();
93 $resObj->obj_id = $a_obj_id;
94 $resObj->usr_id = $a_usr_id;
95 $resObj->result = null;
96 $resObj->save();
97 return $resObj;
98 } else {
99 return null;
100 }
101 }
102
107 protected function fillData(array $data): void
108 {
109 $this->id = (int) $data['id'];
110 $this->obj_id = (int) $data['obj_id'];
111 $this->usr_id = (int) $data['usr_id'];
112 $this->result = $data['result'] == null ? null : (float) $data['result'];
113 }
114
118 public function save(): bool
119 {
120 global $DIC; /* @var \ILIAS\DI\Container $DIC */
121
122 $logger = $DIC->logger()->root();
123
124 $logger->info('save: ' . $this->obj_id . ' ' . $this->usr_id);
125
126 if (!isset($this->usr_id) || !isset($this->obj_id)) {
127 return false;
128 }
129 if (!isset($this->id)) {
130 $this->id = $DIC->database()->nextId('lti_consumer_results');
131 }
132
133 $logger = $DIC->logger()->root();
134
135 $logger->info('save 2: ' . $this->obj_id . ' ' . $this->usr_id);
136
137 $DIC->database()->replace(
138 'lti_consumer_results',
139 array(
140 'id' => array('integer', $this->id)
141 ),
142 array(
143 'obj_id' => array('integer', $this->obj_id),
144 'usr_id' => array('integer', $this->usr_id),
145 'result' => array('float', $this->result)
146 )
147 );
148 return true;
149 }
150
151 public function getId(): int
152 {
153 return $this->id;
154 }
155
156 public function getObjId(): int
157 {
158 return $this->obj_id;
159 }
160
161 public function getUsrId(): int
162 {
163 return $this->usr_id;
164 }
165
166 public function getResult(): ?float
167 {
168 return $this->result;
169 }
170
175 public static function getResultsForObject(int $objId): array
176 {
177 global $DIC; /* @var \ILIAS\DI\Container $DIC */
178
179 $query = 'SELECT * FROM lti_consumer_results'
180 . ' WHERE obj_id = ' . $DIC->database()->quote($objId, 'integer');
181
182 $res = $DIC->database()->query($query);
183
184 $results = [];
185
186 if ($row = $DIC->database()->fetchAssoc($res)) {
187 $resObj = new ilLTIConsumerResult();
188 $resObj->fillData($row);
189
190 $results[$resObj->getUsrId()] = $resObj;
191 }
192
193 return $results;
194 }
195}
static getResultsForObject(int $objId)
static getByKeys(int $a_obj_id, int $a_usr_id, ?bool $a_create=false)
Get a result by object and user key.
save()
Save a result object.
fillData(array $data)
Fill the properties with data from an array.
static getById(int $a_id)
Get a result by id.
$res
Definition: ltiservices.php:69
$results
global $DIC
Definition: shib_login.php:26
$objId
Definition: xapitoken.php:57