jury

Run Settings
LanguagePHP
Language Version
Run Command
<?php /* * Fonctions pour les évaluations et inscriptions du jury */ // Check le site en cours et attribut les id et autres function who_is_site(){ // Récupere ID du site courant $blog_id = get_current_blog_id(); if ($blog_id == 2){ // reunion.webcup.fr $ile = 'reunion'; $titre = 'Webcup Réunion'; $form_inscription_id = '4'; // Id du formulaire d'inscription $form_connect_id = '5'; // Id du formulaire de connexion $form_evaluation_id = '6'; // Id du formulaire de notation } elseif ($blog_id == 3){ $ile = 'mayotte'; $titre = 'Webcup Mayotte'; $form_inscription_id = '4'; $form_connect_id = '5'; $form_evaluation_id = '6'; } elseif ($blog_id == 4){ $ile = 'maurice'; $titre = 'Webcup Maurice'; $form_inscription_id = '3'; $form_connect_id = '4'; $form_evaluation_id = '5'; } elseif ($blog_id == 5){ $ile = 'madagascar'; $titre = 'Webcup Madagascar'; $form_inscription_id = '1'; $form_connect_id = '2'; $form_evaluation_id = '3'; } elseif ($blog_id == 6){ $ile = 'seychelles'; $titre = 'Webcup Seychelles'; $form_inscription_id = '2'; $form_connect_id = '3'; $form_evaluation_id = '4'; } elseif ($blog_id == 7){ $ile = 'comores'; $titre = 'Webcup Comores'; $form_inscription_id = '2'; $form_connect_id = '3'; $form_evaluation_id = '4'; } elseif ($blog_id == 8){ $ile = 'rodrigues'; $titre = 'Webcup Rodrigues'; $form_inscription_id = '2'; $form_connect_id = '3'; $form_evaluation_id = '4'; } $ile_detail = array( "nom" => $ile, "titre" => $titre, "form_inscription_id" => $form_inscription_id, "form_connect_id" => $form_connect_id, "form_evaluation_id" => $form_evaluation_id, ); return $ile_detail; } /////////////////////////////////////////////////////////////////////////////// /* * Création compte utilisateur jury */ // On récupére le id des formulaires $ile_detail = who_is_site(); $form_inscription_id = $ile_detail['form_inscription_id']; $form_connect_id = $ile_detail['form_connect_id']; $form_evaluation_id = $ile_detail['form_evaluation_id']; /////////////////////////////////////////////////////////////////////////////// /* * Verifier si le compte existe dèja */ add_filter('quform_element_valid_'.$form_inscription_id.'_18', function ($valid, $value, Quform_Element_Field $element) { if (email_exists($value)) { $element->addError('Cette adresse email est déjà enregistrée'); $valid = false; } return $valid; }, 10, 3); /////////////////////////////////////////////////////////////////////////////// /* * Créer l'utilisateur "jury" dans Wordpress */ add_action('quform_post_process_'.$form_inscription_id.'', function (array $result, Quform_Form $form) { $ile_detail = who_is_site(); $form_inscription_id = $ile_detail['form_inscription_id']; $email = $form->getValueText('quform_'.$form_inscription_id.'_18'); $password = $form->getValueText('quform_'.$form_inscription_id.'_7'); $nom = $form->getValue('quform_'.$form_inscription_id.'_9'); $prenom = $form->getValue('quform_'.$form_inscription_id.'_13'); $type_jury = $form->getValue('quform_'.$form_inscription_id.'_19'); $title = $prenom.' '.$nom; $userdata = array( 'user_login' => $email, 'user_pass' => $password, 'user_email' => $email, 'first_name' => $prenom, 'last_name' => $nom, 'display_name' => $title, 'nickname' => $title, 'role' => 'jury', 'user_registered' => date('Y-m-d h:i:s'), ); $user_id = wp_insert_user( $userdata ) ; update_user_meta( $user_id, 'type_jury', $type_jury); update_user_meta( $user_id, 'valide_jury', 'non'); return $result; }, 10, 2); /////////////////////////////////////////////////////////////////////////////// /* * Insertion du membre jury dans le custom post type jury pour affichage sur le site */ add_filter('quform_post_process_'.$form_inscription_id.'', function (array $result, Quform_Form $form) { $ile_detail = who_is_site(); $form_inscription_id = $ile_detail['form_inscription_id']; $choix_aficher_infos = $form->getValue('quform_'.$form_inscription_id.'_21'); if ($choix_aficher_infos == 'Oui'){ $nom = $form->getValue('quform_'.$form_inscription_id.'_9'); $prenom = $form->getValue('quform_'.$form_inscription_id.'_13'); $title = $prenom.' '.$nom; $bio = $form->getValue('quform_'.$form_inscription_id.'_22'); $post = array( 'post_title' => $title, 'post_content' => '', 'post_type' => 'lejury', 'post_status' => 'pending' ); // wp_insert_post($post); ///////////////////////////// $the_post_id = wp_insert_post($post); $bio_key = "field_534578f9445bb"; // Bio update_field( $bio_key, $bio, $the_post_id ); // Add attachment $file = $form->getValue('quform_'.$form_inscription_id.'_24'); $photo_key = "field_53457914445bc"; // photo // Add attachment if (isset($file[0])) { $file = $file[0]; $filename = $file['name']; $path = $file['path']; $wpFiletype = wp_check_filetype($filename); $attachment = array( 'guid' => $file['url'], 'post_mime_type' => $wpFiletype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', $filename), 'post_content' => '', 'post_status' => 'inherit' ); $attachId = wp_insert_attachment($attachment, $path, $the_post_id); require_once ABSPATH . 'wp-admin/includes/image.php'; $attachData = wp_generate_attachment_metadata($attachId, $path); wp_update_attachment_metadata($attachId, $attachData); set_post_thumbnail($the_post_id, $attachId); } update_field( $photo_key, $attachId, $the_post_id ); } // End if return $result; }, 10, 2); /////////////////////////////////////////////////////////////////////////////// /* * Formulaire de connexion au tableau de bord jury */ add_filter('quform_post_validate_'.$form_connect_id.'', function (array $result, Quform_Form $form) { $ile_detail = who_is_site(); $form_connect_id = $ile_detail['form_connect_id']; $credentials = array( 'user_login' => $form->getValueText('quform_'.$form_connect_id.'_7'), 'user_password' => $form->getValueText('quform_'.$form_connect_id.'_12'), 'remember' => $form->getValueText('quform_'.$form_connect_id.'_13') == 'Se souvenir de moi', ); $user = wp_signon($credentials); if (is_wp_error($user)) { $result = array( 'type' => 'error', 'error' => array( 'enabled' => true, 'title' => '', 'content' => $user->get_error_message() ) ); } return $result; }, 10, 2); /////////////////////////////////////////////////////////////////////////////// /* * Verifie le role de l'utilisateur */ function check_user_role($roles, $user_id = null) { if ($user_id) $user = get_userdata($user_id); else $user = wp_get_current_user(); if (empty($user)) return false; foreach ($user->roles as $role) { if (in_array($role, $roles)) { return true; } } return false; } /////////////////////////////////////////////////////////////////////////////// /* * Ajouts des paramétres dans les champs cachés du formulaire de notation */ // Ajout si juri est un dev add_filter('quform_element_value_type_jury', function ($value) { $current_user = wp_get_current_user(); if ($current_user->roles[0] == 'jury'){ $type_jury = get_user_meta( $current_user->ID, 'type_jury', true ); } return $type_jury; }); // ID du membre jury add_filter('quform_element_value_id_jury', function ($value) { $jure_id = wp_get_current_user(); $jure = $jure_id->ID; return ''.$jure; }); /////////////////////////////////////////////////////////////////////////////// /* * Traitement du formulaire d'évaluation */ add_filter('quform_post_process_'.$form_evaluation_id.'', function (array $result, Quform_Form $form) { $ile_detail = who_is_site(); $form_evaluation_id = $ile_detail['form_evaluation_id']; $carnet_id = $form->replaceVariables('{post|ID}'); $jury_id = $form->getValue('quform_'.$form_evaluation_id.'_159'); $type_jury = $form->getValue('quform_'.$form_evaluation_id.'_156'); // Valeurs 1 $sujet_1 = $form->getValue('quform_'.$form_evaluation_id.'_42'); $sujet_2 = $form->getValue('quform_'.$form_evaluation_id.'_43'); $design_1 = $form->getValue('quform_'.$form_evaluation_id.'_92'); $design_2 = $form->getValue('quform_'.$form_evaluation_id.'_94'); $design_3 = $form->getValue('quform_'.$form_evaluation_id.'_96'); $design_4 = $form->getValue('quform_'.$form_evaluation_id.'_195'); $design_5 = $form->getValue('quform_'.$form_evaluation_id.'_197'); $design_6 = $form->getValue('quform_'.$form_evaluation_id.'_199'); $autre_1 = $form->getValue('quform_'.$form_evaluation_id.'_147'); $autre_2 = $form->getValue('quform_'.$form_evaluation_id.'_149'); $total_tab_1 = $sujet_1 + $sujet_2 + $design_1 + $design_2 + $design_3 + $design_4 + $design_5 + $design_6 + $autre_1 + $autre_2; // Bonus $bonus_1 = $form->getValue('quform_'.$form_evaluation_id.'_125'); if (!$bonus_1[0]){ $bonus_1 = '0'; } else { $bonus_1 = $bonus_1[0]; } $bonus_2 = $form->getValue('quform_'.$form_evaluation_id.'_126'); if (!$bonus_2[0]){ $bonus_2 = '0'; } else { $bonus_2 = $bonus_2[0]; } $bonus_3 = $form->getValue('quform_'.$form_evaluation_id.'_127'); if (!$bonus_3[0]){ $bonus_3 = '0'; } else { $bonus_3 = $bonus_3[0]; } $bonus_4 = $form->getValue('quform_'.$form_evaluation_id.'_128'); if (!$bonus_4[0]){ $bonus_4 = '0'; } else { $bonus_4 = $bonus_4[0]; } $bonus_5 = $form->getValue('quform_'.$form_evaluation_id.'_129'); if (!$bonus_5[0]){ $bonus_5 = '0'; } else { $bonus_5 = $bonus_5[0]; } // Malus $malus_1 = $form->getValue('quform_'.$form_evaluation_id.'_175'); if (!$malus_1[0]){ $malus_1 = '0'; } else { $malus_1 = $malus_1[0]; } $malus_2 = $form->getValue('quform_'.$form_evaluation_id.'_176'); if (!$malus_2[0]){ $malus_2 = '0'; } else { $malus_2 = $malus_2[0]; } $malus_3 = $form->getValue('quform_'.$form_evaluation_id.'_184'); if (!$malus_3[0]){ $malus_3 = '0'; } else { $malus_3 = $malus_3[0]; } $malus_4 = $form->getValue('quform_'.$form_evaluation_id.'_185'); if (!$malus_4[0]){ $malus_4 = '0'; } else { $malus_4 = $malus_4[0]; } $malus_5 = $form->getValue('quform_'.$form_evaluation_id.'_186'); if (!$malus_5[0]){ $malus_5 = '0'; } else { $malus_5 = $malus_5[0]; } $total_bonus = $bonus_1 + $bonus_2 + $bonus_3 + $bonus_4 + $bonus_5 ; $total_malus = $malus_1 + $malus_2 + $malus_3 + $malus_4 + $malus_5; $total_final_malus = 100 - $total_malus; if ($type_jury == 'membre du jury dans la catégorie développeur'){ // SI C EST UN DEV $not_dev_1 = $form->getValue('quform_'.$form_evaluation_id.'_155'); if (!$not_dev_1){ $not_dev_1 = '0'; } else { $not_dev_1 = $not_dev_1 * 10; } $not_dev_2 = $form->getValue('quform_'.$form_evaluation_id.'_160'); if (!$not_dev_2){ $not_dev_2 = '0'; } else { $not_dev_2 = $not_dev_2 * 10; } // SI C EST UN DEV $total_general = $total_tab_1 + $total_final_malus + $total_bonus + $not_dev_1 + $not_dev_2; $moyenne_general = $total_general / 5; } else { $total_general = $total_tab_1 + $total_final_malus + $total_bonus; $moyenne_general = $total_general / 3; $not_dev_1 = '0'; $not_dev_2 = '0'; } $note_equipe = array( "jure_id" => $jury_id, "type_jury" => $type_jury, "sujet_1" => $sujet_1, "sujet_2" => $sujet_2, "design_1" => $design_1, "design_2" => $design_2, "design_3" => $design_3, "design_4" => $design_4, "design_5" => $design_5, "design_6" => $design_6, "autre_1" => $autre_1, "autre_2" => $autre_2, "not_dev_1" => $not_dev_1, "not_dev_2" => $not_dev_2, "bonus_1" => $bonus_1, "bonus_2" => $bonus_2, "bonus_3" => $bonus_3, "bonus_4" => $bonus_4, "bonus_5" => $bonus_5, "malus_1" => $malus_1, "malus_2" => $malus_2, "malus_3" => $malus_3, "malus_4" => $malus_4, "malus_5" => $malus_5, "total_bonus" => $total_bonus, "total_malus" => $total_malus, "total_tab_1" => $total_tab_1, "total_final_malus" => $total_final_malus, "total_general" => $total_general, "moyenne_general" => $moyenne_general, ); update_post_meta( $carnet_id, 'note_jury_'.$jury_id.'', $note_equipe ); return $result; }, 10, 2); /////////////////////////////////////////////////////////////////////////////// /* * Calcul de la notation moyenne finale */ function note_global_team(){ // Liste des membre du jury $args1 = array( 'role' => 'jury', 'orderby' => 'user_nicename', 'order' => 'ASC' ); $subscribers = get_users($args1); $montant_total_1 = 0; $montant_total_2 = 0; $montant_total_3 = 0; $montant_total_4 = 0; $montant_total_5 = 0; $montant_total_6 = 0; $montant_total_7 = 0; $montant_total_8 = 0; $montant_total_9 = 0; $montant_total_10 = 0; $montant_total_11 = 0; $montant_total_12 = 0; $montant_total_13 = 0; $montant_total_14 = 0; $montant_total_15 = 0; $montant_total_16 = 0; $montant_total_17 = 0; $montant_total_18 = 0; $montant_total_19 = 0; $montant_total_20 = 0; $montant_total_21 = 0; $montant_total_22 = 0; $montant_total_23 = 0; $montant_total_24 = 0; foreach ($subscribers as $user) { $jury_id = $user->ID; $notes_jury = get_post_meta( get_the_ID(), 'note_jury_'.$jury_id.'' ); if ($notes_jury){ $note = $notes_jury[0]; $nb_jury = $montant_total_23 += '1'; $sujet_1 = $montant_total_1 += $note['sujet_1']; $sujet_1 = $sujet_1 / $nb_jury; $sujet_2 = $montant_total_2 += $note['sujet_2']; $sujet_2 = $sujet_2 / $nb_jury; $design_1 = $montant_total_3 += $note['design_1']; $design_1 = $design_1 / $nb_jury; $design_2 = $montant_total_4 += $note['design_2']; $design_2 = $design_2 / $nb_jury; $design_3 = $montant_total_5 += $note['design_3']; $design_3 = $design_3 / $nb_jury; $design_4 = $montant_total_6 += $note['design_4']; $design_4 = $design_4 / $nb_jury; $design_5 = $montant_total_7 += $note['design_5']; $design_5 = $design_5 / $nb_jury; $design_6 = $montant_total_8 += $note['design_6']; $design_6 = $design_6 / $nb_jury; $autre_1 = $montant_total_9 += $note['autre_1']; $autre_1 = $autre_1 / $nb_jury; $autre_2 = $montant_total_10 += $note['autre_2']; $autre_2 = $autre_2 / $nb_jury; $total_tab_1 = $montant_total_12 += $note['total_tab_1']; $total_tab_1 = $total_tab_1 / $nb_jury; $bonus_1 = $montant_total_13 += $note['bonus_1']; $bonus_1 = $bonus_1 / $nb_jury; $bonus_2 = $montant_total_14 += $note['bonus_2']; $bonus_2 = $bonus_2 / $nb_jury; $bonus_3 = $montant_total_15 += $note['bonus_3']; $bonus_3 = $bonus_3 / $nb_jury; $bonus_4 = $montant_total_16 += $note['bonus_4']; $bonus_4 = $bonus_4 / $nb_jury; $bonus_5 = $montant_total_17 += $note['bonus_5']; $bonus_5 = $bonus_5 / $nb_jury; $malus_1 = $montant_total_18 += $note['malus_1']; $malus_1 = $malus_1 / $nb_jury; $malus_2 = $montant_total_19 += $note['malus_2']; $malus_2 = $malus_2 / $nb_jury; $malus_3 = $montant_total_20 += $note['malus_3']; $malus_3 = $malus_3 / $nb_jury; $malus_4 = $montant_total_21 += $note['malus_4']; $malus_4 = $malus_4 / $nb_jury; $malus_5 = $montant_total_22 += $note['malus_5']; $malus_5 = $malus_5 / $nb_jury; $moyenne_general = $montant_total_24 += $note['moyenne_general']; $moyenne_general = $moyenne_general / $nb_jury; $total_bonus = $bonus_1 + $bonus_2 + $bonus_3 + $bonus_4 + $bonus_5 ; $total_malus = $malus_1 + $malus_2 + $malus_3 + $malus_4 + $malus_5; $total_final_malus = 100 - $total_malus; if ($note['type_jury'] == 'membre du jury dans la catégorie développeur'){ // SI C EST UN DEV $not_dev_1 = $note['not_dev_1']; if (!$not_dev_1){ $not_dev_1 = '0'; } $not_dev_2 = $note['not_dev_2']; if (!$not_dev_2){ $not_dev_2 = '0'; } } else { $not_dev_1 = '0'; $not_dev_2 = '0'; } } } if ($sujet_1){ $moyenne_equipe = array( "nb_jury" => $nb_jury, "sujet_1" => $sujet_1, "sujet_2" => $sujet_2, "design_1" => $design_1, "design_2" => $design_2, "design_3" => $design_3, "design_4" => $design_4, "design_5" => $design_5, "design_6" => $design_6, "autre_1" => $autre_1, "autre_2" => $autre_2, "not_dev_1" => $not_dev_1, "not_dev_2" => $not_dev_2, "bonus_1" => $bonus_1, "bonus_2" => $bonus_2, "bonus_3" => $bonus_3, "bonus_4" => $bonus_4, "bonus_5" => $bonus_5, "malus_1" => $malus_1, "malus_2" => $malus_2, "malus_3" => $malus_3, "malus_4" => $malus_4, "malus_5" => $malus_5, "total_bonus" => $total_bonus, "total_malus" => $total_malus, "total_tab_1" => $total_tab_1, "total_final_malus" => $total_final_malus, "moyenne_general" => $moyenne_general, ); } else { $moyenne_equipe = array( "nb_jure" => '', "sujet_1" => '', "sujet_2" => '', "design_1" => '', "design_2" => '', "design_3" => '', "design_4" => '', "design_5" => '', "design_6" => '', "autre_1" => '', "autre_2" => '', "autre_3" => '', "not_dev_1" => '', "not_dev_2" => '', "bonus_1" => '', "bonus_2" => '', "bonus_3" => '', "bonus_4" => '', "bonus_5" => '', "malus_1" => '', "malus_2" => '', "malus_3" => '', "malus_4" => '', "malus_5" => '', "total_bonus" => '', "total_malus" => '', "total_tab_1" => '', "total_final_malus" => '', "total_general" => '', "moyenne_general" => '', ); } return $moyenne_equipe; } /////////////////////////////////////////////////////////////////////////////// /* * function pour compter le nombre de membre du jury */ function compter_jury(){ $args1 = array( 'role' => 'jury', ); $nombre_jury = count(get_users($args1)) ; return $nombre_jury; } /////////////////////////////////////////////////////////////////////////////// /* * Fonction d'affichage des résultats de toutes les îles dans le tableau de bord des admins Webcup Réunion. * https://reunion.webcup.fr/resultats-global-evaluations-du-jury */ function display_all_result(){ $detail = who_is_site(); $nomb_jury = compter_jury(); if ( !$nomb_jury ){ $nomb_jury ='0'; } $args = array ( 'post_type' => 'team_webcup', 'posts_per_page' => -1, 'meta_key' => 'annee_edition_webcup', 'meta_value' => '2021' ); $query = new WP_Query( $args ); $totalpost = $query->found_posts; if ( $query->have_posts() ) { ob_start(); ?> <div class="c-desc"> <article role="article"> <h2><span class="label label-success c-font-slim"><?php echo $detail['titre']; ?></span> <span class="badge c-bg-dark"><?php echo $totalpost ?></span> équipes | <span class="badge c-bg-yellow"><?php echo $nomb_jury ?></span> membres du jury</h2> <table class="table table-striped"> <thead> <tr> <th>#id</th> <th>Nom de l'équipe</th> <th>Capitaine</th> <th>Nombre de participants</th> <th>Évaluation global</th> <th>Nb d'évaluations</th> <th>Carnet de route</th> </tr> </thead> <tbody> <?php while ( $query->have_posts() ) { $query->the_post(); $post_id=get_the_ID(); $nb_team = count($post_id); $nb_personnes_dans_team = get_field('nb_personnes_dans_team'); $url = get_permalink($post_id); $notes = note_global_team(); $nom_capitaine = get_field('nom_capitaine'); $prenom_capitaine = get_field('prenom__capitaine'); $mail_capitaine = get_field('mail_capitaine'); ?> <tr> <td> <?php echo $post_id?> </td> <td> <?php the_title(); ?> </td> <td> <a href="mailto:<?php echo $mail_capitaine; ?>" target="_blank"><?php echo $prenom_capitaine; ?> <?php echo $nom_capitaine; ?></a> </td> <td> <span class="badge c-bg-green"><?php echo $nb_personnes_dans_team?></span> </td> <td> <?php if ($notes['moyenne_general'] ){ ?> <span class="c-content-label c-font-uppercase c-font-bold c-bg-green-2 c-font-slim c-label-lg"><?php echo round($notes['moyenne_general'], 2);?><span class="small">/100</span></span> <?php } ?> </td> <td> <?php if ($notes['nb_jury'] ){ ?> <span class="c-content-label c-font-uppercase c-font-bold c-bg-green-2 c-font-slim c-label-lg"><?php echo $notes['nb_jury'];?>/<?php echo $nomb_jury?></span> <?php } ?> </td> <td> <?php $etat = '<a href="'.$url.'" target="_blank" class="btn btn-info">Voir</a>'; if ( $nomb_jury > '0' ){ if ( $notes['nb_jury'] == $nomb_jury ){ $etat = '<a href="'.$url.'" target="_blank" class="btn btn-success ">Terminé</a>'; } elseif ($notes['moyenne_general']){ $etat = '<a href="'.$url.'" target="_blank" class="btn btn-warning">En cours</a>'; } } echo $etat; ?> </td> </tr> <?php } ?> </tbody> </table> </article> </div> <?php } else { // no posts found } wp_reset_postdata(); return ob_get_clean(); } ////////////////////////////////////////////////// function cheks_jury_activ(){ $args1 = array( 'role' => 'jury', ); $jurys_data = get_users($args1); $check = false; foreach ($jurys_data as $user) { $jury_id = $user->ID; $user_last = get_user_meta( $jury_id, 'valide_jury', true ); } return $user_last; }
Editor Settings
Theme
Key bindings
Full width
Lines