Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
pagination.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
8 {
9  /*
10  array(
11  "type",
12  "tab",
13  "dirid",
14  "catg",
15  "famid",
16  "pds",
17  "onglet"
18  )
19  */
20  $paginationConfig = $action->getParam("paginationConfig");
21  /*
22  array(
23  "next",
24  "prev",
25  "last",
26  "numberofpage",
27  "pagenumber",
28  "numberofdocuments",
29  "rangefrom",
30  "rangeto",
31  "hasnext"
32  )
33  */
34  $searchConfig = $action->getParam("searchConfig");
35 
36  $action->parent->addJsRef("GENERIC:pagination.js");
37 
38  $layoutKeys = array(
39  "alignleft",
40  "aligncenter",
41  "alignright"
42  );
43  $paginationDefButton = array(
44  /* "%n" => $searchConfig["hasnext"] ? getButtonLayout("nextpage", $paginationConfig, $searchConfig["next"], _("Next page")) : "",
45  "%p" => $searchConfig["pagenumber"] != 1 ? getButtonLayout("prevpage", $paginationConfig, $searchConfig["prev"], _("Previous page")) : "",
46  "%l" => $searchConfig["hasnext"] ? getButtonLayout("lastpage", $paginationConfig, $searchConfig["last"], _("Last page")) : "",
47  "%f" => $searchConfig["pagenumber"] != 1 ? getButtonLayout("firstpage", $paginationConfig, "0", _("First page")) : ""
48  */
49 
50  "%n" => getButtonLayout($action, "nextpage", $paginationConfig, $searchConfig["next"], _("Next page") , $searchConfig["hasnext"]) ,
51  "%p" => getButtonLayout($action, "prevpage", $paginationConfig, $searchConfig["prev"], _("Previous page") , $searchConfig["pagenumber"] != 1) ,
52  "%l" => getButtonLayout($action, "lastpage", $paginationConfig, $searchConfig["last"], _("Last page") , $searchConfig["hasnext"]) ,
53  "%f" => getButtonLayout($action, "firstpage", $paginationConfig, "0", _("First page") , $searchConfig["pagenumber"] != 1)
54  );
55 
56  $paginationDefOther = array(
57  "%np" => $searchConfig["numberofpage"],
58  "%cp" => $searchConfig["pagenumber"],
59  "%nd" => $searchConfig["numberofdocuments"],
60  "%br" => $searchConfig["rangefrom"],
61  "%er" => $searchConfig["rangeto"]
62  );
63 
64  $action->lay->set("pagination", true);
65  if ($paginationConfig["type"] !== "none") {
66 
67  $type = $paginationConfig["type"];
68  switch ($paginationConfig["type"]) {
69  case "basic":
70  $type = "%p%t%cp%t%n";
71  break;
72 
73  case "pageNumber":
74  $type = "%f%p%t%cp/%np%t%n%l";
75  break;
76 
77  case "documentNumber":
78  $type = _("Showing %br to %er of %nd documents%t%t%p%n");
79  break;
80 
81  default:
82  if ($type) {
83  $type = _($type);
84  }
85  }
86  $parts = explode("%t", $type);
87  $action->lay->set("centeralign", count($parts) > 1);
88  $action->lay->set("rightalign", count($parts) > 2);
89 
90  foreach ($parts as $k => $v) {
91  if ($k > 2) break;
92 
93 
94  if (!empty($v)) {
95  $v = str_replace(array_keys($paginationDefOther) , array_values($paginationDefOther) , $v);
96  $action->lay->set($layoutKeys[$k], str_replace(array_keys($paginationDefButton) , array_values($paginationDefButton) , $v));
97  } else $action->lay->set($layoutKeys[$k], "");
98  }
99  } else {
100  $action->lay->set("pagination", false);
101  }
102 }
103 
104 function getButtonLayout(Action & $action, $buttonName, $paginationConfig, $page, $buttonTitle, $visible = true)
105 {
106  $lay = new Layout("GENERIC/Layout/pagination_button.xml");
107  foreach ($paginationConfig as $key => $value) {
108  $lay->set($key, $value);
109  }
110  $lay->set("APPNAME", isset($action->parent->name) ? $action->parent->name : '');
111  $lay->set("page", $page);
112  $lay->set("buttonclass", $buttonName);
113  $lay->set("buttontitle", $buttonTitle);
114  $lay->set("buttonvisible", $visible == true);
115  return $lay->gen();
116 }
Layout is a template generator.
global $action
getButtonLayout(Action &$action, $buttonName, $paginationConfig, $page, $buttonTitle, $visible=true)
Definition: pagination.php:104
pagination(Action &$action)
Definition: pagination.php:7
getParam($name, $def="")
$value
← centre documentaire © anakeen