ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ReadingTimeDBRepo.php
Go to the documentation of this file.
1<?php
2
20
22{
23 protected \ilDBInterface $db;
24
25 public function __construct()
26 {
27 global $DIC;
28 $this->db = $DIC->database();
29 }
30
31 public function getTime(
32 int $page_id,
33 string $parent_type,
34 string $lang = "-"
35 ): int {
36 $db = $this->db;
37 $set = $db->queryF(
38 "SELECT est_reading_time FROM page_object " .
39 " WHERE page_id = %s AND parent_type = %s AND lang = %s",
40 ["integer", "text", "text"],
41 [$page_id, $parent_type, $lang]
42 );
43 if ($rec = $db->fetchAssoc($set)) {
44 return (int) $rec["est_reading_time"];
45 }
46 return 0;
47 }
48
49 public function saveTime(
50 int $page_id,
51 string $parent_type,
52 string $lang = "-",
53 int $est_reading_time = 0
54 ): void {
55 $db = $this->db;
56 $db->update(
57 "page_object",
58 [
59 "est_reading_time" => ["integer", $est_reading_time]
60 ],
61 [ // where
62 "page_id" => ["integer", $page_id],
63 "parent_type" => ["text", $parent_type],
64 "lang" => ["text", $lang],
65 ]
66 );
67 }
68
70 string $a_parent_type,
71 int $a_parent_id
72 ): array {
73 $db = $this->db;
74 $q = "SELECT * FROM page_object " .
75 " WHERE parent_id = " . $db->quote($a_parent_id, "integer") .
76 " AND parent_type = " . $db->quote($a_parent_type, "text") .
77 " AND est_reading_time = " . $db->quote(0, "integer");
78
79 $set = $db->query($q);
80 $pages = [];
81 while ($rec = $db->fetchAssoc($set)) {
82 $pages[] = [
83 "parent_type" => $a_parent_type,
84 "parent_id" => $a_parent_id,
85 "page_id" => (int) $rec["page_id"],
86 "lang" => $rec["lang"]
87 ];
88 }
89 return $pages;
90 }
91
92 public function getParentReadingTime(
93 string $a_parent_type,
94 int $a_parent_id
95 ): int {
96 $db = $this->db;
97 $q = "SELECT SUM(est_reading_time) as rt FROM page_object " .
98 " WHERE parent_id = " . $db->quote($a_parent_id, "integer") .
99 " AND parent_type = " . $db->quote($a_parent_type, "text") .
100 " AND lang = " . $db->quote("-", "text");
101
102 $set = $db->query($q);
103 $rec = $db->fetchAssoc($set);
104 return (int) ($rec["rt"] ?? 0);
105 }
106}
getParentReadingTime(string $a_parent_type, int $a_parent_id)
getPagesWithMissingReadingTime(string $a_parent_type, int $a_parent_id)
saveTime(int $page_id, string $parent_type, string $lang="-", int $est_reading_time=0)
getTime(int $page_id, string $parent_type, string $lang="-")
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
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
$q
Definition: shib_logout.php:23