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

71b064af0e8ca30ec7b29b773c340a5e8c1b07b3
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                         $units_name = $access_data->get_units_name();
148                         $existing_units_id = array( MAIN_STRUCT_NO_UNIT=>MAIN_STRUCT_NO_UNIT ) + MonLaboLib::secured_array_keys( $access_data->get_units_name() );
150                         // si units non vide
151                         if ( !empty( $units ) ) {
152                                 // Si l'on demande que la structure principale
153                                 $id_of_units = array_values( $units );
154                                 if ( ( count( $units ) === 1 ) and ( MAIN_STRUCT_NO_UNIT === $id_of_units[0] ) ) {
155                                         // Demander toutes les unités
156                                         $units = $existing_units_id;
157                                 }
158                                 // On enlève les unités fantaisistes
159                                 $units = array_intersect( $units, $existing_units_id );
160                         } else { //$units et $teams sont vides
161                                 // Demander toutes les unités
162                                 $units = $existing_units_id;
163                         }
165                         // On filtre
166                         $MonLabo_persons->filter_with_units( $units, $status );
167                 }
169                 //---------------------------------------
170                 // 3 - Filtrage en fonction de catégories
171                 //---------------------------------------
172                 // Si vide utiliser toutes les catégories existantes (pas la peine de filtrer)
173                 if ( empty( $categories ) ) {
174                         $categories = get_MonLabo_persons_categories();
175                 // Filtrage si non vide
176                 } else {
177                         $MonLabo_persons->filter_with_categories( $categories );
178                 }
180                 return array( $MonLabo_persons, $direction_title_mode );
181         }
183         //--------------------------------------------------------------------------------
184         // Add shortcode [members_list]
185         // get list of persons from teams, labs etc...
186         //------------------------------------------------
187         // ex 1: [members_list] => get all the persons
188         // ex 2: [members_list team = '1'] => get all the persons of team 1, separate leaders
189         // ex 3: [members_list team = '1' uniquelist = 'yes'] => get all the persons of team 1
190         //                                                                                                        do not separate leaders
191         //--------------------------------------------------------------------------------
192         static function members_list( $atts ) {
193                 $a_afficher = '';
194                 $access_data = New MonLabo_access_data();
195                 $generate_HTML = New MonLabo_generate_HTML();
196                 $currentlang = get_locale();
198                 // normalize attribute keys, lowercase
199                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
201                 // Attributes
202                 $args = shortcode_atts(
203                         array(
204                                 'team' => '',
205                                 'unit' => MAIN_STRUCT_NO_UNIT, //structure mère par défaut
206                                 'uniquelist' => 'no',
207                                 'display_direction' => 'yes',
208                                 'categories' => '',
209                                 'person' => '',
210                         ),
211                         $atts,
212                         'members_list'
213                 );
215                 //Prendre des noms de variable plus adequats pour le traitement
216                 $units = sanitize_text_field( $args['unit'] );
217                 $teams = sanitize_text_field( $args['team'] );
218                 $persons = sanitize_text_field( $args['person'] );
220                 //Normalize values keys
221                 $args['categories'] = strtolower( sanitize_text_field( $args['categories'] ) );
222                 $args['display_direction'] = sanitize_key( $args['display_direction'] );
223                 $args['uniquelist'] = sanitize_key( $args['uniquelist'] );
225                 //--------------------------------------------
226                 // 1 - Sélectionner les personnes
227                 //--------------------------------------------
228                 if ( '' == $persons ) {
229                         //On recherche une éventuelle équipe ou unité attachée à la page courrante
230                         if ( ( '' === $teams ) ) { $teams = self::_team_of_curent_page(); }
231                         //On filtre les personnes
232                         list( $MonLabo_persons, $direction_title_mode )
233                                 = self::_filter_persons_from_belongins( $teams, $units, $args['categories'] );
234                 } else {
235                         $MonLabo_persons = New MonLabo_persons( $access_data->get_persons_information( 'actif' ) );
236                         $persons_ids = MonLaboLib::prepare_multiple_values_variable_into_array( $persons );
237                         $MonLabo_persons->filter_with_ids( $persons_ids );
238                         $args['uniquelist'] = 'yes';
239                 }
241                 //--------------------------------------------
242                 // 2 - Générer l'affichage
243                 //--------------------------------------------
244                 if ( 'yes' === $args['uniquelist'] ) {
245                         if ( $MonLabo_persons->count() > 0 ) {
246                                 $a_afficher .= $generate_HTML->persons_list( '', '', $MonLabo_persons->sort_by_name()->get_persons(), $currentlang );
247                         }
248                 } else {
249                         if ( 'yes' === $args['display_direction'] ) {
250                                 if ( 'team_leaders' === $direction_title_mode ) {
251                                         $MonLabo_leaders = $MonLabo_persons->extract_and_suppress_team_leaders();
252                                         if ( $MonLabo_leaders->count()  >0 ) {
253                                                 $a_afficher .= $generate_HTML->persons_list(
254                                                         MonLabo_translate::translate( 'Team leader', $currentlang ),
255                                                         MonLabo_translate::translate( 'Team leaders', $currentlang ),
256                                                         $MonLabo_leaders->sort_by_name()->get_persons(),
257                                                         $currentlang
258                                                 );
259                                         }
260                                 } else {
261                                         $MonLabo_directors = $MonLabo_persons->extract_and_suppress_direction();
262                                         if ( $MonLabo_directors->count() >0 ) {
263                                                 $a_afficher .= $generate_HTML->persons_list(
264                                                         MonLabo_translate::translate( 'Direction', $currentlang ),
265                                                         MonLabo_translate::translate( 'Direction', $currentlang ),
266                                                         $MonLabo_directors->sort_by_name()->get_persons(),
267                                                         $currentlang
268                                                 );
269                                         }
270                                 }
271                         }
272                         if ( 'team_leaders' === $direction_title_mode ) {
273                                 //On est dans une équipe, afficher tous les non leaders ensemble.
274                                 if ( $MonLabo_persons->count() >0 ) {
275                                         $a_afficher .= $generate_HTML->persons_list(
276                                                 MonLabo_translate::translate( 'Member', $currentlang ),
277                                                 MonLabo_translate::translate( 'Members', $currentlang ),
278                                                 $MonLabo_persons->sort_by_name()->get_persons(),
279                                                 $currentlang
280                                         );
281                                 }
282                         } else {
283                                 //On est dans une unité, séparer par catégories
284                                 foreach ( $args['categories'] as $key => $category ) {
285                                         $MonLabo_persons_for_one_category= New MonLabo_persons( $MonLabo_persons->get_persons() );
286                                         $MonLabo_persons_for_one_category->filter_with_categories( array( "$category" ) );
287                                         if ( $MonLabo_persons->count() >0 ) {
288                                                 $a_afficher .= $generate_HTML->persons_list(
289                                                         $category,
290                                                         $category,
291                                                         $MonLabo_persons_for_one_category->sort_by_name()->get_persons(),
292                                                         $currentlang
293                                                 );
294                                         }
295                                 }
296                         }
297                 }
298                 return $a_afficher;
299         }
301         //--------------------------------------------------------------------------------
302         // Add shortcode [members_table]
303         // get table of persons from teams, labs etc...
304         //------------------------------------------------
305         // ex 1: [members_table] => get all the persons
306         // ex 2: [members_table team = '1'] => get all the persons of team 1
307         //--------------------------------------------------------------------------------
308         static function members_table( $atts ) {
309                 $a_afficher = '';
311                 $access_data = New MonLabo_access_data();
312                 $generate_HTML = New MonLabo_generate_HTML();
313                 $currentlang = get_locale();
315                 // normalize attribute keys, lowercase
316                 $atts = array_change_key_case( (array ) $atts, CASE_LOWER );
318                 // Attributes
319                 $args = shortcode_atts(
320                                 array(
321                                 'team' => '',
322                                 'unit' => MAIN_STRUCT_NO_UNIT, //structure mère par défaut
323                                 'presentation' => 'normal',
324                                 'uniquelist' => 'no',
325                                 'display_direction' => 'yes',
326                                 'categories' => ''
327                         ),
328                         $atts,
329                         'members_table'
330                 );
331                 //Prendre des noms de variable plus adequats pour le traitement
332                 $units = sanitize_text_field( $args['unit'] );
333                 $teams = sanitize_text_field( $args['team'] );
335                 //Normalize values keys
336                 $args['categories'] = sanitize_text_field( strtolower( $args['categories'] ) );
337                 $args['display_direction'] = sanitize_key( $args['display_direction'] );
338                 $args['uniquelist'] = sanitize_key( $args['uniquelist'] );
339                 $args['presentation'] = sanitize_key( $args['presentation'] );
341                 //--------------------------------------------
342                 // 1 - Sélectionner les personnes
343                 //--------------------------------------------
345                 //On recherche une éventuelle équipe attachée à la page courrante
346                 if ( '' === $teams ) { $teams = self::_team_of_curent_page(); }
348                 list( $MonLabo_persons, $direction_title_mode ) =
349                         self::_filter_persons_from_belongins( $teams, $units, $args['categories'] );
351                 //----------------------------------------------------
352                 // 2 - S'il n'y a qu'une équipe, récupérer sa couleur
353                 //----------------------------------------------------
354                 $color = self::_color_of_team_if_only_one_team( $teams );
356                 //--------------------------------------------
357                 // 3 - Générer l'affichage
358                 //--------------------------------------------
359                 $MonLabo_directors = New MonLabo_persons();
360                 if ( ( 'yes' === $args['display_direction'] ) and ( 'yes' != $args['uniquelist'] ) ) {
361                         //Ajoute une catégorie 'direction'
362                         $MonLabo_directors = $MonLabo_persons->extract_and_suppress_direction();
363                 }
365                 if ( 'compact' === $args['presentation'] ) {
366                         $person_array = array();
367                         foreach ( $args['categories'] as $key => $category ) {
368                                 $MonLabo_persons_for_one_category = New MonLabo_persons( $MonLabo_persons->get_persons() );
369                                 $MonLabo_persons_for_one_category->filter_with_categories( array( "$category" ) );
370                                 if ( $MonLabo_directors->count() >0 ) {
371                                         $person_array['direction'] = $generate_HTML->persons_table_compact_column(
372                                                 $MonLabo_directors->sort_by_name()->get_persons(),
373                                                 MonLabo_translate::translate( 'Direction', $currentlang ),
374                                                 $currentlang,
375                                                 $color
376                                         );
377                                 }
378                                 if ( $MonLabo_persons_for_one_category->count() >0 ) {
379                                         $person_array[$category] = $generate_HTML->persons_table_compact_column(
380                                                 $MonLabo_persons_for_one_category->sort_by_name()->get_persons(),
381                                                 ucfirst( $category ),
382                                                 $currentlang,
383                                                 $color
384                                         );
385                                 }
386                         }
387                         //$person_array has to be 2 dimensions.
388                         if ( count( $person_array ) >0 ) {
389                                 $a_afficher .= $generate_HTML->generic_table( '', '', array( $person_array ), "", "", "MonLabo-persons-table-compact" );
390                         }
391                 } else {
392                         //Affichage du mode normal ( annuaire )
393                         $colum_titles = array( 'Nom', 'Equipe', 'Email', 'Tel' );
394                         if ( 'yes' != $args['uniquelist'] ) {
395                                 if ( $MonLabo_directors->count() >0 ) {
396                                         $a_afficher .=$generate_HTML->persons_table_normal(
397                                                 MonLabo_translate::translate( 'Direction', $currentlang ),
398                                                 $colum_titles,
399                                                 $MonLabo_directors->sort_by_name()->get_persons(),
400                                                 $currentlang,
401                                                 $color
402                                         );
403                                 }
404                                 foreach ( $args['categories'] as $key => $category ) {
405                                         $MonLabo_persons_for_one_category= New MonLabo_persons( $MonLabo_persons->get_persons() );
406                                         $MonLabo_persons_for_one_category->filter_with_categories( array( "$category" ) );
407                                         if ( $MonLabo_persons_for_one_category->count() >0 ) {
408                                                 $a_afficher .=$generate_HTML->persons_table_normal(
409                                                         ucfirst( $category ),
410                                                         $colum_titles,
411                                                         $MonLabo_persons_for_one_category->sort_by_name()->get_persons(),
412                                                         $currentlang,
413                                                         $color
414                                                 );
415                                         }
416                                 }
417                         } else { //$args['uniquelist'] === 'yes'
418                                 if ( $MonLabo_persons->count() >0 ) {
419                                         $a_afficher .=$generate_HTML->persons_table_normal(
420                                                 '',
421                                                 $colum_titles,
422                                                 $MonLabo_persons->sort_by_name()->get_persons(),
423                                                 $currentlang,
424                                                 $color
425                                         );
426                                 }
427                         }
428                 }
430                 return $a_afficher;
431         }
433         //--------------------------------------------------------------------------------
434         // Add shortcode [members_chart]
435         // get organizational chart of persons from teams, labs etc...
436         //------------------------------------------------
437         // ex 1: [members_chart] => get all the persons
438         //--------------------------------------------------------------------------------
439         static function members_chart( $atts ) {
440                 return self::persons_chart( $atts, 'actif' , 'members_chart' );
441         }
443         //--------------------------------------------------------------------------------
444         // Add shortcode [alumni_chart]
445         // get organizational chart of alumni from teams, labs etc...
446         //------------------------------------------------
447         // ex 1: [alumni_chart] => get all the alumni
448         //--------------------------------------------------------------------------------
449         static function alumni_chart( $atts ) {
450                 return self::persons_chart( $atts, 'alumni', 'alumni_chart' );
451         }
453         static function persons_chart( $atts, $status = 'actif', $shortcode_name = 'members_chart' ) {
454                 //TODO: Mettre en place les couleurs des équipes à partir de la version 1.00 de la base de données
455                 $a_afficher = '';
456                 $access_data = New MonLabo_access_data();
457                 $generate_HTML = New MonLabo_generate_HTML();
458                 $persons_information_by_category_and_team = array();
459                 $currentlang = get_locale();
461                 // normalize attribute keys, lowercase
462                 $atts = array_change_key_case( (array ) $atts, CASE_LOWER );
464                 // Attributes
465                 $args = shortcode_atts(
466                                 array(
467                                 'unit' => '',
468                                 'team' => '',
469                                 'display_direction' => 'yes',
470                                 'categories' => '',
471                                 'years' => '', /*Pour les alumni */
472                                 'year' => '',
473                                 'annee' => '',
474                         ),
475                         $atts,
476                         $shortcode_name
477                         );
479                 //Normalize values keys
480                 $args['categories'] = sanitize_text_field( strtolower( $args['categories'] ) );
481                 $args['display_direction'] = sanitize_key( $args['display_direction'] );
483                 //-----------------------------------------------------------------------
484                 // Tenter de déterminer le contexte. Par défaut concaténer les équipes courantes
485                 //-----------------------------------------------------------------------
486                 // Si ni unité ni équipe n'est demandée, regarder si la page en cours n'en
487                 // précise pas par défaut. Sinon, prendre toutes les unités + la structure
488                 // principale.
489                 //-----------------------------------------------------------------------
490                 //  Si units et teams sont vides
491                 //        Si unite(page en cours )  existe  ==>  units = unite(page en cours )
492                 //        Si equipe(page en cours ) existe  ==>  teams = equipe(page en cours )
493                 //        sinon
494                 //                units = { ensemble des unites}+structure principale
496                 //-----------------------------------------------------------------------
497                 // On prend la direction de la structure principale si elle est demandée
498                 // si celle ci-est vide, alors on concatène la direction de l'ensemble
499                 // des unites demandée
500                 //-----------------------------------------------------------------------
501                 //  Si teams non vide
502                 //        directeurs = vide  //Cela n'a pas de sens d'afficher des directeurs
503                 //  sinon
504                 //        Si units comprend la structure principale
505                 //                directeurs = directeurs(structure principale )
506                 //                si directeurs est vide
507                 //                        directeurs = directeurs{units}
508                 //        sinon
509                 //                directeurs = directeurs{units}
511                 //-----------------------------------------------------------------------
512                 // On prend le nom de la structure principale si elle est demandée
513                 // sinon, et s'il n'y a qu'une unité demandée, on prend son nom.
514                 //-----------------------------------------------------------------------
515                 //  Si teams non vide
516                 //        nom de la structure = vide
517                 //  sinon
518                 //        Si units comprend la structure principale
519                 //                nom de la structure = structure principale
520                 //        sinon
521                 //                nom de la structure = vide ou nom de l'unité s'il n'y en a qu'une
525                 // Prendre des noms de variable plus adequats pour le traitement
526                 $units = sanitize_text_field( $args['unit'] );
527                 $teams = sanitize_text_field( $args['team'] );
529                 // Pouvoir utiliser le paramètre years au sigulier au besoin
530                 if ( '' === $args['years'] )   { $args['years'] = $args['year'];         }
531                 // Par defaut years remplace annee sauf si years est vide
532                 if ( '' === $args['years'] )   { $args['years'] = $args['annee'];        }
533                 $args['years'] = sanitize_text_field( $args['years'] );
535                 //--------------------------------------------
536                 // 1 - Sélectionner les personnes
537                 //--------------------------------------------
538                 if ( ( '' === $teams ) and ( '' === $units ) ) {
540                         // On recherche une éventuelle équipe attachée à la page courante
541                         $teams = self::_team_of_curent_page();
542                         if ( '' === $teams ) {
543                                 $units_name = $access_data->get_units_name();
544                                 $units = MAIN_STRUCT_NO_UNIT.','.MonLaboLib::secured_implode( ',', MonLaboLib::secured_array_keys( $access_data->get_units_name() ) );
545                         }
546                 }
548                 //Cela met à jour la liste des équipes, unités...
549                 list( $MonLabo_persons, $direction_title_mode ) = self::_filter_persons_from_belongins( $teams, $units, $args['categories'], $status );
551                 //--------------------------------------------
552                 // 3 - Determiner le nom de l'unité à afficher
553                 //---------------------------------------------
554                 $unit_name ='';
555                 if ( ( empty( $teams ) ) and ( in_array( MAIN_STRUCT_NO_UNIT, $units ) ) ) {
556                         $options = get_option( 'MonLabo_settings_group1' );
557                         $unit_name = $options['MonLabo_nom'].'  -  '.$options['MonLabo_code'];
558                 } elseif ( ( empty( $teams ) ) and ( count( $units ) === 1 ) ) {
559                         $unit_ids = array_values( $units );
560                         $unit_id = $unit_ids[0];
561                         $unit_information = $access_data->get_unit_information( $unit_id );
562                         $unitTextName = $access_data->get_unit_name( $unit_id, $currentlang );
563                         $unit_name = $unitTextName . '  -  ' . $unit_information->code;
564                 } else {
565                         $unit_name = '';
566                 }
568                 //--------------------------------------------
569                 // 4 - Determiner les directeurs à afficher
570                 //---------------------------------------------
571                 $directors = array();
572                 if ( 'alumni' != $status ) {
573                         if ( ( empty( $teams ) ) and ( 'yes' === $args['display_direction'] ) ) {
574                                 if ( in_array( MAIN_STRUCT_NO_UNIT, $units ) ) {
575                                         $directors = $access_data->get_directors_information_for_an_unit( MAIN_STRUCT_NO_UNIT );
576                                 }
577                                 if ( empty( $directors ) ) {
578                                         $directors = array();
579                                         if ( !empty( $units ) ) {
580                                                 foreach ( $units as $one_unit ) {
581                                                         $directors_for_one_unit = $access_data->get_directors_information_for_an_unit(
582                                                                 $one_unit
583                                                         );
584                                                         if ( empty( $directors_for_one_unit ) ) { $directors_for_one_unit = array(); }
585                                                         $directors = $directors + $directors_for_one_unit;
586                                                 }
587                                         }
588                                 }
589                         }
590                 }
591                 $MonLabo_directors = New MonLabo_persons( $directors );
593                 //--------------------------------------------
594                 // 5 - Prendre toutes les équipes des unités indiquées si aucune équipe précisée
595                 //---------------------------------------------
596                 $teams_information = array();
597                 $all_teams_information = $access_data->get_teams_information();
599                 if ( ( empty( $teams ) ) and ( !empty( $units ) ) ) {
600                         foreach ( $units as $unit_id ) {
601                                 $teams_for_unit = $access_data->get_teams_id_for_an_unit( $unit_id );
602                                 if ( NULL === $teams_for_unit ) { $teams_for_unit = Array(); }
603                                 $teams = $teams + $teams_for_unit;
604                         }
605                 }
606                 foreach ( $teams as $team_id ) {
607                         if ( array_key_exists( $team_id, $all_teams_information ) ) {
608                                 $teams_information[$team_id] = $all_teams_information[$team_id];
609                         }
610                 }
612                 //--------------------------------------------
613                 // 6 - Générer l'affichage
614                 //--------------------------------------------
615                 foreach ( $args['categories'] as $category ) {
616                         foreach ( $teams as $team_id ) {
617                                 $persons_information = $access_data->get_persons_information_for_a_category_in_a_team(
618                                         $category,
619                                         $team_id,
620                                         $status
621                                 );
622                                 $MonLabo_persons = New MonLabo_persons( $persons_information );
623                                 $MonLabo_persons->suppress_non_visible();
625                                 // Les filtrer selon la date si l'on est en mode alumni
626                                 if ( 'alumni_chart' === $shortcode_name ) {
627                                         if ( !empty( $args['years'] ) ) {
628                                                 if ( !empty( $persons_information ) ) {
629                                                         $MonLabo_persons->filter_with_alumni_years( $args['years'] );
630                                                 }
631                                         }
632                                 }
633                                 $persons_information = $MonLabo_persons->get_persons();
634                                 $team_leaders_id = $access_data->get_leaders_id_for_a_team( $team_id );
636                                 // On tague les leaders de chaque équipe
637                                 if ( !empty( $persons_information ) ) {
638                                         foreach ( $persons_information as $id => $person ) {
639                                                 $person = (array) $person;
640                                                 if ( ( !empty( $team_leaders_id ) ) and ( in_array( $id, $team_leaders_id) ) ) {
641                                                         $person['leader'] = true;
642                                                 } else {
643                                                         $person['leader'] = false;
644                                                 }
645                                                 $persons_information[$id] = (object ) $person;
646                                         }
647                                         $persons_information_by_category_and_team[$category][$team_id] = $persons_information;
648                                 }
649                         }
651                 }
652                 $a_afficher .= $generate_HTML->persons_chart(
653                         $unit_name,
654                         $MonLabo_directors->get_persons(),
655                         $teams_information,
656                         $persons_information_by_category_and_team,
657                         $currentlang
658                 );
660                 return $a_afficher;
661         }
663         //--------------------------------------------------------------------------------
664         // Add shortcode [perso_panel]
665         // Generate the personnal panel of the user belonging to the current page
666         // Ex: [perso_panel] => Only way to use ( no parameters )
667         //--------------------------------------------------------------------------------
668         static function perso_panel( $atts ) {
669                 $generate_HTML = New MonLabo_generate_HTML();
670                 $access_data = New MonLabo_access_data();
672                 // normalize attribute keys, lowercase
673                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
674                 // Attributes
675                 $args = shortcode_atts(
676                         array(
677                                 'person' => '',
678                         ),
679                         $atts,
680                         'perso_panel'
681                 );
682                 if ( '' == $args['person'] ) {
683                         $person_id = self::_person_of_curent_page();;
684                 } else {
685                         $person_id = intval( $args['person'] );
686                 }
688                 //var_dump( $person_id );
689                 if ( !empty( $person_id ) ) {
690                         $person_information = $access_data->get_person_information( $person_id );
691                         if ( !empty( $person_information ) ) {
692                                 $mentors_information= $access_data->get_mentors_information_for_a_person( $person_id );
693                                 $students_information = $access_data->get_students_information_for_a_person( $person_id );
694                                 $currentlang = get_locale( );
695                                 return $generate_HTML->person_panel(
696                                         $person_information,
697                                         $mentors_information,
698                                         $students_information,
699                                         $currentlang
700                                 );
701                         }
702                 }
703                 return '';
704         }
706         //--------------------------------------------------------------------------------
707         // Add shortcode [team_panel]
708         // Generate the team panel of the team belonging to the current page
709         // Ex: [team_panel] => Only way to use (no parameters)
710         //--------------------------------------------------------------------------------
711         static function team_panel( $atts ) {
712                 $generate_HTML = New MonLabo_generate_HTML();
713                 $access_data = New MonLabo_access_data();
715                 // normalize attribute keys, lowercase
716                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
718                 // Attributes
719                 $args = shortcode_atts(
720                         array(
721                                 'team' => '',
722                         ),
723                         $atts,
724                         'team_panel'
725                 );
727                 if ( '' == $args['team'] ) {
728                         $team_id = self::_team_of_curent_page();;
729                 } else {
730                         $team_id = intval( $args['team'] );
731                 }
733                 if ( !empty( $team_id ) ) {
734                         $team_information = $access_data->get_team_information( $team_id );
735                         if ( !empty( $team_information ) ) {
736                                 $leaders_information = $access_data->get_leaders_information_for_a_team( $team_id );
737                                 $currentlang = get_locale();
738                                 $thematics_name = $access_data->get_thematics_name_for_a_team( $team_id, $currentlang );
739                                 return $generate_HTML->team_panel(
740                                         $team_information,
741                                         $leaders_information,
742                                         $thematics_name,
743                                         $currentlang
744                                 );
745                         }
746                 }
747                 return '';
748         }
750         //--------------------------------------------------------------------------------
751         // Add shortcode [alumni_list]
752         // get list of old members from teams, labs etc...
753         //------------------------------------------------
754         // 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
755         //--------------------------------------------------------------------------------
756         static function alumni_list( $atts ) {
757                 $a_afficher = '';
758                 $generate_HTML = New MonLabo_generate_HTML();
759                 $currentlang = get_locale();
761                 // normalize attribute keys, lowercase
762                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
763                 // Attributes
764                 $args = shortcode_atts(
765                         array(
766                                 'team' => '',
767                                 'unit' => MAIN_STRUCT_NO_UNIT, //structure mère par défaut
768                                 'title' => '',
769                                 'categories' => '',
770                                 'years' => '',
771                                 'year' => '',
772                                 'annee' => '',
773                                 'external_link_title' => '',
774                         ),
775                         $atts,
776                         'alumni_list'
777                 );
778                 //Prendre des noms de variable plus adequats pour le traitement
779                 $units = sanitize_text_field( $args['unit'] );
780                 $teams = sanitize_text_field( $args['team'] );
782                 // Pouvoir utiliser le paramètre years au sigulier au besoin
783                 if ( '' === $args['years'] )   { $args['years'] = $args['year'];         }
784                 // Par defaut years remplace annee sauf si years est vide
785                 if ( '' === $args['years'] )   { $args['years'] = $args['annee'];        }
786                 $args['years'] = sanitize_text_field( $args['years'] );
788                 // Normalize values keys
789                 $args['categories'] = strtolower( sanitize_text_field( $args['categories'] ) );
790                 $args['title'] = sanitize_text_field( $args['title'] );
791                 $args['external_link_title'] = esc_url( $args['external_link_title'] );
793                 //--------------------------------------------
794                 // 1 - Sélectionner les personnes
795                 //--------------------------------------------
796                 // On recherche une éventuelle équipe attachée à la page courrante
797                 if ( '' === $teams ) { $teams = self::_team_of_curent_page(); }
799                 list( $MonLabo_persons, $dummy ) = self::_filter_persons_from_belongins(
800                         $teams,
801                         $units,
802                         $args['categories'],
803                         'alumni'
804                 );
806                 //--------------------------------------------
807                 // 2 - Les filtrer selon la date
808                 //--------------------------------------------
809                 if ( !empty( $args['years'] ) ) {
810                         $MonLabo_persons->filter_with_alumni_years( $args['years'] );
811                 }
813                 //--------------------------------------------
814                 // 3 - Générer l'affichage
815                 //--------------------------------------------
816                 if ( $MonLabo_persons->count() >0 ) {
817                         //2 - Lance l'affichage
818                         $MonLabo_persons->sort_by_name();
819                         $a_afficher .= $generate_HTML->persons_list(
820                                 $args['title'],
821                                 $args['title'],
822                                 $MonLabo_persons->get_persons(),
823                                 $currentlang
824                         );
825                 }
826                 return $a_afficher;
827         }
829         //--------------------------------------------------------------------------------
830         // Add shortcode [alumni_table]
831         // get list of old members from teams, labs etc...
832         //------------------------------------------------
833         // 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
834         //--------------------------------------------------------------------------------
835         static function alumni_table( $atts ) {
836                 $a_afficher = '';
837                 $access_data = New MonLabo_access_data();
838                 $generate_HTML = New MonLabo_generate_HTML();
839                 $currentlang = get_locale();
841                 // normalize attribute keys, lowercase
842                 $atts = array_change_key_case( ( array) $atts, CASE_LOWER );
844                 // Attributes
845                 $args = shortcode_atts(
846                         array(
847                                 'team' => '',
848                                 'unit' => MAIN_STRUCT_NO_UNIT, //structure mère par défaut
849                                 'title' => '',
850                                 'categories' => '',
851                                 'years' => '',
852                                 'year' => '',
853                                 'annee' => '',
854                         ),
855                         $atts,
856                         'alumni_table'
857                 );
859                 // Prendre des noms de variable plus adequats pour le traitement
860                 $units = sanitize_text_field( $args['unit'] );
861                 $teams = sanitize_text_field( $args['team'] );
863                 // Pouvoir utiliser le paramètre years au sigulier au besoin
864                 if ( '' === $args['years'] )   { $args['years'] = $args['year'];          }
865                 //Par defaut years remplace annee sauf si years est vide
866                 if ( '' === $args['years'] )   { $args['years'] = $args['annee'];        }
867                 $args['years'] = sanitize_text_field( $args['years'] );
869                 // Normalize values keys
870                 $args['categories'] = sanitize_text_field( strtolower( $args['categories'] ) );
872                 //--------------------------------------------
873                 // 1 - Sélectionner les personnes
874                 //--------------------------------------------
875                 // On recherche une éventuelle équipe attachée à la page courrante
876                 if ( '' === $teams ) { $teams = self::_team_of_curent_page(); }
878                 list( $MonLabo_persons, $dummy ) = self::_filter_persons_from_belongins(
879                         $teams,
880                         $units,
881                         $args['categories'],
882                         'alumni'
883                 );
885                 //--------------------------------------------
886                 // 2 - Les filtrer selon la date
887                 //--------------------------------------------
888                 if ( !empty( $args['years'] ) ) {
889                         $MonLabo_persons->filter_with_alumni_years( $args['years'] );
890                 }
892                 //----------------------------------------------------
893                 // 3 - S'il n'y a qu'une équipe, récupérer sa couleur
894                 //----------------------------------------------------
895                 $color = self::_color_of_team_if_only_one_team( $teams );
897                 //--------------------------------------------
898                 // 4 - Générer l'affichage
899                 //--------------------------------------------
900                 //Affichage du mode normal ( annuaire )
901                 $colum_titles = array( 'Nom', 'Equipe', 'Email', 'Tel' );
902                 if ( $MonLabo_persons->count() >0 ) {
903                         $a_afficher .=$generate_HTML->persons_table_normal(
904                                 $args['title'],
905                                 $colum_titles,
906                                 $MonLabo_persons->sort_by_name()->get_persons(),
907                                 $currentlang,
908                                 $color,
909                                 'alumni'
910                         );
911                 }
912                 return $a_afficher;
913         }
915         //--------------------------------------------------------------------------------
916         // Add shortcode [teams_list]
917         // get list of teams
918         //------------------------------------------------
919         // ex: [teams_list thematic = "3"] => Get the list of teams for thematics 3
920         //--------------------------------------------------------------------------------
921         static function teams_list( $atts ) {
922                 $a_afficher = "";
923                 $access_data = New MonLabo_access_data();
924                 $generate_HTML = New MonLabo_generate_HTML();
925                 $currentlang = get_locale();
927                 // normalize attribute keys, lowercase
928                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
930                 // Attributes
931                 $args = shortcode_atts(
932                         array(
933                                 'thematic' => "",
934                                 'unit' => "",
935                                 'group' => "",
936                                 'teams_publications_page' => ""
937                         ),
938                         $atts,
939                         'teams_list'
940                 );
942                 $args['unit'] = sanitize_text_field( $args['unit'] );
943                 $args['thematic'] = sanitize_text_field( $args['thematic'] );
944                 $args['group'] = sanitize_text_field( $args['group'] );
945                 $args['teams_publications_page'] = esc_url( $args['teams_publications_page'] );
948                 if ( !( '' === $args['thematic'] ) ) {
949                         $args['group'] = $args['thematic'];
950                 }
951                 if ( !( '' === $args['group'] ) ) {
952                         $teams_information = $access_data->get_teams_information_for_a_thematic( $args['group'] );
953                 } else {
954                         $teams_information = $access_data->get_teams_information();
955                 }
956                 $groups_information = array();
957                 $teams_leaders = array();
958                 if ( is_array( $teams_information ) ) {
959                         foreach ( $teams_information as $key=>$team_information ) {
960                                 $groups_information[$team_information->id] = $access_data->get_thematics_information_for_a_team( $team_information->id );
961                                 $teams_leaders[$team_information->id] = $access_data->get_leaders_name_for_a_team( $team_information->id );
963                                 //Si pas de logo définit, utiliser celui de l'unité
964                                 if ( empty( $team_information->logo ) ) {
965                                         if ( isset( $team_information->id_unit ) ) {
966                                                 $unit_information = $access_data->get_unit_information( $team_information->id_unit );
967                                                 if ( ( !empty( $unit_information ) ) and ( isset( $unit_information->logo ) ) ) {
968                                                         $teams_information[$key]->logo = $unit_information->logo;
969                                                 }
970                                         }
971                                 }
972                         }
973                 }
974                 $a_afficher .= $generate_HTML->teams_list(
975                         $args['group'],
976                         $teams_information,
977                         $teams_leaders,
978                         $groups_information,
979                         $args['teams_publications_page'],
980                         $currentlang
981                 );
983                 return $a_afficher;
984         }
986         //--------------------------------------------------------------------------------
987         // Add shortcode [dev_team_name]
988         // get team name from Descartes Pubbmed id for developpers...
989         // This function is not public and documented, only for developping purpose
990         //------------------------------------------------
991         // ex 1: [dev_team_name descartes_publi_team_id = "3"] => get the english name of team 3
992         //--------------------------------------------------------------------------------
993         static function dev_team_name( $atts ) {
995                 // normalize attribute keys, lowercase
996                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
998                 // Attributes
999                 $args = shortcode_atts(
1000                                 array(
1001                                 'descartes_publi_team_id' => '',
1002                         ),
1003                         $atts,
1004                         'dev_team_name'
1005                 );
1007                 $args['descartes_publi_team_id'] = sanitize_text_field( $args['descartes_publi_team_id'] );
1009                 global $wpdb;
1010                 $team = $wpdb->get_results(
1011                         $wpdb->prepare( "SELECT `name_en` FROM MonLabo_teams  WHERE `descartes_publi_team_id` = %s", $args['descartes_publi_team_id']),
1012                         ARRAY_A
1013                 );
1014                 if ( ( isset( $team[0] ) ) and isset( $team[0]["name_en"] ) ) {
1015                         return $team[0]["name_en"];
1016                 }
1017                 return "";
1018         }
1019         //--------------------------------------------------------------------------------
1020         // Add shortcode [dev_team_logo]
1021         // get team logo from Descartes Pubbmed id for developpers...
1022         // This function is not public and documented, only for developping purpose
1023         //------------------------------------------------
1024         // ex 1: [dev_team_logo descartes_publi_team_id = "3"] => get the logo of team 3
1025         //--------------------------------------------------------------------------------
1026         static function dev_team_logo( $atts ) {
1028                 // normalize attribute keys, lowercase
1029                 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
1031                 // Attributes
1032                 $args = shortcode_atts(
1033                                 array(
1034                                 'descartes_publi_team_id' => '',
1035                         ),
1036                         $atts,
1037                         'dev_team_logo'
1038                 );
1040                 $args['descartes_publi_team_id'] = sanitize_text_field( $args['descartes_publi_team_id'] );
1042                 global $wpdb;
1043                 $team = $wpdb->get_results(
1044                         $wpdb->prepare( "SELECT `logo` FROM MonLabo_teams  WHERE `descartes_publi_team_id` = %s", $args['descartes_publi_team_id']),
1045                         ARRAY_A
1046                 );
1047                 if ( ( isset( $team[0] ) ) and isset( $team[0]["logo"] ) ) {
1048                         return $team[0]["logo"];
1049                 }
1050                 return "";
1051         }