ILIAS  release_8 Revision v8.24
class.ilLTIConsumerResult.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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 $query = 'SELECT * FROM lti_consumer_results'
80 . ' WHERE obj_id = ' . $DIC->database()->quote($a_obj_id, 'integer')
81 . ' AND usr_id = ' . $DIC->database()->quote($a_usr_id, 'integer');
82
83 $res = $DIC->database()->query($query);
84 if ($row = $DIC->database()->fetchAssoc($res)) {
85 $resObj = new ilLTIConsumerResult();
86 $resObj->fillData($row);
87 return $resObj;
88 } elseif ($a_create) {
89 $resObj = new ilLTIConsumerResult();
90 $resObj->obj_id = $a_obj_id;
91 $resObj->usr_id = $a_usr_id;
92 $resObj->result = null;
93 $resObj->save();
94 return $resObj;
95 } else {
96 return null;
97 }
98 }
99
104 protected function fillData(array $data): void
105 {
106 $this->id = (int) $data['id'];
107 $this->obj_id = (int) $data['obj_id'];
108 $this->usr_id = (int) $data['usr_id'];
109 $this->result = (float) $data['result'];
110 }
111
115 public function save(): bool
116 {
117 global $DIC; /* @var \ILIAS\DI\Container $DIC */
118
119 if (!isset($this->usr_id) || !isset($this->obj_id)) {
120 return false;
121 }
122 if (!isset($this->id)) {
123 $this->id = $DIC->database()->nextId('lti_consumer_results');
124 }
125 $DIC->database()->replace(
126 'lti_consumer_results',
127 array(
128 'id' => array('integer', $this->id)
129 ),
130 array(
131 'obj_id' => array('integer', $this->obj_id),
132 'usr_id' => array('integer', $this->usr_id),
133 'result' => array('float', $this->result)
134 )
135 );
136 return true;
137 }
138
139 public function getId(): int
140 {
141 return $this->id;
142 }
143
144 public function getObjId(): int
145 {
146 return $this->obj_id;
147 }
148
149 public function getUsrId(): int
150 {
151 return $this->usr_id;
152 }
153
154 public function getResult(): ?float
155 {
156 return $this->result;
157 }
158
163 public static function getResultsForObject(int $objId): array
164 {
165 global $DIC; /* @var \ILIAS\DI\Container $DIC */
166
167 $query = 'SELECT * FROM lti_consumer_results'
168 . ' WHERE obj_id = ' . $DIC->database()->quote($objId, 'integer');
169
170 $res = $DIC->database()->query($query);
171
172 $results = [];
173
174 if ($row = $DIC->database()->fetchAssoc($res)) {
175 $resObj = new ilLTIConsumerResult();
176 $resObj->fillData($row);
177
178 $results[$resObj->getUsrId()] = $resObj;
179 }
180
181 return $results;
182 }
183}
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.
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query
$results
$objId
Definition: xapitoken.php:57