syntaxe POO (visibilite)
[mw_pages] / app / helpers / mw_helper_pages.php
1 <?php
2
3   class mw_helper_pages extends mw_helper{
4
5     public function datetime2timestamp($string){
6       list($date, $time) = explode(" ", $string);
7       list($year, $month, $day) = explode("-", $date);
8       list($hour, $minute, $second) = explode(":", $time);
9       $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
10       return $timestamp;
11     }
12
13     public function pages_arbo_navig_lis($env, $arbo, $ariane = array()){
14       $content = "";
15       if($arbo["subs"]){
16         if($path_item = array_shift($ariane)){
17           foreach($arbo["subs"] as $page){
18             $content .= "<li".($path_item["id"] == $page["id"] ? " class=\"current\"" : "")."><a href=\"".$env->url("pages/view/page", array("id" => $page["id"]))."\">".$page["title"]."</a></li>\n";
19             if($path_item["id"] == $page["id"]){
20               if($sub_content = $this->pages_arbo_navig_lis($env, $page, $ariane)){
21                 $content .=
22                  "<ul>\n"
23                 .$sub_content
24                 ."</ul>\n";
25               }
26             }
27           }
28         }
29         else{
30           foreach($arbo["subs"] as $page){
31             $content .= "<li><a href=\"".$env->url("pages/view/page", array("id" => $page["id"]))."\">".$page["title"]."</a></li>\n";
32           }
33         }
34       }
35       return $content;
36     }
37
38     public function pages_arbo_edit_select_options($arbo, $id_page, $id_parent, $indent_increment = "", $indent = ""){
39       $arbo["id"] = $arbo["id"] ? $arbo["id"] : "";
40       $content =
41        "<option"
42       ." value=\"".$arbo["id"]."\""
43       .(isset($id_parent) && ($arbo["id"] == $id_parent) ? " selected=\"selected\"" : "")
44       .">"
45       .$indent.($arbo["id"] ? $arbo["title"] : "Aucune")
46       ."</option>";
47       if($arbo["subs"]){
48         $indent .= $indent_increment;
49         foreach($arbo["subs"] as $i => $sub){
50           if(!isset($id_page) || $id_page != $sub["id"]){
51             $content .= $this->pages_arbo_edit_select_options($sub, $id_page, $id_parent, $indent_increment, $indent);
52           }
53         }
54       }
55       return $content;
56     }
57
58     public function pages_arbo_list_select_options($env, $etat, $arbo, $current_page_id, $indent_increment = "", $indent = ""){
59       $arbo["id"] = isset($arbo["id"]) ? $arbo["id"] : "";
60       $content =
61        "<option"
62       ." value=\"".$env->url($etat, array("parent" => $arbo["id"]))."\""
63       .(isset($current_page_id) && ($arbo["id"] == $current_page_id) ? " selected=\"selected\"" : "")
64       .">"
65       .$indent.($arbo["id"] ? $arbo["title"] : "Racine des pages")
66       ."</option>";
67       if($arbo["subs"]){
68         $indent .= $indent_increment;
69         foreach($arbo["subs"] as $i => $sub){
70           $content .= $this->pages_arbo_list_select_options($env, $etat, $sub, $current_page_id, $indent_increment, $indent);
71         }
72       }
73       return $content;
74     }
75
76     public function pages_arbo_start_select_options($env, $arbo, $current_start_action, $current_start_action_params, $indent_increment = "", $indent = ""){
77       $arbo["id"] = isset($arbo["id"]) ? $arbo["id"] : "";
78       $content = "";
79       if($arbo["id"]){
80         $content =
81          "<option"
82         ." value=\"".$arbo["id"]."\""
83         .(    isset($current_start_action)
84            && ($current_start_action == "pages/view/page")
85            && isset($current_start_action_params["id"])
86            && ($arbo["id"] == $current_start_action_params["id"])
87            ?
88              " selected=\"selected\""
89            : ""
90          )
91         .">"
92         .$indent.$arbo["title"]
93         ."</option>";
94       }
95       if($arbo["subs"]){
96         $indent .= $indent_increment;
97         $indent .= "&nbsp;&nbsp;";
98         foreach($arbo["subs"] as $i => $sub){
99           $content .= $this->pages_arbo_start_select_options($env, $sub, $current_start_action, $current_start_action_params, $indent_increment, $indent);
100         }
101       }
102       return $content;
103     }
104
105   }