ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilWikiPageTemplate.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  public const TYPE_ALL = 0;
27  public const TYPE_NEW_PAGES = 1;
28  public const TYPE_ADD_TO_PAGE = 2;
29 
30  protected ilDBInterface $db;
31  protected int $wiki_id;
32 
33  public function __construct(
34  int $a_wiki_id
35  ) {
36  global $DIC;
37 
38  $this->wiki_id = $a_wiki_id;
39  $this->db = $DIC->database();
40  }
41 
42  public function getAllInfo(
43  int $a_type = self::TYPE_ALL,
44  string $lang = "-"
45  ): array {
46  if ($lang === "") {
47  $lang = "-";
48  }
49  $and = "";
50  if ($a_type === self::TYPE_NEW_PAGES) {
51  $and = " AND t.new_pages = " . $this->db->quote(1, "integer");
52  }
53  if ($a_type === self::TYPE_ADD_TO_PAGE) {
54  $and = " AND t.add_to_page = " . $this->db->quote(1, "integer");
55  }
56 
57  $set = $this->db->queryF(
58  $q = "SELECT t.wiki_id, t.wpage_id, p.title, t.new_pages, t.add_to_page FROM wiki_page_template t JOIN il_wiki_page p ON " .
59  " (t.wpage_id = p.id AND p.lang = %s) " .
60  " WHERE t.wiki_id = %s " .
61  $and,
62  ["text", "integer"],
63  [$lang, $this->wiki_id]
64  );
65  $templates = array();
66  while ($rec = $this->db->fetchAssoc($set)) {
67  $templates[] = $rec;
68  }
69  return $templates;
70  }
71 
76  public function save(
77  int $a_id,
78  int $a_new_pages = 0,
79  int $a_add_to_page = 0
80  ): void {
81  if ($a_id <= 0) {
82  return;
83  }
84 
85  $set = $this->db->query(
86  "SELECT * FROM wiki_page_template " .
87  " WHERE wiki_id = " . $this->db->quote($this->wiki_id, "integer") .
88  " AND wpage_id = " . $this->db->quote($a_id, "integer")
89  );
90  if (!$this->db->fetchAssoc($set)) {
91  $this->db->manipulate("INSERT INTO wiki_page_template " .
92  "(wiki_id, wpage_id, new_pages, add_to_page) VALUES (" .
93  $this->db->quote($this->wiki_id, "integer") . "," .
94  $this->db->quote($a_id, "integer") . "," .
95  $this->db->quote($a_new_pages, "integer") . "," .
96  $this->db->quote($a_add_to_page, "integer") .
97  ")");
98  } else {
99  $this->db->manipulate(
100  "UPDATE wiki_page_template SET " .
101  " new_pages = " . $this->db->quote($a_new_pages, "integer") . "," .
102  " add_to_page = " . $this->db->quote($a_add_to_page, "integer") .
103  " WHERE wiki_id = " . $this->db->quote($this->wiki_id, "integer") .
104  " AND wpage_id = " . $this->db->quote($a_id, "integer")
105  );
106  }
107  }
108 
113  public function remove(
114  int $a_id
115  ): void {
116  $this->db->manipulate(
117  "DELETE FROM wiki_page_template WHERE " .
118  " wiki_id = " . $this->db->quote($this->wiki_id, "integer") .
119  " AND wpage_id = " . $this->db->quote($a_id, "integer")
120  );
121  }
122 
126  public function isPageTemplate(int $a_id): bool
127  {
128  $set = $this->db->query("SELECT t.wpage_id" .
129  " FROM wiki_page_template t" .
130  " JOIN il_wiki_page p ON " .
131  " (t.wpage_id = p.id) " .
132  " WHERE t.wiki_id = " . $this->db->quote($this->wiki_id, "integer") .
133  " AND p.id = " . $this->db->quote($a_id, "integer"));
134  return (bool) $this->db->numRows($set);
135  }
136 }
isPageTemplate(int $a_id)
Is page set as template?
getAllInfo(int $a_type=self::TYPE_ALL, string $lang="-")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:22
$lang
Definition: xapiexit.php:25
save(int $a_id, int $a_new_pages=0, int $a_add_to_page=0)
Add wiki page template.
$q
Definition: shib_logout.php:21