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
31 public function __construct()
32 {
34 global $DIC;
35 $this->db = $DIC->database();
36 }
37
38 public function getTime(
39 int $page_id,
40 string $parent_type,
41 string $lang = "-"
42 ): int {
43 $db = $this->db;
44 $set = $db->queryF(
45 "SELECT est_reading_time FROM page_object " .
46 " WHERE page_id = %s AND parent_type = %s AND lang = %s",
47 ["integer", "text", "text"],
48 [$page_id, $parent_type, $lang]
49 );
50 if ($rec = $db->fetchAssoc($set)) {
51 return (int) $rec["est_reading_time"];
52 }
53 return 0;
54 }
55
56 public function saveTime(
57 int $page_id,
58 string $parent_type,
59 string $lang = "-",
60 int $est_reading_time = 0
61 ): void {
62 $db = $this->db;
63 $db->update(
64 "page_object",
65 [
66 "est_reading_time" => ["integer", $est_reading_time]
67 ],
68 [ // where
69 "page_id" => ["integer", $page_id],
70 "parent_type" => ["text", $parent_type],
71 "lang" => ["text", $lang],
72 ]
73 );
74 }
75
77 string $a_parent_type,
78 int $a_parent_id
79 ) {
80 $db = $this->db;
81 $q = "SELECT * FROM page_object " .
82 " WHERE parent_id = " . $db->quote($a_parent_id, "integer") .
83 " AND parent_type = " . $db->quote($a_parent_type, "text") .
84 " AND est_reading_time = " . $db->quote(0, "integer");
85
86 $set = $db->query($q);
87 $pages = [];
88 while ($rec = $db->fetchAssoc($set)) {
89 $pages[] = [
90 "parent_type" => $a_parent_type,
91 "parent_id" => $a_parent_id,
92 "page_id" => (int) $rec["page_id"],
93 "lang" => $rec["lang"]
94 ];
95 }
96 return $pages;
97 }
98
99 public function getParentReadingTime(
100 string $a_parent_type,
101 int $a_parent_id
102 ): int {
103 $db = $this->db;
104 $q = "SELECT SUM(est_reading_time) as rt FROM page_object " .
105 " WHERE parent_id = " . $db->quote($a_parent_id, "integer") .
106 " AND parent_type = " . $db->quote($a_parent_type, "text") .
107 " AND lang = " . $db->quote("-", "text");
108
109 $set = $db->query($q);
110 $rec = $db->fetchAssoc($set);
111 return (int) ($rec["rt"] ?? 0);
112 }
113}
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="-")
__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
$q
Definition: shib_logout.php:23
$lang
Definition: xapiexit.php:25