3 class mw_data_pages extends mw_data{
5 public function page_ariane($id, $ariane = array()){
6 if($page = $this->page($id)){
7 if(isset($page["id_parent"]) && $page["id_parent"]) $ariane = $this->page_ariane($page["id_parent"], $ariane);
14 public 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);
25 if($rst = $sgbd->open_data("pages")){
26 while($v_rst = $sgbd->fetch_data($rst)){
27 if(isset($v_rst)) $res[$v_rst["id"]] = $v_rst;
33 $sgbd->close_data($rst);
35 if(isset($order_by)) $res = $this->ordonne($res, "position", isset($order) ? $order : "ASC");
36 foreach($res as $id_res => $v_rst){
38 if(isset($id_parent)){
40 ($id_parent && isset($v_rst["id_parent"]) && ($id_parent == $v_rst["id_parent"]))
41 || ($id_parent == "" && (!isset($v_rst["id_parent"]) || !$v_rst["id_parent"]))
46 $MATCH = ($v_rst["enabled"] == $enabled);
51 $MATCH = ($v_rst["user_creation"] == $user);
56 $MATCH = !isset($start) || !$max || ($pages["total"] > $start && $pages["total"] <= ($start + $max));
58 if($MATCH) $pages["list"][$v_rst["id"]] = $v_rst;
66 public function pages_arbo($params = array()){
67 $params["id_parent"] = isset($params["id_parent"]) ? $params["id_parent"] : "";
68 $params["enabled"] = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null;
69 $params["user"] = isset($params["user"]) ? $params["user"] : null;
70 $params["order_by"] = isset($params["order_by"]) ? $params["order_by"] : null;
71 $params["order"] = isset($params["order"]) ? $params["order"] : "ASC";
72 $sgbd = $this->sgbd();
74 if($params["id_parent"]){
75 if($parent = $this->page($params["id_parent"])) $arbo = $parent;
78 $arbo["subs"] = array();
79 if(($subs = $this->pages($params)) !== false){
80 foreach($subs["list"] as $id_sub => $sub){
81 $params["id_parent"] = $sub["id"];
82 $arbo["subs"][] = $this->pages_arbo($params);
88 public function page($id){
89 $sgbd = $this->sgbd();
90 return ($page = $sgbd->get_data("pages", $id)) ? $page : false;
93 public function add_page($params){
94 $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null;
95 $title = isset($params["title"]) ? $params["title"] : null;
96 $content = isset($params["content"]) ? $params["content"] : null;
97 $user = isset($params["user"]) ? $params["user"] : null;
98 $enabled = isset($params["enabled"]) ? ($params["enabled"] ? 1 : 0) : 1;
99 $position = isset($params["position"]) ? $params["position"] : 0;
100 $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 public 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 : (isset($page["id_parent"]) ? $page["id_parent"] : null));
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 public 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);