Commit b4d9998858c6fc4fb071fdfa3345d32470c22f46
1 parent
2dcbb7bd
Exists in
master
and in
2 other branches
user add : moins de ldap... (suite)
refactorisation: création de setUsersLists() dans AppController
Showing
4 changed files
with
41 additions
and
17 deletions
Show diff stats
src/Controller/AppController.php
... | ... | @@ -472,6 +472,26 @@ class AppController extends Controller |
472 | 472 | return false; |
473 | 473 | } |
474 | 474 | |
475 | + | |
476 | + // (EP) Used by Materiels and Users Controllers | |
477 | + protected function setUsersLists() { | |
478 | + // On recup tous les users du LDAP (ou fakeLDAP si on n'est pas en mode LDAP) | |
479 | + //$users = TableRegistry::get('LdapConnections')->getListUsers(); | |
480 | + //sort($users); | |
481 | + $users_login_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersLoginAndEmail(); | |
482 | + $users_name = array_keys($users_login_and_email); | |
483 | + // Formatage en $users_option_list["Etienne Pallier"] = "Etienne Pallier" ... | |
484 | + $users_option_list = []; | |
485 | + for ($i = 0; $i < sizeof($users_name); $i ++) | |
486 | + $users_option_list[$users_name[$i]] = $users_name[$i]; | |
487 | + $this->set(compact( | |
488 | + 'users_option_list', | |
489 | + 'users_login_and_email' | |
490 | + )); | |
491 | + return $users_name; | |
492 | + } | |
493 | + | |
494 | + | |
475 | 495 | public function getTablePriviledgedUserFromCurrentSessionUserIfExists($user = null) |
476 | 496 | { |
477 | 497 | if (! $this->CURRENT_PRIVILEDGED_USER) { | ... | ... |
src/Controller/MaterielsController.php
... | ... | @@ -935,17 +935,19 @@ class MaterielsController extends AppController |
935 | 935 | // not used |
936 | 936 | //$utilisateurconnect = $usersTable->find('all')->toArray(); |
937 | 937 | |
938 | - // TODO: code redondant avec edit(), à factoriser | |
939 | - // HOWTO: https://book.cakephp.org/3.0/en/orm.html | |
938 | + | |
939 | + $users_name = $this->setUsersLists(); | |
940 | + /* | |
940 | 941 | //$users = TableRegistry::get('LdapConnections')->getListUsers(); |
941 | - //$users = TableRegistry::get('LdapConnections')->getUsersWithNameAndEmail(); | |
942 | - $users_login_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); | |
942 | + //$users = TableRegistry::get('LdapConnections')->getUsersLoginAndEmail(); | |
943 | + $users_login_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersLoginAndEmail(); | |
943 | 944 | $users_name = array_keys($users_login_and_email); |
944 | 945 | $users_option_list = []; |
945 | 946 | for ($i = 0; $i < sizeof($users_name); $i ++) { |
946 | 947 | // $users_option_list["Etienne Pallier"] = "Etienne Pallier" |
947 | 948 | $users_option_list[$users_name[$i]] = $users_name[$i]; |
948 | 949 | } |
950 | + */ | |
949 | 951 | |
950 | 952 | $mail_responsable = $usersTable->find() |
951 | 953 | ->select('email') |
... | ... | @@ -984,7 +986,8 @@ class MaterielsController extends AppController |
984 | 986 | return in_array($fieldName, $myReadonlyFields); |
985 | 987 | }; |
986 | 988 | |
987 | - $this->set('isReadonlyField', $isReadonlyField); | |
989 | + //$this->set('isReadonlyField', $isReadonlyField); | |
990 | + $this->set(compact('isReadonlyField')); | |
988 | 991 | $this->set('IS_CREATED', $materiel->status == 'CREATED'); |
989 | 992 | $this->set('IS_VALIDATED', $materiel->status == 'VALIDATED'); |
990 | 993 | $this->set('IS_ARCHIVED_OR_TOBE', in_array($materiel->status, [ |
... | ... | @@ -1038,7 +1041,7 @@ class MaterielsController extends AppController |
1038 | 1041 | 'lieu_detail', |
1039 | 1042 | 'fournisseurs', |
1040 | 1043 | //'utilisateurs', |
1041 | - 'users_login_and_email', 'users_option_list', | |
1044 | + //'users_login_and_email', 'users_option_list', | |
1042 | 1045 | // Gestionnaires (id=>name): |
1043 | 1046 | 'administrateurs' |
1044 | 1047 | )); | ... | ... |
src/Controller/UsersController.php
... | ... | @@ -174,6 +174,8 @@ class UsersController extends AppController |
174 | 174 | ]); |
175 | 175 | } |
176 | 176 | |
177 | + | |
178 | + | |
177 | 179 | /** |
178 | 180 | * Add method |
179 | 181 | * |
... | ... | @@ -217,29 +219,28 @@ class UsersController extends AppController |
217 | 219 | ]); |
218 | 220 | |
219 | 221 | // TODO: Refactoriser: idem pour add() et edit() (ainsi que leurs pendants dans MaterielsController) |
222 | + $this->setUsersLists(); | |
223 | + /* | |
220 | 224 | // On recup tous les users du LDAP (ou fakeLDAP si on n'est pas en mode LDAP) |
221 | 225 | //$users = TableRegistry::get('LdapConnections')->getListUsers(); |
222 | 226 | //sort($users); |
223 | - $users_login_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersWithNameAndEmail(); | |
227 | + $users_login_and_email = TableRegistry::getTableLocator()->get('LdapConnections')->getUsersLoginAndEmail(); | |
224 | 228 | $users_name = array_keys($users_login_and_email); |
225 | 229 | // Formatage en $users_option_list["Etienne Pallier"] = "Etienne Pallier" ... |
226 | 230 | $users_option_list = []; |
227 | 231 | for ($i = 0; $i < sizeof($users_name); $i ++) { |
228 | 232 | $users_option_list[$users_name[$i]] = $users_name[$i]; |
229 | 233 | } |
230 | - | |
231 | - | |
232 | - | |
233 | - //debug($users); | |
234 | - //debug($utilisateurs); | |
234 | + */ | |
235 | 235 | |
236 | 236 | // On passe à la vue add.ctp toutes les variables créés ci-dessus |
237 | 237 | // "user" est l'utilisateur $user créé au début, et qui est vide |
238 | - $this->set(compact('user', | |
238 | + $this->set(compact( | |
239 | + 'user', | |
239 | 240 | 'groupesMetiers', |
240 | - 'users_option_list', 'users_login_and_email', | |
241 | - 'groupesThematiques', 'sur_categorie') | |
242 | - ); | |
241 | + //'users_option_list', 'users_login_and_email', | |
242 | + 'groupesThematiques', 'sur_categorie' | |
243 | + )); | |
243 | 244 | $this->set('_serialize', [ |
244 | 245 | 'user' |
245 | 246 | ]); | ... | ... |
src/Model/Table/LdapConnectionsTable.php
... | ... | @@ -269,7 +269,7 @@ class LdapConnectionsTable extends AppTable |
269 | 269 | /** |
270 | 270 | * Return a list of Users with key = username & value = email |
271 | 271 | */ |
272 | - public function getUsersWithNameAndEmail() { | |
272 | + public function getUsersLoginAndEmail() { | |
273 | 273 | $usersWithNameAndEmail = []; |
274 | 274 | // Get all users (with ALL their attributes) |
275 | 275 | $u = $this->getAllLdapUsers(); | ... | ... |