Ubiquity  2.0.0
php rapid development framework
Gui.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Ubiquity\views;
4 
10 class Gui {
11 
18  public static function show($values, $method='toString', $implode="<br/>") {
19  if (is_array($values)) {
20  foreach ( $values as $v ) {
21  Gui::showOne($v, $method);
22  echo $implode;
23  }
24  } else
25  Gui::showOne($values, $method);
26  }
27 
34  public static function get($values, $method='toString', $implode="<br/>") {
35  $result="";
36  if (is_array($values)) {
37  foreach ( $values as $v ) {
38  $result.=Gui::getOne($v, $method) . $implode;
39  }
40  } else
41  $result=Gui::getOne($values, $method);
42  return $result;
43  }
44 
50  public static function showOne($value, $method='toString') {
51  echo Gui::getOne($value, $method);
52  }
53 
59  public static function getOne($value, $method='toString') {
60  if (method_exists("GUI", $method)) {
61  $value=GUI::$method($value);
62  } else {
63  if (method_exists($value, $method)) {
64  $value=$value->$method();
65  } else {
66  $value=$value . '';
67  }
68  }
69  return $value;
70  }
71 
77  public static function addDelete($value) {
78  return "<tr><td class='element'><input title='Sélectionner' type='checkbox' class='ck' id='ck" . $value->getId() . "' value='" . $value->getId() . "'><span title='Modifier...' class='update' id='update" . $value->getId() . "'>&nbsp;" . $value->toString() . "<span></td><td><span title='Supprimer...' class='delete' id='delete" . $value->getId() . "'>&nbsp;</span></td></tr>";
79  }
80 
86  public static function toSelect($value) {
87  return "<option class='element' id='element" . $value->getId() . "' value='" . $value->getId() . "'>" . $value->toString() . "</option>";
88  }
89 
95  public static function select($values, $value, $first=null) {
96  $result="";
97  if ($first) {
98  $result.="<option class='element'>" . $first . "</option>";
99  }
100  foreach ( $values as $v ) {
101  $selected="";
102  $id=$v;
103  if (is_object($v) === true) {
104  $id=$v->getId();
105  }
106  if ($id === $value) {
107  $selected="selected";
108  }
109  $result.="<option " . $selected . " class='element' id='element" . $id . "' value='" . $id . "'>" . $v . "</option>";
110  }
111  return $result;
112  }
113 
120  public static function pluriel($singulier, $pluriel, $nb) {
121  if ($nb == 0) {
122  $result="Aucun " . $singulier;
123  } else {
124  $result=sprintf(ngettext("%d " . $singulier, "%d " . $pluriel, $nb), $nb);
125  }
126  return $result;
127  }
128 }
static getOne($value, $method='toString')
Retourne un objet $value en lui ayant au préalable appliqué la méthode $method.
Definition: Gui.php:59
static addDelete($value)
Definition: Gui.php:77
static show($values, $method='toString', $implode="<br/>")
Affiche un objet ou un tableau d&#39;objets en appliquant au préalable la méthode $method à chacun d&#39;entr...
Definition: Gui.php:18
Classe technique destinée à la conception des interfaces.
Definition: Gui.php:10
static showOne($value, $method='toString')
Affiche un objet $value en lui ayant au préalable appliqué la méthode $method.
Definition: Gui.php:50
static toSelect($value)
Definition: Gui.php:86
static select($values, $value, $first=null)
Retourne un objet ou un tableau d&#39;objets sous forme de liste HTML (select)
Definition: Gui.php:95
static pluriel($singulier, $pluriel, $nb)
Retourne l&#39;expression $singulier au pluriel en fonction du nombre $nb.
Definition: Gui.php:120