maj syntaxe accolades et correction param manquant
[mw_pages] / app / data / modules / xml / mw_data_pages.php
index 18a3613..9ea3f70 100644 (file)
@@ -1,19 +1,18 @@
 <?php
 
-  class mw_data_pages extends mw_data
-  {
+  class mw_data_pages extends mw_data{
 
-    function page_ariane($id, $ariane = array())
-    { if($page = $this->page($id))
-      { if($page["id_parent"]) $ariane = $this->page_ariane($page["id_parent"], $ariane);
+    function page_ariane($id, $ariane = array()){
+      if($page = $this->page($id)){
+        if($page["id_parent"]) $ariane = $this->page_ariane($page["id_parent"], $ariane);
         $ariane[] = $page;
         return $ariane;
       }
       return false;
     }
 
-    function pages($params = array())
-    { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null;
+    function pages($params = array()){
+      $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null;
       $enabled = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null;
       $user = isset($params["user"]) ? $params["user"] : null;
       $order_by = isset($params["order_by"]) ? $params["order_by"] : null;
       $sgbd = $this->sgbd();
       $pages = array("list" => array(), "total" => 0);
       $res = array();
-      if($rst = $sgbd->open_data("pages"))
-      { while($v_rst = $sgbd->fetch_data($rst))
-        { if(isset($v_rst)) $res[$v_rst["id"]] = $v_rst;
-          else
-          { $res = false;
+      if($rst = $sgbd->open_data("pages")){
+        while($v_rst = $sgbd->fetch_data($rst)){
+          if(isset($v_rst)) $res[$v_rst["id"]] = $v_rst;
+          else{
+            $res = false;
             break;
           }
         }
         $sgbd->close_data($rst);
-        if($res !== false)
-        { if(isset($order_by)) $res = $this->ordonne($res, "position", isset($order) ? $order : "ASC");
-          foreach($res as $id_res => $v_rst)
-          { $MATCH = true;
-            if(isset($id_parent))
-            { $MATCH =
-              (    ($id_parent && isset($v_rst["id_parent"]) && ($id_parent == $v_rst["id_parent"]))
+        if($res !== false){
+          if(isset($order_by)) $res = $this->ordonne($res, "position", isset($order) ? $order : "ASC");
+          foreach($res as $id_res => $v_rst){
+            $MATCH = true;
+            if(isset($id_parent)){
+              $MATCH = (
+                   ($id_parent && isset($v_rst["id_parent"]) && ($id_parent == $v_rst["id_parent"]))
                 || ($id_parent == "" && !$v_rst["id_parent"])
               );
             }
-            if($MATCH)
-            { if(isset($enabled))
-              { $MATCH = ($v_rst["enabled"] == $enabled);
+            if($MATCH){
+              if(isset($enabled)){
+                $MATCH = ($v_rst["enabled"] == $enabled);
               }
             }
-            if($MATCH)
-            { if(isset($user))
-              { $MATCH = ($v_rst["user_creation"] == $user);
+            if($MATCH){
+              if(isset($user)){
+                $MATCH = ($v_rst["user_creation"] == $user);
               }
             }
-            if($MATCH)
-            { $pages["total"]++;
+            if($MATCH){
+              $pages["total"]++;
               $MATCH = !isset($start) || !$max || ($pages["total"] > $start && $pages["total"] <= ($start + $max));
             }
             if($MATCH) $pages["list"][$v_rst["id"]] = $v_rst;
       return $pages;
     }
 
-    function pages_arbo($params = array())
-    { $params["id_parent"] = isset($params["id_parent"]) ? $params["id_parent"] : "";
+    function pages_arbo($params = array()){
+      $params["id_parent"] = isset($params["id_parent"]) ? $params["id_parent"] : "";
       $params["enabled"] = isset($params["enabled"]) ? ($params["enabled"] ? "1" : "0") : null;
       $params["user"] = isset($params["user"]) ? $params["user"] : null;
       $params["order_by"] = isset($params["order_by"]) ? $params["order_by"] : null;
       $params["order"] = isset($params["order"]) ? $params["order"] : "ASC";
       $sgbd = $this->sgbd();
       $arbo = array();
-      if($params["id_parent"])
-      { if($parent = $this->page($params["id_parent"])) $arbo = $parent;
+      if($params["id_parent"]){
+        if($parent = $this->page($params["id_parent"])) $arbo = $parent;
         else return false;
       }
       $arbo["subs"] = array();
-      if(($subs = $this->pages($params)) !== false)
-      { foreach($subs["list"] as $id_sub => $sub)
-        { $params["id_parent"] = $sub["id"];
+      if(($subs = $this->pages($params)) !== false){
+        foreach($subs["list"] as $id_sub => $sub){
+          $params["id_parent"] = $sub["id"];
           $arbo["subs"][] = $this->pages_arbo($params);
         }
       }
       return $arbo;
     }
 
-    function page($id)
-    { $sgbd = $this->sgbd();
+    function page($id){
+      $sgbd = $this->sgbd();
       return ($page = $sgbd->get_data("pages", $id)) ? $page : false;
     }
 
-    function add_page($params)
-    { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null;
+    function add_page($params){
+      $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : null;
       $title = isset($params["title"]) ? $params["title"] : null;
       $content = isset($params["content"]) ? $params["content"] : null;
       $user = isset($params["user"]) ? $params["user"] : null;
       $enabled = isset($params["enabled"]) ? ($params["enabled"] ? 1 : 0) : 1;
       $position = isset($params["position"]) ? $params["position"] : 0;
       $sgbd = $this->sgbd();
-      return
-      ( ( $id_page = $sgbd->add_data
-          ( "pages",
+      return (
+        (
+          $id_page = $sgbd->add_data(
+            "pages",
             array
             ( "id_parent" => $id_parent,
               "title" => $title,
       );
     }
 
-    function set_page($id, $params, $RAZ = false)
-    { if($page = $this->page($id))
-      { $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : ($RAZ ? null : $page["id_parent"]);
+    function set_page($id, $params, $RAZ = false){
+      if($page = $this->page($id)){
+        $id_parent = isset($params["id_parent"]) ? $params["id_parent"] : ($RAZ ? null : $page["id_parent"]);
         $title = isset($params["title"]) ? $params["title"] : ($RAZ ? null : $page["title"]);
         $content = isset($params["content"]) ? $params["content"] : ($RAZ ? null : $page["content"]);
         $user = isset($params["user"]) ? $params["user"] : null;
         $enabled = isset($params["enabled"]) ? ($params["enabled"] ? 1 : 0) : ($RAZ ? 1 : $page["enabled"]);
         $position = isset($params["position"]) ? $params["position"] : ($RAZ ? 0 : $page["position"]);
         $sgbd = $this->sgbd();
-        return $sgbd->set_data
-        ( "pages",
+        return $sgbd->set_data(
+          "pages",
           $id,
-          array
-          ( "id_parent" => $id_parent,
+          array(
+            "id_parent" => $id_parent,
             "title" => $title,
             "content" => $content,
             "date_creation" => $page["date_creation"],
       return false;
     }
 
-    function del_page($id)
-    { $sgbd = $this->sgbd();
-      if($sgbd->del_data("pages", $id))
-      { $OK = true;
-        if($rst = $sgbd->open_data("pages"))
-        { while($v_rst = $sgbd->fetch_data($rst))
-          { if(isset($v_rst))
-            { if(isset($v_rst["id_parent"]) && isset($v_rst["id"]) && $v_rst["id_parent"] == $id)
-              { unset($v_rst["id_parent"]);
-                if(!$sgbd->set_data("pages", $v_rst["id"], $v_rst))
-                { $OK = false;
+    function del_page($id){
+      $sgbd = $this->sgbd();
+      if($sgbd->del_data("pages", $id)){
+        $OK = true;
+        if($rst = $sgbd->open_data("pages")){
+          while($v_rst = $sgbd->fetch_data($rst)){
+            if(isset($v_rst)){
+              if(isset($v_rst["id_parent"]) && isset($v_rst["id"]) && $v_rst["id_parent"] == $id){
+                unset($v_rst["id_parent"]);
+                if(!$sgbd->set_data("pages", $v_rst["id"], $v_rst)){
+                  $OK = false;
                   break;
                 }
               }