3 class mw_data_pages extends mw_data{
5 function page_ariane($id, $ariane = array()){
6 if($page = $this->page($id)){
7 if($page["id_parent"]) $ariane = $this->page_ariane($page["id_parent"], $ariane);
14 function pages($params = array()){
15 $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null;
16 $enabled = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null;
17 $user = isset($params["user"]) ? $params["user"] : null;
18 $order_by = isset($params["order_by"]) ? $params["order_by"] : null;
19 $order = isset($params["order"]) ? $params["order"] : "ASC";
20 $start = isset($params["start"]) ? $params["start"] : null;
21 $max = isset($params["max"]) ? $params["max"] : null;
22 $sgbd = $this->sgbd();
23 $pages = array("list" => array(), "total" => 0);
24 $SELECT = "SELECT * FROM #--pages";
25 $COUNT_SELECT = "SELECT count(*) as n FROM #--pages";
27 $WHERE .= (isset($id_parent) ? ($WHERE ? " AND" : " WHERE")." id_parent".(strlen($id_parent) > 0 ? "=".$this->eq($id_parent) : " IS NULL") : "");
28 $WHERE .= (isset($enabled) ? ($WHERE ? " AND" : " WHERE")." enabled=".$this->eq($enabled) : "");
29 $WHERE .= (isset($user) ? ($WHERE ? " AND" : " WHERE")." user_creation=".$this->eq($user) : "");
32 " ORDER BY ".$order_by.(isset($order) ? " ".$order : "")
35 $LIMIT = isset($max) ? " LIMIT ".$max.(isset($start) ? " OFFSET ".$start : "") : "";
36 $sql = $COUNT_SELECT.$WHERE;
37 $rst = $sgbd->query($sql);
38 if(!isset($rst)) return false;
39 if($v_rst = $sgbd->fetch_assoc($rst)) $pages["total"] = $v_rst["n"];
40 $sgbd->free_result($rst);
42 $sql = $SELECT.$WHERE.$ORDER_BY.$LIMIT;
43 $rst = $sgbd->query($sql);
44 if(!isset($rst)) return false;
45 while($v_rst = $sgbd->fetch_assoc($rst)) $pages["list"][$v_rst["id"]] = $v_rst;
46 $sgbd->free_result($rst);
51 function pages_arbo($params = array()){
52 $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null;
53 $enabled = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null;
54 $user = isset($params["user"]) ? $params["user"] : null;
55 $order_by = isset($params["order_by"]) ? $params["order_by"] : null;
56 $order = isset($params["order"]) ? $params["order"] : "ASC";
57 $sgbd = $this->sgbd();
59 if(isset($id_parent)){
60 if($parent = $this->page($id_parent)) $arbo = $parent;
63 $arbo["subs"] = array();
64 $SELECT = "SELECT id FROM #--pages";
66 $WHERE .= ($WHERE ? " AND" : " WHERE")." id_parent".(isset($id_parent) && $id_parent ? "=".$this->eq($id_parent) : " IS NULL");
67 $WHERE .= (isset($enabled) ? ($WHERE ? " AND" : " WHERE")." enabled=".$this->eq($enabled) : "");
68 $WHERE .= (isset($user) ? ($WHERE ? " AND" : " WHERE")." user_creation=".$this->eq($user) : "");
71 " ORDER BY ".$order_by.(isset($order) ? " ".$order : "")
74 $sql = $SELECT.$WHERE.$ORDER_BY;
75 $rst = $sgbd->query($sql);
76 if(!isset($rst)) return false;
77 while($v_rst = $sgbd->fetch_assoc($rst)){
78 $params["id_parent"] = $v_rst["id"];
79 $arbo["subs"][] = $this->pages_arbo($params);
81 $sgbd->free_result($rst);
87 $sgbd = $this->sgbd();
88 $sql = "SELECT * FROM #--pages WHERE id=".$this->eq($id);
89 $rst = $sgbd->query($sql);
90 if(!isset($rst)) return false;
91 if($v_rst = $sgbd->fetch_assoc($rst)) $page = $v_rst;
95 function add_page($params){
96 $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null;
97 $title = isset($params["title"]) ? $params["title"] : null;
98 $content = isset($params["content"]) ? $params["content"] : null;
99 $user = isset($params["user"]) ? $params["user"] : null;
100 $enabled = isset($params["enabled"]) ? ($params["enabled"] ? 1 : 0) : 1;
101 $position = isset($params["position"]) ? $params["position"] : 0;
102 $sgbd = $this->sgbd();
104 "INSERT INTO #--pages"
105 ."(id_parent, title, content, date_creation, user_creation, date_last_update, user_last_update, enabled, position)"
107 ."( ".$this->eq($id_parent)
108 .", ".$this->eq($title)
109 .", ".$this->eq($content)
110 .", '".date("Y-m-d H:i:s")."'"
111 .", ".$this->eq($user)
112 .", '".date("Y-m-d H:i:s")."'"
113 .", ".$this->eq($user)
114 .", ".$this->eq($enabled)
115 .", ".$this->eq($position)
117 if($sgbd->query($sql)) return $sgbd->insert_id();
121 function set_page($id, $params, $RAZ = false){
122 if($page = $this->page($id)){
123 $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : ($RAZ ? null : $page["id_parent"]);
124 $title = isset($params["title"]) ? $params["title"] : ($RAZ ? null : $page["title"]);
125 $content = isset($params["content"]) ? $params["content"] : ($RAZ ? null : $page["content"]);
126 $user = isset($params["user"]) ? $params["user"] : null;
127 $enabled = isset($params["enabled"]) ? ($params["enabled"] ? 1 : 0) : ($RAZ ? 1 : $page["enabled"]);
128 $position = isset($params["position"]) ? $params["position"] : ($RAZ ? 0 : $page["position"]);
129 $sgbd = $this->sgbd();
131 "UPDATE #--pages SET"
132 ." id_parent=".$this->eq($id_parent)
133 .", title=".$this->eq($title)
134 .", content=".$this->eq($content)
135 .", date_last_update='".date("Y-m-d H:i:s")."'"
136 .", user_last_update=".$this->eq($user)
137 .", enabled=".$this->eq($enabled)
138 .", position=".$this->eq($position)
139 ." WHERE id=".$this->eq($id);
140 if($sgbd->query($sql)) return true;
145 function del_page($id){
146 $sgbd = $this->sgbd();
147 if($sgbd->query("DELETE FROM #--pages WHERE id=".$this->eq($id))){
148 return $sgbd->query("UPDATE #--pages SET id_parent=NULL WHERE id_parent=".$this->eq($id)) ? true : false;