ILIAS  release_8 Revision v8.24
class.ilPCAMDPageList.php
Go to the documentation of this file.
1<?php
2
27{
29 protected ilDBInterface $db;
30 protected ilLanguage $lng;
31
32 public function init(): void
33 {
34 global $DIC;
35
36 $this->db = $DIC->database();
37 $this->lng = $DIC->language();
38 $this->setType("amdpl");
39 }
40
41 public static function getLangVars(): array
42 {
43 return array("ed_insert_amd_page_list", "pc_amdpl");
44 }
45
46 public function setNode(php4DOMElement $a_node): void
47 {
48 parent::setNode($a_node); // this is the PageContent node
49 $this->amdpl_node = $a_node->first_child(); // this is the courses node
50 }
51
52 public function create(
53 ilPageObject $a_pg_obj,
54 string $a_hier_id,
55 string $a_pc_id = ""
56 ): void {
57 $this->node = $this->createPageContentNode();
58 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
59 $this->amdpl_node = $this->dom->create_element("AMDPageList");
60 $this->amdpl_node = $this->node->append_child($this->amdpl_node);
61 }
62
63 public function setData(
64 array $a_fields_data,
65 int $a_mode = null
66 ): void {
67 $ilDB = $this->db;
68
69 $data_id = $this->amdpl_node->get_attribute("Id");
70 if ($data_id) {
71 $ilDB->manipulate("DELETE FROM pg_amd_page_list" .
72 " WHERE id = " . $ilDB->quote($data_id, "integer"));
73 } else {
74 $data_id = $ilDB->nextId("pg_amd_page_list");
75 $this->amdpl_node->set_attribute("Id", $data_id);
76 }
77
78 $this->amdpl_node->set_attribute("Mode", (int) $a_mode);
79
80 foreach ($a_fields_data as $field_id => $field_data) {
81 $fields = array(
82 "id" => array("integer", $data_id)
83 ,"field_id" => array("integer", $field_id)
84 ,"sdata" => array("text", serialize($field_data))
85 );
86 $ilDB->insert("pg_amd_page_list", $fields);
87 }
88 }
89
90 public function getMode(): int
91 {
92 if (is_object($this->amdpl_node)) {
93 return (int) $this->amdpl_node->get_attribute("Mode");
94 }
95 return 0;
96 }
97
101 public function getFieldValues(
102 int $a_data_id = null
103 ): array {
104 $ilDB = $this->db;
105
106 $res = array();
107
108 if (!$a_data_id) {
109 if (is_object($this->amdpl_node)) {
110 $a_data_id = $this->amdpl_node->get_attribute("Id");
111 }
112 }
113
114 if ($a_data_id) {
115 $set = $ilDB->query("SELECT * FROM pg_amd_page_list" .
116 " WHERE id = " . $ilDB->quote($a_data_id, "integer"));
117 while ($row = $ilDB->fetchAssoc($set)) {
118 $res[$row["field_id"]] = unserialize($row["sdata"], ["allowed_classes" => false]);
119 }
120 }
121 return $res;
122 }
123 public static function handleCopiedContent(
124 DOMDocument $a_domdoc,
125 bool $a_self_ass = true,
126 bool $a_clone_mobs = false,
127 int $new_parent_id = 0,
128 int $obj_copy_id = 0
129 ): void {
130 global $DIC;
131
132 $ilDB = $DIC->database();
133 $old_id = 0;
134 $node = null;
135
136 // #15688
137
138 $xpath = new DOMXPath($a_domdoc);
139 $nodes = $xpath->query("//AMDPageList");
140 foreach ($nodes as $node) {
141 $old_id = $node->getAttribute("Id");
142 break;
143 }
144
145 if ($old_id) {
146 $new_id = $ilDB->nextId("pg_amd_page_list");
147
148 $set = $ilDB->query("SELECT * FROM pg_amd_page_list" .
149 " WHERE id = " . $ilDB->quote($old_id, "integer"));
150 while ($row = $ilDB->fetchAssoc($set)) {
151 $fields = array(
152 "id" => array("integer", $new_id)
153 ,"field_id" => array("integer", $row["field_id"])
154 ,"sdata" => array("text", $row["sdata"])
155 );
156 $ilDB->insert("pg_amd_page_list", $fields);
157 }
158
159 $node->setAttribute("Id", $new_id);
160 }
161 }
162
163
164 //
165 // presentation
166 //
167
168 protected function findPages(
169 int $a_list_id
170 ): array {
171 $ilDB = $this->db;
172
173 $list_values = $this->getFieldValues($a_list_id);
174
176 $wpage = $this->getPage();
177 $wiki_id = $wpage->getWikiId();
178 $wiki_ref_id = $wpage->getWikiRefId();
179
180 $found_result = array();
181
182 // only search in active fields
183 $found_ids = null;
184 $recs = ilAdvancedMDRecord::_getSelectedRecordsByObject("wiki", $wiki_ref_id, "wpg");
185 foreach ($recs as $record) {
186 foreach (ilAdvancedMDFieldDefinition::getInstancesByRecordId($record->getRecordId(), true) as $field) {
187 if (isset($list_values[$field->getFieldId()]) && $list_values[$field->getFieldId()] !== "") {
188 $field_form = ilADTFactory::getInstance()->getSearchBridgeForDefinitionInstance($field->getADTDefinition(), true, false);
189 $field->setSearchValueSerialized($field_form, $list_values[$field->getFieldId()]);
190 $found_pages = $field->searchSubObjects($field_form, $wiki_id, "wpg");
191 if (is_array($found_ids)) {
192 $found_ids = array_intersect($found_ids, $found_pages);
193 } else {
194 $found_ids = $found_pages;
195 }
196 }
197 }
198 }
199
200 if (is_array($found_ids) && count($found_ids) > 0) {
201 $sql = "SELECT id,title FROM il_wiki_page" .
202 " WHERE " . $ilDB->in("id", $found_ids, "", "integer") .
203 " ORDER BY title";
204 $set = $ilDB->query($sql);
205 while ($row = $ilDB->fetchAssoc($set)) {
206 $found_result[$row["id"]] = $row["title"];
207 }
208 }
209
210 return $found_result;
211 }
212
214 string $a_output,
215 string $a_mode,
216 bool $a_abstract_only = false
217 ): string {
218 if ($this->getPage()->getParentType() !== "wpg") {
219 return $a_output;
220 }
221 $end = 0;
222 $wiki_id = $this->getPage()->getWikiId();
223
224 $start = strpos($a_output, "[[[[[AMDPageList;");
225 if (is_int($start)) {
226 $end = strpos($a_output, "]]]]]", $start);
227 }
228 while ($end > 0) {
229 $parts = explode(";", substr($a_output, $start + 17, $end - $start - 17));
230
231 $list_id = (int) $parts[0];
232 $list_mode = (count($parts) === 2)
233 ? (int) $parts[1]
234 : 0;
235
236 $ltpl = new ilTemplate("tpl.wiki_amd_page_list.html", true, true, "Modules/Wiki");
237
238 $pages = $this->findPages($list_id);
239 if (count($pages)) {
240 $ltpl->setCurrentBlock("page_bl");
241 foreach ($pages as $page_id => $page_title) {
242 // see ilWikiUtil::makeLink()
243 $frag = new stdClass();
244 $frag->mFragment = null;
245 $frag->mTextform = $page_title;
246
247 $ltpl->setVariable("PAGE", ilWikiUtil::makeLink($frag, $wiki_id, $page_title));
248 $ltpl->parseCurrentBlock();
249 }
250 } else {
251 $ltpl->touchBlock("no_hits_bl");
252 }
253
254 $ltpl->setVariable("LIST_MODE", $list_mode ? "ol" : "ul");
255
256 $a_output = substr($a_output, 0, $start) .
257 $ltpl->get() .
258 substr($a_output, $end + 5);
259
260 $start = strpos($a_output, "[[[[[AMDPageList;", $start + 5);
261 $end = 0;
262 if (is_int($start)) {
263 $end = strpos($a_output, "]]]]]", $start);
264 }
265 }
266
267 return $a_output;
268 }
269
276 public static function migrateField(
277 int $a_field_id,
278 array $mapping
279 ): void {
280 global $DIC;
281
282 $ilDB = $DIC->database();
283
284 // this does only work for select and select multi
285
286 $set = $ilDB->query("SELECT * FROM pg_amd_page_list" .
287 " WHERE field_id = " . $ilDB->quote($a_field_id, "integer"));
288 while ($row = $ilDB->fetchAssoc($set)) {
289 $data = unserialize(unserialize($row["sdata"], ["allowed_classes" => false]), ["allowed_classes" => false]);
290 if (!is_array($data)) {
291 continue;
292 }
293 $updated_data = $data;
294 foreach ($mapping as $old_option => $new_option) {
295 if (!in_array($old_option, $data)) {
296 continue;
297 }
298 $idx = array_search($old_option, $data);
299 if ($new_option !== '') {
300 $updated_data[$idx] = $new_option;
301 } else {
302 unset($updated_data[$idx]);
303 }
304 }
305 $fields = array(
306 "sdata" => array("text", serialize(empty($updated_data) ? '' : serialize($updated_data)))
307 );
308 $primary = array(
309 "id" => array("integer", $row["id"]),
310 "field_id" => array("integer", $row["field_id"])
311 );
312 $ilDB->update("pg_amd_page_list", $fields, $primary);
313 }
314 }
315}
const IL_INSERT_AFTER
static getInstancesByRecordId( $a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
static _getSelectedRecordsByObject(string $a_obj_type, int $a_id, string $a_sub_type="", bool $is_ref_id=true)
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
static getLangVars()
Get lang vars needed for editing.
setNode(php4DOMElement $a_node)
Set xml node of page content.
static migrateField(int $a_field_id, array $mapping)
Migrate search/filter values on advmd change.
static handleCopiedContent(DOMDocument $a_domdoc, bool $a_self_ass=true, bool $a_clone_mobs=false, int $new_parent_id=0, int $obj_copy_id=0)
Handle copied content.
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)
Modify page content after xsl.
setData(array $a_fields_data, int $a_mode=null)
getFieldValues(int $a_data_id=null)
Get filter field values.
php4DOMElement $amdpl_node
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
insertContent(ilPageContent $a_cont_obj, string $a_pos, int $a_mode=IL_INSERT_AFTER, string $a_pcid="", bool $remove_placeholder=true)
insert a content node before/after a sibling or as first child of a parent
special template class to simplify handling of ITX/PEAR
static makeLink(object $nt, int $a_wiki_id, string $text='', string $query='', string $trail='', string $prefix='', bool $a_offline=false)
Make a wiki link, the following formats are supported:
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64