MyHelperHelper.php
8.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/* src/View/Helper/ButtonHelper.php */
namespace App\View\Helper;
use Cake\View\Helper;
use phpDocumentor\Reflection\Types\Void_;
//class MyButtonHelper extends Helper {
class MyHelperHelper extends Helper {
// On a besoin du HtmlHelper
public $helpers = ['Html', 'Form'];
public function initialize(array $config) {
//debug($config);
}
function echoListToManageOrViewWithIcon($can_manage=false, $list_name, $controller_name, $action_name='index') {
//function echo_list($html, $verb, $list_name, $controller_name, $action_name) {
$verb = $can_manage ? 'Gérer' : 'Voir';
$icon_name = $can_manage ? 'config2.png' : 'see2.png';
$this->echoMenuItemWithIcon($icon_name, "$verb les $list_name", $controller_name, $action_name, 'nom');
}
function echoMenuItemPostLinkWithIcon($icon_name, $title, $controller_name, $action_name) {
$this->echoMenuItemLinkOrPostLinkWithIcon(true, $icon_name, $title, $controller_name, $action_name);
}
function echoMenuItemWithIcon($img_name, $title, $controller_name, $action_name=null, $sort_field=null) {
$this->echoMenuItemLinkOrPostLinkWithIcon(false, $img_name, $title, $controller_name, $action_name, $sort_field);
}
function echoMenuItemLinkOrPostLinkWithIcon($postlink, $img_name, $title, $controller_name, $action_name=null, $sort_field=null) {
$icon_size=40;
echo '<tr>';
echo "<td width=$icon_size>";
echo $this->Html->image("icons/$img_name", [
"alt" => $title,
'height' => $icon_size, 'width' => $icon_size,
'url' => ['controller' => $controller_name, 'action' => $action_name]
]);
echo '</td>';
echo '<td>';
if (! $postlink) {
echo $this->Html->link($title, [
'controller' => $controller_name,
'action' => $action_name,
'sort' => $sort_field,
]);
}
else {
echo $this->Form->postlink($title, [
'controller' => $controller_name,
'action' => $action_name,
], [
'confirm' => __('Êtes-vous sur ?')
]);
}
echo '</td>';
echo '</tr>';
}
public function getActionButton($icon_class, $buttonStyle, $title, $controller, $action, $id, $other_args=[], $tip='', $confirmMessage='', $moreButtonStyle='') {
if ($controller=='') $controller='materiels';
$controllerArgs = [];
$controllerArgs['controller'] = $controller;
$controllerArgs['action'] = $action;
$controllerArgs[] = $id;
foreach ($other_args as $other_arg) $controllerArgs[] = $other_arg;
return $this->Html->link(
__("<i class=$icon_class></i>$title"),
$controllerArgs,
/*
[
'controller' => $controller,
'action' => $action,
$id,
$other_args
],
*/
[
'title' => $tip,
'escape' => false,
'onclick' => 'return true;',
//'style' => 'margin-right: 10px'.$moreButtonStyle,
'style' => $buttonStyle,
'confirm' => $confirmMessage
]
);
}
public function displayElement($nom, $valeur, $params = "") {
$TD = ($params=="") ? 'TD' : "TD $params";
//$TD = ($params=="") ? '<TD>' : '<TD '.$params.'>';
//$tdstyle = $params!="" ? $params : '';
// Ca c'est parce que sinon y'a au moins deux tests qui passent pas, a cause de l'espace dans la balise ...
//if ($valeur != "") echo '<tr> <td><strong>'.$nom.' </strong></td>' . $TD.$valeur.'</td></tr>';
//if ($valeur != "") echo '<tr><td><strong>' . $nom . ' </strong></td>' . $balise . $valeur . '</td></tr>';
//if ($valeur!="") echo "<TR> <TD><strong>".__($nom)."</strong></TD> <$TD>".h($valeur)."</TD> </TR>";
//if ($valeur!="") echo "<TR> <TD><strong>".__($nom)."</strong></TD> <$TD>".$valeur."</TD> </TR>";
if ($valeur!==null && $valeur!=='') {
$val = $valeur;
if ($valeur === true) $val = 'Oui';
if ($valeur === false) $val = 'Non';
echo "<TR> <TD><strong>".__($nom)."</strong></TD> <$TD>".$val."</TD> </TR>";
}
//if ($valeur!="") echo "<TR> <TD><strong>$nom</strong></TD> <$TD>$valeur</TD> </TR>";
}
/* Pour src/Template/Configurations/view et edit */
public function echoSectionStart($title) {
$WITH_TABLE=true;
//echo '<h3 id="t_'.$section.'" style="cursor: pointer;">';
//echo "<h3 id='t_$section' class='toggle' style='cursor: pointer;'>";
echo "<h3 id='t_$title' class='toggle' style='cursor: pointer;'>";
//echo '<i class="icon-chevron-down" style="font-size: 14px;" id="i_'.$section.'"></i>';
echo '<i class="icon-chevron-down" style="font-size: 14px;" id="i_'.$title.'"></i>';
echo '<span style="text-decoration: underline;">'.$title.'</span>';
echo '</h3>';
//echo '<div id="'.$section.'" style="margin-bottom: 20px;">';
echo '<div id="'.$title.'" style="margin-bottom: 20px;">';
if ($WITH_TABLE) {
echo '<table>';
echo '<tr><th style="width: 250px;"></th><th></th></tr>';
}
}
public function echoSectionStop() {
$WITH_TABLE=true;
if ($WITH_TABLE) echo '</table>';
echo '</div>';
}
//function displaySectionShowHide($controller_name, $entity_type_name, $title, $id_name, $is_masculine, $name_field_name, $entities) {
//function displaySectionShowHide($controller_name, $entity_type_name, $title, $is_masculine, $name_field_name, $entities) {
function displayAssociatedEntitiesAsSectionShowHide($controller_name, $entity_type_name, $title, $is_masculin, $name_field_name, $entities) {
$id_name = $controller_name;
$id_h3 = 't_'.$id_name;
$id_i = 'i_'.$id_name;
$title = ucfirst($title).' associé'. ($is_masculin ? 's' : 'es');
echo "<h3 id='$id_h3' class='toggle' style='cursor: pointer;'>";
echo "<i class='icon-chevron-down' style='font-size: 14px;' id='$id_i'></i>";
//echo " <span style='text-decoration: underline;'>$title (".$entities->count().")</span>";
echo " <span style='text-decoration: underline;'>$title (".count($entities).")</span>";
echo "</h3>";
echo "<div id='$id_name' style='margin-bottom: 20px;'>";
//if (true) {
$shift3 = ' ';
$shift5 = ' ';
//if ($entities->isEmpty()) {
if (empty($entities)) {
//echo "Aucune $entity_name liée à ce domaine.";
echo $shift5.($is_masculin ? "Aucun $entity_type_name associé" : "Aucune $entity_type_name associée");
}
else {
echo "<table>";
/*
<tr>
<th><= __('Nom') ?></th>
<th style="width: 50px;"><= __('Détail') ?></th>
</tr>
*/
foreach ($entities as $entity) {
echo "<tr>";
echo "<td>";
// Nom de l'entité (ou numéro de l'entité si nom vide, comme pour les emprunts par exemple...)
$name = $entity->$name_field_name ? $entity->$name_field_name : "$entity_type_name #".$entity->id;
echo $shift3.$this->Html->link(h($name), ['controller' => $controller_name, 'action' => 'view', h($entity->id)]);
echo "</td>";
/*
<td class="actions">
<= $this->Html->link(__('<i class="icon-search"></i>'), ['controller' => $controller, 'action' => 'view', $entity->id], ['escape' => false, 'style' => 'margin:0']) ?>
</td>
*/
echo "</tr>";
}
echo "</table>";
}
echo "</div>";
} // displaySectionShowHide()
}