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