ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ReadingTimeDBRepo.php
Go to the documentation of this file.
1<?php
2
20
25{
29 protected $db;
30
34 protected static $times = [];
35
36 public function __construct()
37 {
39 global $DIC;
40 $this->db = $DIC->database();
41 }
42
43 public function isActivated(int $lm_id): bool
44 {
45 $db = $this->db;
46 $set = $db->queryF(
47 "SELECT act_est_reading_time FROM content_object " .
48 " WHERE id = %s ",
49 ["integer"],
50 [$lm_id]
51 );
52 if ($rec = $db->fetchAssoc($set)) {
53 return (bool) $rec["act_est_reading_time"];
54 }
55 return false;
56 }
57
58 public function activate(int $lm_id, bool $activated): void
59 {
60 $db = $this->db;
61 $db->update(
62 "content_object",
63 [
64 "act_est_reading_time" => ["integer", $activated]
65 ],
66 [ // where
67 "id" => ["integer", $lm_id]
68 ]
69 );
70 }
71
72 public function saveReadingTime(int $lm_id, int $reading_time): void
73 {
74 $db = $this->db;
75 $db->update(
76 "content_object",
77 [
78 "est_reading_time" => ["integer", $reading_time]
79 ],
80 [ // where
81 "id" => ["integer", $lm_id]
82 ]
83 );
84 }
85
86 public function getReadingTime(int $lm_id): ?int
87 {
88 if (!isset(self::$times[$lm_id])) {
89 $this->loadData([$lm_id]);
90 }
91 return self::$times[$lm_id];
92 }
93
94 public function loadData(array $lm_ids): void
95 {
96 $db = $this->db;
97 $set = $db->queryF(
98 "SELECT id, act_est_reading_time, est_reading_time FROM content_object " .
99 " WHERE " . $db->in("id", $lm_ids, false, "integer"),
100 [],
101 []
102 );
103 foreach ($lm_ids as $lm_id) {
104 self::$times[(int) $lm_id] = null;
105 }
106 while ($rec = $db->fetchAssoc($set)) {
107 if ($rec["act_est_reading_time"]) {
108 self::$times[(int) $rec["id"]] = (int) $rec["est_reading_time"];
109 }
110 }
111 }
112}
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
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