ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLTIConsumerResult.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
16{
20 public $id;
21
25 public $obj_id;
26
30 public $usr_id;
31
35 public $result;
36
37
43 public static function getById($a_id)
44 {
45 global $DIC;
46
47 $query = 'SELECT * FROM lti_consumer_results'
48 . ' WHERE id = ' . $DIC->database()->quote($a_id, 'integer');
49
50 $res = $DIC->database()->query($query);
51 if ($row = $DIC->database()->fetchAssoc($res)) {
52 $resObj = new ilLTIConsumerResult;
53 $resObj->fillData($row);
54 return $resObj;
55 } else {
56 return null;
57 }
58 }
59
69 public static function getByKeys($a_obj_id, $a_usr_id, $a_create = false)
70 {
71 global $DIC;
72
73 $query = 'SELECT * FROM lti_consumer_results'
74 . ' WHERE obj_id = ' . $DIC->database()->quote($a_obj_id, 'integer')
75 . ' AND usr_id = ' . $DIC->database()->quote($a_usr_id, 'integer');
76
77 $res = $DIC->database()->query($query);
78 if ($row = $DIC->database()->fetchAssoc($res)) {
79 $resObj = new ilLTIConsumerResult;
80 $resObj->fillData($row);
81 return $resObj;
82 } elseif ($a_create) {
83 $resObj = new ilLTIConsumerResult;
84 $resObj->obj_id = $a_obj_id;
85 $resObj->usr_id = $a_usr_id;
86 $resObj->result = null;
87 $resObj->save();
88 return $resObj;
89 } else {
90 return null;
91 }
92 }
93
98 protected function fillData($data)
99 {
100 $this->id = $data['id'];
101 $this->obj_id = $data['obj_id'];
102 $this->usr_id = $data['usr_id'];
103 $this->result = $data['result'];
104 }
105
109 public function save()
110 {
111 global $DIC; /* @var \ILIAS\DI\Container $DIC */
112
113 if (!isset($this->usr_id) or !isset($this->obj_id)) {
114 return false;
115 }
116 if (!isset($this->id)) {
117 $this->id = $DIC->database()->nextId('lti_consumer_results');
118 }
119 $DIC->database()->replace(
120 'lti_consumer_results',
121 array(
122 'id' => array('integer', $this->id)
123 ),
124 array(
125 'obj_id' => array('integer', $this->obj_id),
126 'usr_id' => array('integer', $this->usr_id),
127 'result' => array('float', $this->result)
128 )
129 );
130 return true;
131 }
132
136 public function getId()
137 {
138 return $this->id;
139 }
140
144 public function getObjId()
145 {
146 return $this->obj_id;
147 }
148
152 public function getUsrId()
153 {
154 return $this->usr_id;
155 }
156
160 public function getResult()
161 {
162 return $this->result;
163 }
164
169 public static function getResultsForObject($objId)
170 {
171 global $DIC; /* @var \ILIAS\DI\Container $DIC */
172
173 $query = 'SELECT * FROM lti_consumer_results'
174 . ' WHERE obj_id = ' . $DIC->database()->quote($objId, 'integer');
175
176 $res = $DIC->database()->query($query);
177
178 $results = [];
179
180 if ($row = $DIC->database()->fetchAssoc($res)) {
181 $resObj = new ilLTIConsumerResult;
182 $resObj->fillData($row);
183
184 $results[$resObj->getUsrId()] = $resObj;
185 }
186
187 return $results;
188 }
189}
An exception for terminatinating execution or to throw for unit testing.
fillData($data)
Fill the properties with data from an array.
save()
Save a result object.
static getByKeys($a_obj_id, $a_usr_id, $a_create=false)
Get a result by object and user key.
static getById($a_id)
Get a result by id.
global $DIC
Definition: goto.php:24
$query
$results
foreach($_POST as $key=> $value) $res
$data
Definition: storeScorm.php:23
$objId
Definition: xapitoken.php:39