The Higher Education and Research forge

Home My Page Projects Code Snippets Project Openings MonLabo
Summary Activity Tracker Tasks Docs SCM Files Dokuwiki Continious Integration Listes Sympa

SCM Repository

1 <?php
2 defined( 'ABSPATH' ) or die( 'No direct script access allowed' );
4 /**
5  * Class MonLabo_shortcodes_mother_class
6  * Pour être utilisée dans les classes MonLabo_shortcodes et MonLabo_shortcodes_publications
7  * @package
8  */
9 class MonLabo_shortcodes_mother_class {
11         private static function _item_of_curent_page( $get_item_id_from_wpPostId_method ) {
12                 $MonLabo_access_data = New MonLabo_access_data();
13                 $wp_post_id = get_the_ID();
14                 if ( false != $wp_post_id ) {
15                         $item_id = $MonLabo_access_data->$get_item_id_from_wpPostId_method( $wp_post_id );
16                 }
17                 if ( isset( $item_id ) ) {
18                         return $item_id;
19                 } else {
20                         //Ici on doit refaire un test avec l'url de la page
21                         $url= MonLaboLib::get_current_url_without_queries();
22                         $item_id = $MonLabo_access_data->$get_item_id_from_wpPostId_method( $url );
23                         if ( isset( $item_id ) ) {
24                                 return $item_id;
25                         } else {
26                                 return '';
27                         }
28                 }
29         }
30         //----------------------------------------------------------------
31         //On recherche une éventuelle équipe attachée à la page courrante
32         //----------------------------------------------------------------
33         protected static function _team_of_curent_page() {
34                 return self::_item_of_curent_page( 'get_team_id_from_wpPostId' );
35         }
36         //----------------------------------------------------------------
37         //On recherche une éventuelle unité attachée à la page courrante
38         //----------------------------------------------------------------
39         protected static function _unit_of_curent_page() {
40                 return self::_item_of_curent_page( 'get_unit_id_from_wpPostId' );
41         }
43         //------------------------------------------------------------------
44         //On recherche une éventuelle personne attachée à la page courrante
45         //------------------------------------------------------------------
46         protected static function _person_of_curent_page() {
47                 return self::_item_of_curent_page( 'get_person_id_from_wpPostId' );
48         }
49 }
50 /**
51  * Class MonLabo_shortcodes
52  *
53  * @package
54  */
55 class MonLabo_shortcodes extends MonLabo_shortcodes_mother_class {
57         /*
58                 _color_of_team_if_only_one_team( $teams )
59                 _filter_persons_from_belongins( &$teams, &$units, &$categories, $status = 'actif' );
61                 members_list( $atts )                            DONE
62                 members_table( $atts )                          DONE
63                 members_chart ()
65                 perso_panel ()                                          DONE    TESTED
66                 team_panel ()                                            DONE
68                 alumni_list ()                                          DONE
69                 alumni_table ()
71                 teams_list ()
72                 //team_table ()                                          POUR FUTUR EVENTUEL
73                 //thematics_list ()                                      POUR FUTUR EVENTUEL
74                 //unit_list ()                                            POUR FUTUR EVENTUEL
75                 //unit_table ()                                          POUR FUTUR EVENTUEL
77                 dev_team_name()
78                 dev_team_logo()
79         */
81         private static function _color_of_team_if_only_one_team( $teams ) {
82                 //----------------------------------------------------
83                 // S'il n'y a qu'une équipe, récupérer sa couleur
84                 //----------------------------------------------------
85                 $access_data = New MonLabo_access_data();
86                 $color = '';
87                 if ( count( $teams ) === 1 ) {
88                         $first_team_id = reset( $teams );
89                         if ( !empty( $first_team_id ) ) {
90                                 $first_team = $access_data->get_team_information( $first_team_id );
91                                 if ( !empty( $first_team ) ) {
92                                         $color = $first_team->color;
93                                 }
94                         }
95                 }
96                 return $color;
97         }
100         private static function _filter_persons_from_belongins( &$teams, &$units, &$categories, $status = 'actif' ) {
101                 //-----------------------------------------------------------------------
102                 // Si au moins une équipe est précisée, filtrer les personnes en fonction des équipes.
103                 // Sinon filtrer en fonction des unités
104                 //-----------------------------------------------------------------------
105                 //  Si teams non vide
106                 //        (ignorer units )
107                 //        filtrer en fonction de teams
108                 // sinon
109                 //        si units non vide
110                 //                filtrer en fonction de units
111                 //        sinon (i.e. teams et units sont vides)
112                 //                filtrer en fonction de toutes les équipes existantes
113                 // filtrer en fonction des catégories
115                 $access_data = New MonLabo_access_data();
116                 //---------------------------------------
117                 // 1 - Préparation des variables d'entrée
118                 //---------------------------------------
119                 $teams    = MonLaboLib::prepare_multiple_values_variable_into_array( $teams );
120                 $units    = MonLaboLib::prepare_multiple_values_variable_into_array( $units );
121                 $categories = MonLaboLib::prepare_multiple_values_variable_into_array( $categories );
123                 //-------------------------------------------
124                 // 2 - Filtrage en fonction de teams ou units
125                 //-------------------------------------------
126                 $direction_title_mode = 'directors';
127                 $MonLabo_persons = New MonLabo_persons( $access_data->get_persons_information( $status ) );
129                 //  Si teams non vide
130                 if ( !empty( $teams ) ) {
131                         // Préparation de la liste de toutes les équipes existantes
132                         $teams_informations = $access_data->get_teams_information();
133                         if ( ( is_array( $teams_informations ) ) and ( !empty($teams_informations ) ) ) {
134                                 //On ne filtre que si des équipes sont définies
135                                 $existing_teams_id = MonLaboLib::secured_array_keys( $teams_informations );
136                                 // S'il n'y a qu'une seule équipe, chercher les chefs d'équipe plutot que la direction de la structure.
137                                 if ( count( $teams ) === 1 ){ $direction_title_mode = 'team_leaders';  }
138                                 // Par défaut utiliser toutes les équipes.
139                                 if ( empty( $teams ) ) { $teams = $existing_teams_id;  }
140                                 // On enlève les équipes fantaisistes
141                                 $teams = array_intersect( $teams, $existing_teams_id );
142                                 // On filtre
143                                 $MonLabo_persons->filter_with_teams( $teams, $status );
144                         }
145                 } else {
146                         // Préparation de la liste de toutes les unités existantes
147                         $existing_units_id = array( MAIN_STRUCT_NO_UNIT=>MAIN_STRUCT_NO_UNIT ) + MonLaboLib::secured_array_keys( $access_data->get_units_name() );
149                         // si units non vide
150                         if ( !empty( $units ) ) {
151                                 // Si l'on demande que la structure principale
152                                 $id_of_units = array_values( $units );
153                                 if ( ( count( $units ) === 1 ) and ( MAIN_STRUCT_NO_UNIT === $id_of_units[0] ) ) {
154                                         // Demander toutes les unités
155                                         $units = $existing_units_id;
156                                 }
157                                 // On enlève les unités fantaisistes
158                                 $units = array_intersect( $units, $existing_units_id );
159                         } else { //$units et $teams sont vides
160                                 // Demander toutes les unités
161                                 $units = $existing_units_id;
162                         }
164                         // On filtre
165                         $MonLabo_persons->filter_with_units( $units, $status );
166                 }
168                 //---------------------------------------
169                 // 3 - Filtrage en fonction de catégories
170                 //---------------------------------------
171                 // Si vide utiliser toutes les catégories existantes (pas la peine de filtrer)
172                 if ( empty( $categories ) ) {
173                         $categories = get_MonLabo_persons_categories();
174                 // Filtrage si non vide
175                 } else {
176                         $MonLabo_persons->filter_with_categories( $categories );
177                 }
179                 return array( $MonLabo_persons, $direction_title_mode );
180         }
182         //--------------------------------------------------------------------------------
183         // Add shortcode [members_list]
184         // get list of persons from teams, labs etc...
185         //------------------------------------------------
186         // ex 1: [members_list] => get all the persons
187         // ex 2: [members_list team = '1'] => get all the persons of team 1, separate leaders
188         // ex 3: [members_list team = '1' uniquelist = 'yes'] => get all the persons of team 1
189         //                                                                                                        do not separate leaders
190         //--------------------------------------------------------------------------------
191         static function members_list( $atts ) {
192                 $a_afficher = '';
193                 $access_data = New MonLabo_access_data();
194                 $generate_HTML = New MonLabo_generate_HTML();
195                 $currentlang = get_locale();
197                 // normalize attribute keys, lowercase
198                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
200                 // Attributes
201                 $args = shortcode_atts(
202                         array(
203                                 'team' => '',
204                                 'unit' => MAIN_STRUCT_NO_UNIT, //structure mère par défaut
205                                 'uniquelist' => 'no',
206                                 'display_direction' => 'yes',
207                                 'categories' => '',
208                                 'person' => '',
209                         ),
210                         $atts,
211                         'members_list'
212                 );
214                 //Prendre des noms de variable plus adequats pour le traitement
215                 $units = sanitize_text_field( $args['unit'] );
216                 $teams = sanitize_text_field( $args['team'] );
217                 $persons = sanitize_text_field( $args['person'] );
219                 //Normalize values keys
220                 $args['categories'] = strtolower( sanitize_text_field( $args['categories'] ) );
221                 $args['display_direction'] = sanitize_key( $args['display_direction'] );
222                 $args['uniquelist'] = sanitize_key( $args['uniquelist'] );
224                 //--------------------------------------------
225                 // 1 - Sélectionner les personnes
226                 //--------------------------------------------
227                 if ( '' == $persons ) {
228                         //On recherche une éventuelle équipe ou unité attachée à la page courrante
229                         if ( ( '' === $teams ) ) { $teams = self::_team_of_curent_page(); }
230                         //On filtre les personnes
231                         list( $MonLabo_persons, $direction_title_mode )
232                                 = self::_filter_persons_from_belongins( $teams, $units, $args['categories'] );
233                 } else {
234                         $MonLabo_persons = New MonLabo_persons( $access_data->get_persons_information( 'actif' ) );
235                         $persons_ids = MonLaboLib::prepare_multiple_values_variable_into_array( $persons );
236                         $MonLabo_persons->filter_with_ids( $persons_ids );
237                         $args['uniquelist'] = 'yes';
238                 }
240                 //--------------------------------------------
241                 // 2 - Générer l'affichage
242                 //--------------------------------------------
243                 if ( 'yes' === $args['uniquelist'] ) {
244                         if ( $MonLabo_persons->count() > 0 ) {
245                                 $a_afficher .= $generate_HTML->persons_list( '', '', $MonLabo_persons->sort_by_name()->get_persons(), $currentlang );
246                         }
247                 } else {
248                         if ( 'yes' === $args['display_direction'] ) {
249                                 if ( 'team_leaders' === $direction_title_mode ) {
250                                         $MonLabo_leaders = $MonLabo_persons->extract_and_suppress_team_leaders();
251                                         if ( $MonLabo_leaders->count()  >0 ) {
252                                                 $a_afficher .= $generate_HTML->persons_list(
253                                                         MonLabo_translate::translate( 'Team leader', $currentlang ),
254                                                         MonLabo_translate::translate( 'Team leaders', $currentlang ),
255                                                         $MonLabo_leaders->sort_by_name()->get_persons(),
256                                                         $currentlang
257                                                 );
258                                         }
259                                 } else {
260                                         $MonLabo_directors = $MonLabo_persons->extract_and_suppress_direction();
261                                         if ( $MonLabo_directors->count() >0 ) {
262                                                 $a_afficher .= $generate_HTML->persons_list(
263                                                         MonLabo_translate::translate( 'Direction', $currentlang ),
264                                                         MonLabo_translate::translate( 'Direction', $currentlang ),
265                                                         $MonLabo_directors->sort_by_name()->get_persons(),
266                                                         $currentlang
267                                                 );
268                                         }
269                                 }
270                         }
271                         if ( 'team_leaders' === $direction_title_mode ) {
272                                 //On est dans une équipe, afficher tous les non leaders ensemble.
273                                 if ( $MonLabo_persons->count() >0 ) {
274                                         $a_afficher .= $generate_HTML->persons_list(
275                                                 MonLabo_translate::translate( 'Member', $currentlang ),
276                                                 MonLabo_translate::translate( 'Members', $currentlang ),
277                                                 $MonLabo_persons->sort_by_name()->get_persons(),
278                                                 $currentlang
279                                         );
280                                 }
281                         } else {
282                                 //On est dans une unité, séparer par catégories
283                                 foreach ( $args['categories'] as $key => $category ) {
284                                         $MonLabo_persons_for_one_category= New MonLabo_persons( $MonLabo_persons->get_persons() );
285                                         $MonLabo_persons_for_one_category->filter_with_categories( array( "$category" ) );
286                                         if ( $MonLabo_persons->count() >0 ) {
287                                                 $a_afficher .= $generate_HTML->persons_list(
288                                                         $category,
289                                                         $category,
290                                                         $MonLabo_persons_for_one_category->sort_by_name()->get_persons(),
291                                                         $currentlang
292                                                 );
293                                         }
294                                 }
295                         }
296                 }
297                 return $a_afficher;
298         }
300         //--------------------------------------------------------------------------------
301         // Add shortcode [members_table]
302         // get table of persons from teams, labs etc...
303         //------------------------------------------------
304         // ex 1: [members_table] => get all the persons
305         // ex 2: [members_table team = '1'] => get all the persons of team 1
306         //--------------------------------------------------------------------------------
307         static function members_table( $atts ) {
308                 $a_afficher = '';
310                 $access_data = New MonLabo_access_data();
311                 $generate_HTML = New MonLabo_generate_HTML();
312                 $currentlang = get_locale();
314                 // normalize attribute keys, lowercase
315                 $atts = array_change_key_case( (array ) $atts, CASE_LOWER );
317                 // Attributes
318                 $args = shortcode_atts(
319                                 array(
320                                 'team' => '',
321                                 'unit' => MAIN_STRUCT_NO_UNIT, //structure mère par défaut
322                                 'presentation' => 'normal',
323                                 'uniquelist' => 'no',
324                                 'display_direction' => 'yes',
325                                 'categories' => ''
326                         ),
327                         $atts,
328                         'members_table'
329                 );
330                 //Prendre des noms de variable plus adequats pour le traitement
331                 $units = sanitize_text_field( $args['unit'] );
332                 $teams = sanitize_text_field( $args['team'] );
334                 //Normalize values keys
335                 $args['categories'] = sanitize_text_field( strtolower( $args['categories'] ) );
336                 $args['display_direction'] = sanitize_key( $args['display_direction'] );
337                 $args['uniquelist'] = sanitize_key( $args['uniquelist'] );
338                 $args['presentation'] = sanitize_key( $args['presentation'] );
340                 //--------------------------------------------
341                 // 1 - Sélectionner les personnes
342                 //--------------------------------------------
344                 //On recherche une éventuelle équipe attachée à la page courrante
345                 if ( '' === $teams ) { $teams = self::_team_of_curent_page(); }
347                 list( $MonLabo_persons, $direction_title_mode ) =
348                         self::_filter_persons_from_belongins( $teams, $units, $args['categories'] );
350                 //----------------------------------------------------
351                 // 2 - S'il n'y a qu'une équipe, récupérer sa couleur
352                 //----------------------------------------------------
353                 $color = self::_color_of_team_if_only_one_team( $teams );
355                 //--------------------------------------------
356                 // 3 - Générer l'affichage
357                 //--------------------------------------------
358                 $MonLabo_directors = New MonLabo_persons();
359                 if ( ( 'yes' === $args['display_direction'] ) and ( 'yes' != $args['uniquelist'] ) ) {
360                         //Ajoute une catégorie 'direction'
361                         $MonLabo_directors = $MonLabo_persons->extract_and_suppress_direction();
362                 }
364                 if ( 'compact' === $args['presentation'] ) {
365                         $person_array = array();
366                         foreach ( $args['categories'] as $key => $category ) {
367                                 $MonLabo_persons_for_one_category = New MonLabo_persons( $MonLabo_persons->get_persons() );
368                                 $MonLabo_persons_for_one_category->filter_with_categories( array( "$category" ) );
369                                 if ( $MonLabo_directors->count() >0 ) {
370                                         $person_array['direction'] = $generate_HTML->persons_table_compact_column(
371                                                 $MonLabo_directors->sort_by_name()->get_persons(),
372                                                 MonLabo_translate::translate( 'Direction', $currentlang ),
373                                                 $currentlang,
374                                                 $color
375                                         );
376                                 }
377                                 if ( $MonLabo_persons_for_one_category->count() >0 ) {
378                                         $person_array[$category] = $generate_HTML->persons_table_compact_column(
379                                                 $MonLabo_persons_for_one_category->sort_by_name()->get_persons(),
380                                                 ucfirst( $category ),
381                                                 $currentlang,
382                                                 $color
383                                         );
384                                 }
385                         }
386                         //$person_array has to be 2 dimensions.
387                         if ( count( $person_array ) >0 ) {
388                                 $a_afficher .= $generate_HTML->generic_table( '', '', array( $person_array ), "", "", "MonLabo-persons-table-compact" );
389                         }
390                 } else {
391                         //Affichage du mode normal ( annuaire )
392                         $colum_titles = array( 'Nom', 'Equipe', 'Email', 'Tel' );
393                         if ( 'yes' != $args['uniquelist'] ) {
394                                 if ( $MonLabo_directors->count() >0 ) {
395                                         $a_afficher .=$generate_HTML->persons_table_normal(
396                                                 MonLabo_translate::translate( 'Direction', $currentlang ),
397                                                 $colum_titles,
398                                                 $MonLabo_directors->sort_by_name()->get_persons(),
399                                                 $currentlang,
400                                                 $color
401                                         );
402                                 }
403                                 foreach ( $args['categories'] as $key => $category ) {
404                                         $MonLabo_persons_for_one_category= New MonLabo_persons( $MonLabo_persons->get_persons() );
405                                         $MonLabo_persons_for_one_category->filter_with_categories( array( "$category" ) );
406                                         if ( $MonLabo_persons_for_one_category->count() >0 ) {
407                                                 $a_afficher .=$generate_HTML->persons_table_normal(
408                                                         ucfirst( $category ),
409                                                         $colum_titles,
410                                                         $MonLabo_persons_for_one_category->sort_by_name()->get_persons(),
411                                                         $currentlang,
412                                                         $color
413                                                 );
414                                         }
415                                 }
416                         } else { //$args['uniquelist'] === 'yes'
417                                 if ( $MonLabo_persons->count() >0 ) {
418                                         $a_afficher .=$generate_HTML->persons_table_normal(
419                                                 '',
420                                                 $colum_titles,
421                                                 $MonLabo_persons->sort_by_name()->get_persons(),
422                                                 $currentlang,
423                                                 $color
424                                         );
425                                 }
426                         }
427                 }
429                 return $a_afficher;
430         }
432         //--------------------------------------------------------------------------------
433         // Add shortcode [members_chart]
434         // get organizational chart of persons from teams, labs etc...
435         //------------------------------------------------
436         // ex 1: [members_chart] => get all the persons
437         //--------------------------------------------------------------------------------
438         static function members_chart( $atts ) {
439                 return self::persons_chart( $atts, 'actif' , 'members_chart' );
440         }
442         //--------------------------------------------------------------------------------
443         // Add shortcode [alumni_chart]
444         // get organizational chart of alumni from teams, labs etc...
445         //------------------------------------------------
446         // ex 1: [alumni_chart] => get all the alumni
447         //--------------------------------------------------------------------------------
448         static function alumni_chart( $atts ) {
449                 return self::persons_chart( $atts, 'alumni', 'alumni_chart' );
450         }
452         static function persons_chart( $atts, $status = 'actif', $shortcode_name = 'members_chart' ) {
453                 //TODO: Mettre en place les couleurs des équipes à partir de la version 1.00 de la base de données
454                 $a_afficher = '';
455                 $access_data = New MonLabo_access_data();
456                 $generate_HTML = New MonLabo_generate_HTML();
457                 $persons_information_by_category_and_team = array();
458                 $currentlang = get_locale();
460                 // normalize attribute keys, lowercase
461                 $atts = array_change_key_case( (array ) $atts, CASE_LOWER );
463                 // Attributes
464                 $args = shortcode_atts(
465                                 array(
466                                 'unit' => '',
467                                 'team' => '',
468                                 'display_direction' => 'yes',
469                                 'categories' => '',
470                                 'years' => '', /*Pour les alumni */
471                                 'year' => '',
472                                 'annee' => '',
473                         ),
474                         $atts,
475                         $shortcode_name
476                         );
478                 //Normalize values keys
479                 $args['categories'] = sanitize_text_field( strtolower( $args['categories'] ) );
480                 $args['display_direction'] = sanitize_key( $args['display_direction'] );
482                 //-----------------------------------------------------------------------
483                 // Tenter de déterminer le contexte. Par défaut concaténer les équipes courantes
484                 //-----------------------------------------------------------------------
485                 // Si ni unité ni équipe n'est demandée, regarder si la page en cours n'en
486                 // précise pas par défaut. Sinon, prendre toutes les unités + la structure
487                 // principale.
488                 //-----------------------------------------------------------------------
489                 //  Si units et teams sont vides
490                 //        Si unite(page en cours )  existe  ==>  units = unite(page en cours )
491                 //        Si equipe(page en cours ) existe  ==>  teams = equipe(page en cours )
492                 //        sinon
493                 //                units = { ensemble des unites}+structure principale
495                 //-----------------------------------------------------------------------
496                 // On prend la direction de la structure principale si elle est demandée
497                 // si celle ci-est vide, alors on concatène la direction de l'ensemble
498                 // des unites demandée
499                 //-----------------------------------------------------------------------
500                 //  Si teams non vide
501                 //        directeurs = vide  //Cela n'a pas de sens d'afficher des directeurs
502                 //  sinon
503                 //        Si units comprend la structure principale
504                 //                directeurs = directeurs(structure principale )
505                 //                si directeurs est vide
506                 //                        directeurs = directeurs{units}
507                 //        sinon
508                 //                directeurs = directeurs{units}
510                 //-----------------------------------------------------------------------
511                 // On prend le nom de la structure principale si elle est demandée
512                 // sinon, et s'il n'y a qu'une unité demandée, on prend son nom.
513                 //-----------------------------------------------------------------------
514                 //  Si teams non vide
515                 //        nom de la structure = vide
516                 //  sinon
517                 //        Si units comprend la structure principale
518                 //                nom de la structure = structure principale
519                 //        sinon
520                 //                nom de la structure = vide ou nom de l'unité s'il n'y en a qu'une
524                 // Prendre des noms de variable plus adequats pour le traitement
525                 $units = sanitize_text_field( $args['unit'] );
526                 $teams = sanitize_text_field( $args['team'] );
528                 // Pouvoir utiliser le paramètre years au sigulier au besoin
529                 if ( '' === $args['years'] )   { $args['years'] = $args['year'];         }
530                 // Par defaut years remplace annee sauf si years est vide
531                 if ( '' === $args['years'] )   { $args['years'] = $args['annee'];        }
532                 $args['years'] = sanitize_text_field( $args['years'] );
534                 //--------------------------------------------
535                 // 1 - Sélectionner les personnes
536                 //--------------------------------------------
537                 if ( ( '' === $teams ) and ( '' === $units ) ) {
539                         // On recherche une éventuelle équipe attachée à la page courante
540                         $teams = self::_team_of_curent_page();
541                         if ( '' === $teams ) {
542                                 $units = MAIN_STRUCT_NO_UNIT.','.MonLaboLib::secured_implode( ',', MonLaboLib::secured_array_keys( $access_data->get_units_name() ) );
543                         }
544                 }
546                 //Cela met à jour la liste des équipes, unités...
547                 list( $MonLabo_persons, $direction_title_mode ) = self::_filter_persons_from_belongins( $teams, $units, $args['categories'], $status );
549                 //--------------------------------------------
550                 // 3 - Determiner le nom de l'unité à afficher
551                 //---------------------------------------------
552                 $unit_name ='';
553                 if ( ( empty( $teams ) ) and ( in_array( MAIN_STRUCT_NO_UNIT, $units ) ) ) {
554                         $options = get_option( 'MonLabo_settings_group1' );
555                         $unit_name = $options['MonLabo_nom'].'  -  '.$options['MonLabo_code'];
556                 } elseif ( ( empty( $teams ) ) and ( count( $units ) === 1 ) ) {
557                         $unit_ids = array_values( $units );
558                         $unit_id = $unit_ids[0];
559                         $unit_information = $access_data->get_unit_information( $unit_id );
560                         $unitTextName = $access_data->get_unit_name( $unit_id, $currentlang );
561                         $unit_name = $unitTextName . '  -  ' . $unit_information->code;
562                 } else {
563                         $unit_name = '';
564                 }
566                 //--------------------------------------------
567                 // 4 - Determiner les directeurs à afficher
568                 //---------------------------------------------
569                 $directors = array();
570                 if ( 'alumni' != $status ) {
571                         if ( ( empty( $teams ) ) and ( 'yes' === $args['display_direction'] ) ) {
572                                 if ( in_array( MAIN_STRUCT_NO_UNIT, $units ) ) {
573                                         $directors = $access_data->get_directors_information_for_an_unit( MAIN_STRUCT_NO_UNIT );
574                                 }
575                                 if ( empty( $directors ) ) {
576                                         $directors = array();
577                                         if ( !empty( $units ) ) {
578                                                 foreach ( $units as $one_unit ) {
579                                                         $directors_for_one_unit = $access_data->get_directors_information_for_an_unit(
580                                                                 $one_unit
581                                                         );
582                                                         if ( empty( $directors_for_one_unit ) ) { $directors_for_one_unit = array(); }
583                                                         $directors = $directors + $directors_for_one_unit;
584                                                 }
585                                         }
586                                 }
587                         }
588                 }
589                 $MonLabo_directors = New MonLabo_persons( $directors );
591                 //--------------------------------------------
592                 // 5 - Prendre toutes les équipes des unités indiquées si aucune équipe précisée
593                 //---------------------------------------------
594                 $teams_information = array();
595                 $all_teams_information = $access_data->get_teams_information();
597                 if ( ( empty( $teams ) ) and ( !empty( $units ) ) ) {
598                         foreach ( $units as $unit_id ) {
599                                 $teams_for_unit = $access_data->get_teams_id_for_an_unit( $unit_id );
600                                 if ( NULL === $teams_for_unit ) { $teams_for_unit = Array(); }
601                                 $teams = $teams + $teams_for_unit;
602                         }
603                 }
604                 foreach ( $teams as $team_id ) {
605                         if ( array_key_exists( $team_id, $all_teams_information ) ) {
606                                 $teams_information[$team_id] = $all_teams_information[$team_id];
607                         }
608                 }
610                 //--------------------------------------------
611                 // 6 - Générer l'affichage
612                 //--------------------------------------------
613                 foreach ( $args['categories'] as $category ) {
614                         foreach ( $teams as $team_id ) {
615                                 $persons_information = $access_data->get_persons_information_for_a_category_in_a_team(
616                                         $category,
617                                         $team_id,
618                                         $status
619                                 );
620                                 $MonLabo_persons = New MonLabo_persons( $persons_information );
621                                 $MonLabo_persons->suppress_non_visible();
623                                 // Les filtrer selon la date si l'on est en mode alumni
624                                 if ( 'alumni_chart' === $shortcode_name ) {
625                                         if ( !empty( $args['years'] ) ) {
626                                                 if ( !empty( $persons_information ) ) {
627                                                         $MonLabo_persons->filter_with_alumni_years( $args['years'] );
628                                                 }
629                                         }
630                                 }
631                                 $persons_information = $MonLabo_persons->get_persons();
632                                 $team_leaders_id = $access_data->get_leaders_id_for_a_team( $team_id );
634                                 // On tague les leaders de chaque équipe
635                                 if ( !empty( $persons_information ) ) {
636                                         foreach ( $persons_information as $id => $person ) {
637                                                 $person = (array) $person;
638                                                 if ( ( !empty( $team_leaders_id ) ) and ( in_array( $id, $team_leaders_id) ) ) {
639                                                         $person['leader'] = true;
640                                                 } else {
641                                                         $person['leader'] = false;
642                                                 }
643                                                 $persons_information[$id] = (object ) $person;
644                                         }
645                                         $persons_information_by_category_and_team[$category][$team_id] = $persons_information;
646                                 }
647                         }
649                 }
650                 $a_afficher .= $generate_HTML->persons_chart(
651                         $unit_name,
652                         $MonLabo_directors->get_persons(),
653                         $teams_information,
654                         $persons_information_by_category_and_team,
655                         $currentlang
656                 );
658                 return $a_afficher;
659         }
661         //--------------------------------------------------------------------------------
662         // Add shortcode [perso_panel]
663         // Generate the personnal panel of the user belonging to the current page
664         // Ex: [perso_panel] => Only way to use ( no parameters )
665         //--------------------------------------------------------------------------------
666         static function perso_panel( $atts ) {
667                 $generate_HTML = New MonLabo_generate_HTML();
668                 $access_data = New MonLabo_access_data();
670                 // normalize attribute keys, lowercase
671                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
672                 // Attributes
673                 $args = shortcode_atts(
674                         array(
675                                 'person' => '',
676                         ),
677                         $atts,
678                         'perso_panel'
679                 );
680                 if ( '' == $args['person'] ) {
681                         $person_id = self::_person_of_curent_page();;
682                 } else {
683                         $person_id = intval( $args['person'] );
684                 }
686                 //var_dump( $person_id );
687                 if ( !empty( $person_id ) ) {
688                         $person_information = $access_data->get_person_information( $person_id );
689                         if ( !empty( $person_information ) ) {
690                                 $mentors_information= $access_data->get_mentors_information_for_a_person( $person_id );
691                                 $students_information = $access_data->get_students_information_for_a_person( $person_id );
692                                 $currentlang = get_locale( );
693                                 return $generate_HTML->person_panel(
694                                         $person_information,
695                                         $mentors_information,
696                                         $students_information,
697                                         $currentlang
698                                 );
699                         }
700                 }
701                 return '';
702         }
704         //--------------------------------------------------------------------------------
705         // Add shortcode [team_panel]
706         // Generate the team panel of the team belonging to the current page
707         // Ex: [team_panel] => Only way to use (no parameters)
708         //--------------------------------------------------------------------------------
709         static function team_panel( $atts ) {
710                 $generate_HTML = New MonLabo_generate_HTML();
711                 $access_data = New MonLabo_access_data();
713                 // normalize attribute keys, lowercase
714                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
716                 // Attributes
717                 $args = shortcode_atts(
718                         array(
719                                 'team' => '',
720                         ),
721                         $atts,
722                         'team_panel'
723                 );
725                 if ( '' == $args['team'] ) {
726                         $team_id = self::_team_of_curent_page();;
727                 } else {
728                         $team_id = intval( $args['team'] );
729                 }
731                 if ( !empty( $team_id ) ) {
732                         $team_information = $access_data->get_team_information( $team_id );
733                         if ( !empty( $team_information ) ) {
734                                 $leaders_information = $access_data->get_leaders_information_for_a_team( $team_id );
735                                 $currentlang = get_locale();
736                                 $thematics_name = $access_data->get_thematics_name_for_a_team( $team_id, $currentlang );
737                                 return $generate_HTML->team_panel(
738                                         $team_information,
739                                         $leaders_information,
740                                         $thematics_name,
741                                         $currentlang
742                                 );
743                         }
744                 }
745                 return '';
746         }
748         //--------------------------------------------------------------------------------
749         // Add shortcode [alumni_list]
750         // get list of old members from teams, labs etc...
751         //------------------------------------------------
752         // ex : [alumni_list title = 'Former PhDs and Postdocs' categories = 'postdocs,students'] => get all the alumni was PhD or PostDoct Members and print with title caption
753         //--------------------------------------------------------------------------------
754         static function alumni_list( $atts ) {
755                 $a_afficher = '';
756                 $generate_HTML = New MonLabo_generate_HTML();
757                 $currentlang = get_locale();
759                 // normalize attribute keys, lowercase
760                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
761                 // Attributes
762                 $args = shortcode_atts(
763                         array(
764                                 'team' => '',
765                                 'unit' => MAIN_STRUCT_NO_UNIT, //structure mère par défaut
766                                 'title' => '',
767                                 'categories' => '',
768                                 'years' => '',
769                                 'year' => '',
770                                 'annee' => '',
771                                 'external_link_title' => '',
772                         ),
773                         $atts,
774                         'alumni_list'
775                 );
776                 //Prendre des noms de variable plus adequats pour le traitement
777                 $units = sanitize_text_field( $args['unit'] );
778                 $teams = sanitize_text_field( $args['team'] );
780                 // Pouvoir utiliser le paramètre years au sigulier au besoin
781                 if ( '' === $args['years'] )   { $args['years'] = $args['year'];         }
782                 // Par defaut years remplace annee sauf si years est vide
783                 if ( '' === $args['years'] )   { $args['years'] = $args['annee'];        }
784                 $args['years'] = sanitize_text_field( $args['years'] );
786                 // Normalize values keys
787                 $args['categories'] = strtolower( sanitize_text_field( $args['categories'] ) );
788                 $args['title'] = sanitize_text_field( $args['title'] );
789                 $args['external_link_title'] = esc_url( $args['external_link_title'] );
791                 //--------------------------------------------
792                 // 1 - Sélectionner les personnes
793                 //--------------------------------------------
794                 // On recherche une éventuelle équipe attachée à la page courrante
795                 if ( '' === $teams ) { $teams = self::_team_of_curent_page(); }
797                 list( $MonLabo_persons, $dummy ) = self::_filter_persons_from_belongins(
798                         $teams,
799                         $units,
800                         $args['categories'],
801                         'alumni'
802                 );
804                 //--------------------------------------------
805                 // 2 - Les filtrer selon la date
806                 //--------------------------------------------
807                 if ( !empty( $args['years'] ) ) {
808                         $MonLabo_persons->filter_with_alumni_years( $args['years'] );
809                 }
811                 //--------------------------------------------
812                 // 3 - Générer l'affichage
813                 //--------------------------------------------
814                 if ( $MonLabo_persons->count() >0 ) {
815                         //2 - Lance l'affichage
816                         $MonLabo_persons->sort_by_name();
817                         $a_afficher .= $generate_HTML->persons_list(
818                                 $args['title'],
819                                 $args['title'],
820                                 $MonLabo_persons->get_persons(),
821                                 $currentlang
822                         );
823                 }
824                 return $a_afficher;
825         }
827         //--------------------------------------------------------------------------------
828         // Add shortcode [alumni_table]
829         // get list of old members from teams, labs etc...
830         //------------------------------------------------
831         // ex: [alumni_table title = 'Former PhDs and Postdocs' categories = 'postdocs,students'] => get all the alumni was PhD or PostDoct Members and print with title caption
832         //--------------------------------------------------------------------------------
833         static function alumni_table( $atts ) {
834                 $a_afficher = '';
835                 $access_data = New MonLabo_access_data();
836                 $generate_HTML = New MonLabo_generate_HTML();
837                 $currentlang = get_locale();
839                 // normalize attribute keys, lowercase
840                 $atts = array_change_key_case( ( array) $atts, CASE_LOWER );
842                 // Attributes
843                 $args = shortcode_atts(
844                         array(
845                                 'team' => '',
846                                 'unit' => MAIN_STRUCT_NO_UNIT, //structure mère par défaut
847                                 'title' => '',
848                                 'categories' => '',
849                                 'years' => '',
850                                 'year' => '',
851                                 'annee' => '',
852                         ),
853                         $atts,
854                         'alumni_table'
855                 );
857                 // Prendre des noms de variable plus adequats pour le traitement
858                 $units = sanitize_text_field( $args['unit'] );
859                 $teams = sanitize_text_field( $args['team'] );
861                 // Pouvoir utiliser le paramètre years au sigulier au besoin
862                 if ( '' === $args['years'] )   { $args['years'] = $args['year'];          }
863                 //Par defaut years remplace annee sauf si years est vide
864                 if ( '' === $args['years'] )   { $args['years'] = $args['annee'];        }
865                 $args['years'] = sanitize_text_field( $args['years'] );
867                 // Normalize values keys
868                 $args['categories'] = sanitize_text_field( strtolower( $args['categories'] ) );
870                 //--------------------------------------------
871                 // 1 - Sélectionner les personnes
872                 //--------------------------------------------
873                 // On recherche une éventuelle équipe attachée à la page courrante
874                 if ( '' === $teams ) { $teams = self::_team_of_curent_page(); }
876                 list( $MonLabo_persons, $dummy ) = self::_filter_persons_from_belongins(
877                         $teams,
878                         $units,
879                         $args['categories'],
880                         'alumni'
881                 );
883                 //--------------------------------------------
884                 // 2 - Les filtrer selon la date
885                 //--------------------------------------------
886                 if ( !empty( $args['years'] ) ) {
887                         $MonLabo_persons->filter_with_alumni_years( $args['years'] );
888                 }
890                 //----------------------------------------------------
891                 // 3 - S'il n'y a qu'une équipe, récupérer sa couleur
892                 //----------------------------------------------------
893                 $color = self::_color_of_team_if_only_one_team( $teams );
895                 //--------------------------------------------
896                 // 4 - Générer l'affichage
897                 //--------------------------------------------
898                 //Affichage du mode normal ( annuaire )
899                 $colum_titles = array( 'Nom', 'Equipe', 'Email', 'Tel' );
900                 if ( $MonLabo_persons->count() >0 ) {
901                         $a_afficher .=$generate_HTML->persons_table_normal(
902                                 $args['title'],
903                                 $colum_titles,
904                                 $MonLabo_persons->sort_by_name()->get_persons(),
905                                 $currentlang,
906                                 $color,
907                                 'alumni'
908                         );
909                 }
910                 return $a_afficher;
911         }
913         //--------------------------------------------------------------------------------
914         // Add shortcode [teams_list]
915         // get list of teams
916         //------------------------------------------------
917         // ex: [teams_list thematic = "3"] => Get the list of teams for thematics 3
918         //--------------------------------------------------------------------------------
919         static function teams_list( $atts ) {
920                 $a_afficher = "";
921                 $access_data = New MonLabo_access_data();
922                 $generate_HTML = New MonLabo_generate_HTML();
923                 $currentlang = get_locale();
925                 // normalize attribute keys, lowercase
926                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
928                 // Attributes
929                 $args = shortcode_atts(
930                         array(
931                                 'thematic' => "",
932                                 'unit' => "",
933                                 'group' => "",
934                                 'teams_publications_page' => ""
935                         ),
936                         $atts,
937                         'teams_list'
938                 );
940                 $args['unit'] = sanitize_text_field( $args['unit'] );
941                 $args['thematic'] = sanitize_text_field( $args['thematic'] );
942                 $args['group'] = sanitize_text_field( $args['group'] );
943                 $args['teams_publications_page'] = esc_url( $args['teams_publications_page'] );
946                 if ( !( '' === $args['thematic'] ) ) {
947                         $args['group'] = $args['thematic'];
948                 }
949                 if ( !( '' === $args['group'] ) ) {
950                         $teams_information = $access_data->get_teams_information_for_a_thematic( $args['group'] );
951                 } else {
952                         $teams_information = $access_data->get_teams_information();
953                 }
954                 $groups_information = array();
955                 $teams_leaders = array();
956                 if ( is_array( $teams_information ) ) {
957                         foreach ( $teams_information as $key=>$team_information ) {
958                                 $groups_information[$team_information->id] = $access_data->get_thematics_information_for_a_team( $team_information->id );
959                                 $teams_leaders[$team_information->id] = $access_data->get_leaders_name_for_a_team( $team_information->id );
961                                 //Si pas de logo définit, utiliser celui de l'unité
962                                 if ( empty( $team_information->logo ) ) {
963                                         if ( isset( $team_information->id_unit ) ) {
964                                                 $unit_information = $access_data->get_unit_information( $team_information->id_unit );
965                                                 if ( ( !empty( $unit_information ) ) and ( isset( $unit_information->logo ) ) ) {
966                                                         $teams_information[$key]->logo = $unit_information->logo;
967                                                 }
968                                         }
969                                 }
970                         }
971                 }
972                 $a_afficher .= $generate_HTML->teams_list(
973                         $args['group'],
974                         $teams_information,
975                         $teams_leaders,
976                         $groups_information,
977                         $args['teams_publications_page'],
978                         $currentlang
979                 );
981                 return $a_afficher;
982         }
984         //--------------------------------------------------------------------------------
985         // Add shortcode [dev_team_name]
986         // get team name from Descartes Pubbmed id for developpers...
987         // This function is not public and documented, only for developping purpose
988         //------------------------------------------------
989         // ex 1: [dev_team_name descartes_publi_team_id = "3"] => get the english name of team 3
990         //--------------------------------------------------------------------------------
991         static function dev_team_name( $atts ) {
993                 // normalize attribute keys, lowercase
994                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
996                 // Attributes
997                 $args = shortcode_atts(
998                                 array(
999                                 'descartes_publi_team_id' => '',
1000                         ),
1001                         $atts,
1002                         'dev_team_name'
1003                 );
1005                 $args['descartes_publi_team_id'] = sanitize_text_field( $args['descartes_publi_team_id'] );
1007                 global $wpdb;
1008                 $team = $wpdb->get_results(
1009                         $wpdb->prepare( "SELECT `name_en` FROM MonLabo_teams  WHERE `descartes_publi_team_id` = %s", $args['descartes_publi_team_id']),
1010                         ARRAY_A
1011                 );
1012                 if ( ( isset( $team[0] ) ) and isset( $team[0]["name_en"] ) ) {
1013                         return $team[0]["name_en"];
1014                 }
1015                 return "";
1016         }
1017         //--------------------------------------------------------------------------------
1018         // Add shortcode [dev_team_logo]
1019         // get team logo from Descartes Pubbmed id for developpers...
1020         // This function is not public and documented, only for developping purpose
1021         //------------------------------------------------
1022         // ex 1: [dev_team_logo descartes_publi_team_id = "3"] => get the logo of team 3
1023         //--------------------------------------------------------------------------------
1024         static function dev_team_logo( $atts ) {
1026                 // normalize attribute keys, lowercase
1027                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
1029                 // Attributes
1030                 $args = shortcode_atts(
1031                                 array(
1032                                 'descartes_publi_team_id' => '',
1033                         ),
1034                         $atts,
1035                         'dev_team_logo'
1036                 );
1038                 $args['descartes_publi_team_id'] = sanitize_text_field( $args['descartes_publi_team_id'] );
1040                 global $wpdb;
1041                 $team = $wpdb->get_results(
1042                         $wpdb->prepare( "SELECT `logo` FROM MonLabo_teams  WHERE `descartes_publi_team_id` = %s", $args['descartes_publi_team_id']),
1043                         ARRAY_A
1044                 );
1045                 if ( ( isset( $team[0] ) ) and isset( $team[0]["logo"] ) ) {
1046                         return $team[0]["logo"];
1047                 }
1048                 return "";
1049         }