ILIAS  release_8 Revision v8.24
class.ReadingTimeDBRepo.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2022 ILIAS open source, GPLv3, see LICENSE */
4
6
11{
15 protected $db;
16
20 protected static $times = [];
21
22 public function __construct()
23 {
25 global $DIC;
26 $this->db = $DIC->database();
27 }
28
29 public function isActivated(int $lm_id): bool
30 {
31 $db = $this->db;
32 $set = $db->queryF(
33 "SELECT act_est_reading_time FROM content_object " .
34 " WHERE id = %s ",
35 ["integer"],
36 [$lm_id]
37 );
38 if ($rec = $db->fetchAssoc($set)) {
39 return (bool) $rec["act_est_reading_time"];
40 }
41 return false;
42 }
43
44 public function activate(int $lm_id, bool $activated): void
45 {
46 $db = $this->db;
47 $db->update(
48 "content_object",
49 [
50 "act_est_reading_time" => ["integer", $activated]
51 ],
52 [ // where
53 "id" => ["integer", $lm_id]
54 ]
55 );
56 }
57
58 public function saveReadingTime(int $lm_id, int $reading_time): void
59 {
60 $db = $this->db;
61 $db->update(
62 "content_object",
63 [
64 "est_reading_time" => ["integer", $reading_time]
65 ],
66 [ // where
67 "id" => ["integer", $lm_id]
68 ]
69 );
70 }
71
72 public function getReadingTime(int $lm_id): ?int
73 {
74 if (!isset(self::$times[$lm_id])) {
75 $this->loadData([$lm_id]);
76 }
77 return self::$times[$lm_id];
78 }
79
80 public function loadData(array $lm_ids): void
81 {
82 $db = $this->db;
83 $set = $db->queryF(
84 "SELECT id, act_est_reading_time, est_reading_time FROM content_object " .
85 " WHERE " . $db->in("id", $lm_ids, false, "integer"),
86 [],
87 []
88 );
89 foreach ($lm_ids as $lm_id) {
90 self::$times[(int) $lm_id] = null;
91 }
92 while ($rec = $db->fetchAssoc($set)) {
93 if ($rec["act_est_reading_time"]) {
94 self::$times[(int) $rec["id"]] = (int) $rec["est_reading_time"];
95 }
96 }
97 }
98}
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:62
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...