ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
class.HistoryRetrieval.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\COPage\History;
22
24use ILIAS\Repository\RetrievalBase;
27
29{
30 use RetrievalBase;
31
33 protected \ilDBInterface $db;
34 protected int $page_id;
35 protected string $parent_type;
36 protected string $lang;
37
38 public function __construct(
41 int $page_id,
42 string $parent_type,
43 string $lang
44 ) {
45 $this->history_repo = $history_repo;
46 $this->db = $db;
47 $this->page_id = $page_id;
48 $this->parent_type = $parent_type;
49 $this->lang = $lang;
50 }
51
52 public function getData(
53 array $fields,
54 ?Range $range = null,
55 ?Order $order = null,
56 array $filter = [],
57 array $parameters = []
58 ): \Generator {
59 $rows = [];
60
61 // Current version (nr=0)
62 $q = "SELECT page_id, last_change hdate, parent_type, parent_id, last_change_user user_id, content, lang " .
63 "FROM page_object WHERE page_id = %s" .
64 " AND parent_type = %s" .
65 " AND lang = %s";
66 $res = $this->db->queryF($q, ["integer", "text", "text"], [$this->page_id, $this->parent_type, $this->lang]);
67 if ($row = $this->db->fetchAssoc($res)) {
68 $row["nr"] = 0;
69 $row["sortkey"] = 999999999;
70 $row["user"] = (int) $row["user_id"];
71 $row["id"] = "0";
72 $rows[] = $row;
73 }
74
75 // History entries
76 $q = "SELECT * FROM page_history WHERE page_id = %s" .
77 " AND parent_type = %s" .
78 " AND lang = %s";
79
80 $res = $this->db->queryF($q, ["integer", "text", "text"], [$this->page_id, $this->parent_type, $this->lang]);
81 while ($row = $this->db->fetchAssoc($res)) {
82 $row["sortkey"] = (int) $row["nr"];
83 $row["user"] = (int) $row["user_id"];
84 $row["id"] = (string) $row["nr"];
85 $rows[] = $row;
86 }
87
88 array_multisort(
89 array_column($rows, "sortkey"),
90 SORT_DESC,
91 SORT_NUMERIC,
92 $rows
93 );
94
95 $rows = $this->applyRange($rows, $range);
96
97 foreach ($rows as $row) {
98 yield $row;
99 }
100 }
101
102 public function count(
103 array $filter,
104 array $parameters
105 ): int {
106 $q = "SELECT count(*) cnt FROM page_history WHERE page_id = %s" .
107 " AND parent_type = %s" .
108 " AND lang = %s";
109 $res = $this->db->queryF($q, ["integer", "text", "text"], [$this->page_id, $this->parent_type, $this->lang]);
110 $row = $this->db->fetchAssoc($res);
111 return (int) $row["cnt"] + 1;
112 }
113
114 public function isFieldNumeric(
115 string $field
116 ): bool {
117 if ($field === "sortkey" || $field === "nr") {
118 return true;
119 }
120 return false;
121 }
122}
__construct(HistoryDBRepository $history_repo, \ilDBInterface $db, int $page_id, string $parent_type, string $lang)
count(array $filter, array $parameters)
getData(array $fields, ?Range $range=null, ?Order $order=null, array $filter=[], array $parameters=[])
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
if(!file_exists('../ilias.ini.php'))
$q
Definition: shib_logout.php:25