3 declare(strict_types=1);
32 public function getStatesFor(
int $lso_ref_id, array $usr_ids = []) : array
36 foreach ($usr_ids as $usr_id) {
38 if (array_key_exists($usr_id,
$data)) {
39 $ret[$usr_id] =
$data[$usr_id][self::STATES];
53 foreach ($usr_ids as $usr_id) {
55 if (array_key_exists($usr_id,
$data)) {
56 $ret[$usr_id] =
$data[$usr_id][self::CURRENT_ITEM_ID];
67 foreach ($usr_ids as $usr_id) {
69 if (array_key_exists($usr_id,
$data)) {
70 $ret[$usr_id] =
$data[$usr_id][self::FIRST_ACCESS];
81 foreach ($usr_ids as $usr_id) {
83 if (array_key_exists($usr_id,
$data)) {
84 $ret[$usr_id] =
$data[$usr_id][self::LAST_ACCESS];
100 int $current_item = null
102 $insert_first = $this->
entryExistsFor($lso_ref_id, $usr_id) ===
false;
104 $states = $states[$usr_id];
105 $states[$ref_id] =
$state;
107 if (is_null($current_item)) {
108 $current_item = $ref_id;
111 $ilAtomQuery = $this->db->buildAtomQuery();
112 $ilAtomQuery->addTableLock(static::TABLE_NAME);
113 $ilAtomQuery->addQueryCallable(
114 function (
ilDBInterface $db) use ($insert_first, $lso_ref_id, $usr_id, $current_item, $serialized) {
116 $this->
insert($lso_ref_id, $usr_id);
118 $this->
update($db, $lso_ref_id, $usr_id, $current_item, $serialized);
127 return count($this->
select($lso_ref_id, [$usr_id])) > 0;
130 protected function insert(
int $lso_ref_id,
int $usr_id)
132 $first_access = date(
"d.m.Y H:i:s");
134 "lso_ref_id" => array(
"integer", $lso_ref_id),
135 "usr_id" => array(
"integer", $usr_id),
136 "first_access" => array(
"text", $first_access)
139 $this->db->insert(static::TABLE_NAME,
$values);
149 $last_access = date(
"d.m.Y H:i:s");
151 "lso_ref_id" => array(
"integer", $lso_ref_id),
152 "usr_id" => array(
"integer", $usr_id)
155 "current_item" => array(
"integer", $current_item),
156 "states" => array(
"text", $serialized),
157 "last_access" => array(
"text", $last_access)
167 public function deleteFor(
int $lso_ref_id, array $usr_ids = [])
170 "DELETE FROM " . static::TABLE_NAME .
PHP_EOL 171 .
"WHERE lso_ref_id = " . $this->db->quote($lso_ref_id,
"integer") .
PHP_EOL 174 if (count($usr_ids) > 0) {
175 $query .=
"AND usr_id IN (" . implode(
',', $usr_ids) .
")";
178 $this->db->manipulate(
$query);
183 $all_states = $this->
select($lso_ref_id);
184 if (count($all_states) === 0) {
188 $ilAtomQuery = $this->db->buildAtomQuery();
189 $ilAtomQuery->addTableLock(static::TABLE_NAME);
190 $ilAtomQuery->addQueryCallable(
193 foreach ($all_states as $usr_id => $state_entry) {
194 $current_item = $state_entry[
'current_item'];
195 $states = $state_entry[
'states'];
197 if ($current_item === $item_ref_id) {
201 if (array_key_exists($item_ref_id, $states)) {
202 unset($states[$item_ref_id]);
205 $this->
update($db, $lso_ref_id, $usr_id, $current_item, $serialized);
220 $data = json_decode($serialized,
true);
221 foreach (
$data as $ref_id => $kvpair) {
223 if (is_array($kvpair)) {
224 foreach ($kvpair as
$key => $value) {
225 $states[$ref_id] = $states[$ref_id]->withValueFor(
$key, $value);
239 foreach ($states as $ref_id =>
$state) {
243 return json_encode(
$data);
246 protected function select(
int $lso_ref_id, array $usr_ids = [])
249 "SELECT usr_id, current_item, states, first_access, last_access" .
PHP_EOL 250 .
"FROM " . static::TABLE_NAME .
PHP_EOL 251 .
"WHERE lso_ref_id = " . $this->db->quote($lso_ref_id,
"integer") .
PHP_EOL 254 if (count($usr_ids) > 0) {
255 $query .=
"AND usr_id IN (" . implode(
',', $usr_ids) .
")";
263 self::CURRENT_ITEM_ID => (int) $row[self::CURRENT_ITEM_ID],
264 self::STATES => $this->
buildStates($row[self::STATES]),
265 self::FIRST_ACCESS => $row[self::FIRST_ACCESS],
266 self::LAST_ACCESS => $row[self::LAST_ACCESS]
entryExistsFor(int $lso_ref_id, int $usr_id)
getCurrentItemsFor(int $lso_ref_id, array $usr_ids=[])
deleteFor(int $lso_ref_id, array $usr_ids=[])
serializeStates(array $states)
insert(int $lso_ref_id, int $usr_id)
update($table_name, $values, $where)
getFirstAccessFor(int $lso_ref_id, array $usr_ids=[])
deleteForItem(int $lso_ref_id, int $item_ref_id)
updateState(int $lso_ref_id, int $usr_id, int $ref_id, ILIAS\KioskMode\State $state, int $current_item=null)
update a single State (for the item with ref_id); if $current_item is not set, assume that $ref_id is...
update(ilDBInterface $db, int $lso_ref_id, int $usr_id, int $current_item, string $serialized)
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
getStatesFor(int $lso_ref_id, array $usr_ids=[])
Persistence for View-States.
buildStates(string $serialized)
__construct(ilDBInterface $db)
select(int $lso_ref_id, array $usr_ids=[])
getLastAccessFor(int $lso_ref_id, array $usr_ids=[])