ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ReadingTimeDBRepo.php
Go to the documentation of this file.
1<?php
2
20
25{
26 protected \ilDBInterface $db;
27 protected static array $times = [];
28
29 public function __construct()
30 {
31 global $DIC;
32 $this->db = $DIC->database();
33 }
34
35 public function isActivated(int $lm_id): bool
36 {
37 $db = $this->db;
38 $set = $db->queryF(
39 "SELECT act_est_reading_time FROM content_object " .
40 " WHERE id = %s ",
41 ["integer"],
42 [$lm_id]
43 );
44 if ($rec = $db->fetchAssoc($set)) {
45 return (bool) $rec["act_est_reading_time"];
46 }
47 return false;
48 }
49
50 public function activate(int $lm_id, bool $activated): void
51 {
52 $db = $this->db;
53 $db->update(
54 "content_object",
55 [
56 "act_est_reading_time" => ["integer", $activated]
57 ],
58 [ // where
59 "id" => ["integer", $lm_id]
60 ]
61 );
62 }
63
64 public function saveReadingTime(int $lm_id, int $reading_time): void
65 {
66 $db = $this->db;
67 $db->update(
68 "content_object",
69 [
70 "est_reading_time" => ["integer", $reading_time]
71 ],
72 [ // where
73 "id" => ["integer", $lm_id]
74 ]
75 );
76 }
77
78 public function getReadingTime(int $lm_id): ?int
79 {
80 if (!isset(self::$times[$lm_id])) {
81 $this->loadData([$lm_id]);
82 }
83 return self::$times[$lm_id];
84 }
85
86 public function loadData(array $lm_ids): void
87 {
88 $db = $this->db;
89 $set = $db->queryF(
90 "SELECT id, act_est_reading_time, est_reading_time FROM content_object " .
91 " WHERE " . $db->in("id", $lm_ids, false, "integer"),
92 [],
93 []
94 );
95 foreach ($lm_ids as $lm_id) {
96 self::$times[(int) $lm_id] = null;
97 }
98 while ($rec = $db->fetchAssoc($set)) {
99 if ($rec["act_est_reading_time"]) {
100 self::$times[(int) $rec["id"]] = (int) $rec["est_reading_time"];
101 }
102 }
103 }
104}
update(string $table_name, array $values, array $where)
@description $where MUST contain existing columns only.
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
in(string $field, array $values, bool $negate=false, string $type="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26