3 class mw_data_pages extends mw_data
6 function page_ariane($id, $ariane = array())
7 { if($page = $this->page($id))
8 { if($page["id_parent"]) $ariane = $this->page_ariane($page["id_parent"], $ariane);
15 function pages($params = array())
16 { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null;
17 $enabled = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null;
18 $user = isset($params["user"]) ? $params["user"] : null;
19 $order_by = isset($params["order_by"]) ? $params["order_by"] : null;
20 $order = isset($params["order"]) ? $params["order"] : "ASC";
21 $start = isset($params["start"]) ? $params["start"] : null;
22 $max = isset($params["max"]) ? $params["max"] : null;
23 $sgbd = $this->sgbd();
24 $pages = array("list" => array(), "total" => 0);
26 if($rst = $sgbd->open_data("pages"))
27 { while($v_rst = $sgbd->fetch_data($rst))
28 { if(isset($v_rst)) $res[$v_rst["id"]] = $v_rst;
34 $sgbd->close_data($rst);
36 { if(isset($order_by)) $res = $this->ordonne($res, "position", isset($order) ? $order : "ASC");
37 foreach($res as $id_res => $v_rst)
41 ( ($id_parent && isset($v_rst["id_parent"]) && ($id_parent == $v_rst["id_parent"]))
42 || ($id_parent == "" && !$v_rst["id_parent"])
47 { $MATCH = ($v_rst["enabled"] == $enabled);
52 { $MATCH = ($v_rst["user_creation"] == $user);
57 $MATCH = !isset($start) || !$max || ($pages["total"] > $start && $pages["total"] <= ($start + $max));
59 if($MATCH) $pages["list"][$v_rst["id"]] = $v_rst;
67 function pages_arbo($params = array())
68 { $params["id_parent"] = isset($params["id_parent"]) ? $params["id_parent"] : "";
69 $params["enabled"] = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null;
70 $params["user"] = isset($params["user"]) ? $params["user"] : null;
71 $params["order_by"] = isset($params["order_by"]) ? $params["order_by"] : null;
72 $params["order"] = isset($params["order"]) ? $params["order"] : "ASC";
73 $sgbd = $this->sgbd();
75 if($params["id_parent"])
76 { if($parent = $this->page($params["id_parent"])) $arbo = $parent;
79 $arbo["subs"] = array();
80 if(($subs = $this->pages($params)) !== false)
81 { foreach($subs["list"] as $id_sub => $sub)
82 { $params["id_parent"] = $sub["id"];
83 $arbo["subs"][] = $this->pages_arbo($params);
90 { $sgbd = $this->sgbd();
91 return ($page = $sgbd->get_data("pages", $id)) ? $page : false;
94 function add_page($params)
95 { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null;
96 $title = isset($params["title"]) ? $params["title"] : null;
97 $content = isset($params["content"]) ? $params["content"] : null;
98 $user = isset($params["user"]) ? $params["user"] : null;
99 $enabled = isset($params["enabled"]) ? ($params["enabled"] ? 1 : 0) : 1;
100 $position = isset($params["position"]) ? $params["position"] : 0;
101 $sgbd = $this->sgbd();
103 ( ( $id_page = $sgbd->add_data
106 ( "id_parent" => $id_parent,
108 "content" => $content,
109 "date_creation" => date("Y-m-d H:i:s"),
110 "user_creation" => $user,
111 "date_last_update" => date("Y-m-d H:i:s"),
112 "user_last_update" => $user,
113 "enabled" => $enabled,
114 "position" => $position
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();
130 return $sgbd->set_data
134 ( "id_parent" => $id_parent,
136 "content" => $content,
137 "date_creation" => $page["date_creation"],
138 "user_creation" => $page["user_creation"],
139 "date_last_update" => date("Y-m-d H:i:s"),
140 "user_last_update" => $user,
141 "enabled" => $enabled,
142 "position" => $position
149 function del_page($id)
150 { $sgbd = $this->sgbd();
151 if($sgbd->del_data("pages", $id))
153 if($rst = $sgbd->open_data("pages"))
154 { while($v_rst = $sgbd->fetch_data($rst))
156 { if(isset($v_rst["id_parent"]) && isset($v_rst["id"]) && $v_rst["id_parent"] == $id)
157 { unset($v_rst["id_parent"]);
158 if(!$sgbd->set_data("pages", $v_rst["id"], $v_rst))
166 $sgbd->close_data($rst);