ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilWikiPageTemplate.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
4
13{
17 protected $db;
18
19 const TYPE_ALL = 0;
20 const TYPE_NEW_PAGES = 1;
22
23 protected $wiki_id;
24 protected $ilDB;
25
31 public function __construct($a_wiki_id)
32 {
33 global $DIC;
34
35 $ilDB = $DIC->database();
36
37 $this->wiki_id = $a_wiki_id;
38 $this->db = $ilDB;
39 }
40
44 public function getAllInfo($a_type = self::TYPE_ALL)
45 {
46 $and = "";
47 if ($a_type == self::TYPE_NEW_PAGES) {
48 $and = " AND t.new_pages = " . $this->db->quote(1, "integer");
49 }
50 if ($a_type == self::TYPE_ADD_TO_PAGE) {
51 $and = " AND t.add_to_page = " . $this->db->quote(1, "integer");
52 }
53
54 $set = $this->db->query(
55 $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 " .
56 " (t.wpage_id = p.id) " .
57 " WHERE t.wiki_id = " . $this->db->quote($this->wiki_id, "integer") .
58 $and
59 );
60 $templates = array();
61 while ($rec = $this->db->fetchAssoc($set)) {
62 $templates[] = $rec;
63 }
64 return $templates;
65 }
66
72 public function save($a_id, $a_new_pages = 0, $a_add_to_page = 0)
73 {
74 if ($a_id <= 0) {
75 return;
76 }
77
78 $set = $this->db->query(
79 "SELECT * FROM wiki_page_template " .
80 " WHERE wiki_id = " . $this->db->quote($this->wiki_id, "integer") .
81 " AND wpage_id = " . $this->db->quote($a_id, "integer")
82 );
83 if (!$this->db->fetchAssoc($set)) {
84 $this->db->manipulate("INSERT INTO wiki_page_template " .
85 "(wiki_id, wpage_id, new_pages, add_to_page) VALUES (" .
86 $this->db->quote($this->wiki_id, "integer") . "," .
87 $this->db->quote($a_id, "integer") . "," .
88 $this->db->quote($a_new_pages, "integer") . "," .
89 $this->db->quote($a_add_to_page, "integer") .
90 ")");
91 } else {
92 $this->db->manipulate(
93 "UPDATE wiki_page_template SET " .
94 " new_pages = " . $this->db->quote($a_new_pages, "integer") . "," .
95 " add_to_page = " . $this->db->quote($a_add_to_page, "integer") .
96 " WHERE wiki_id = " . $this->db->quote($this->wiki_id, "integer") .
97 " AND wpage_id = " . $this->db->quote($a_id, "integer")
98 );
99 }
100 }
101
107 public function remove($a_id)
108 {
109 $this->db->manipulate(
110 "DELETE FROM wiki_page_template WHERE " .
111 " wiki_id = " . $this->db->quote($this->wiki_id, "integer") .
112 " AND wpage_id = " . $this->db->quote($a_id, "integer")
113 );
114 }
115
122 public function isPageTemplate($a_id)
123 {
124 $set = $this->db->query("SELECT t.wpage_id" .
125 " FROM wiki_page_template t" .
126 " JOIN il_wiki_page p ON " .
127 " (t.wpage_id = p.id) " .
128 " WHERE t.wiki_id = " . $this->db->quote($this->wiki_id, "integer") .
129 " AND p.id = " . $this->db->quote($a_id, "integer"));
130 return (bool) $this->db->numRows($set);
131 }
132}
An exception for terminatinating execution or to throw for unit testing.
isPageTemplate($a_id)
Is page set as template?
save($a_id, $a_new_pages=0, $a_add_to_page=0)
Add wiki page template.
getAllInfo($a_type=self::TYPE_ALL)
Get all info.
__construct($a_wiki_id)
Constructor.
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92