芝麻web文件管理V1.00
编辑当前文件:/home/prismawe/www/resupres/application/classes/controller/stats.php
request->redirect('stats/victoires_par_parti'); } public function action_victoires_par_parti() { // On récupère les anciens duels $duels = ORM::factory('duel') ->where('dateDebut', '<', DB::expr('current_date')) ->order_by('dateDebut', 'DESC') ->find_all(); $partisORM = ORM::factory('parti') ->find_all(); $partis = array(); $victoires = array(); foreach($partisORM as $parti){ $partis["$parti->id"] = $parti->nom; $victoires["$parti->id"] = 0; } foreach($duels as $duel){ $votesCandidat1 = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat1_id) ->find_all() ->count(); $votesCandidat2 = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat2_id) ->find_all() ->count(); if ($votesCandidat1 > $votesCandidat2) $victoires[$duel->candidat1->parti_id]++; else { if ($votesCandidat2 > $votesCandidat1) $victoires[$duel->candidat2->parti_id]++; } } arsort($victoires); $votes = array(); foreach($victoires as $key => $victoire){ $votes[] = array('col3' => $key, 'col2' => $victoire, 'col1' => $partis[$key]); } $this->template->metaDescription = 'Page de l\'historique de tous les duels politiques depuis le lancement du site.'; $this->template->metaKeywords = 'Statistiques, sondages, présidentielles 2012, candidats 2012, election 2012, sarkozy 2012, le pen 2012, ségolène royale 2012, 2012'; $this->template->pageTitle = 'Victoires par parti - Statistiques'; $this->template->content = View::factory('stats/victoires_par_parti'); $this->template->content->nbDuels = $duels->count(); $this->template->content->votes = $votes; } public function action_victoires_par_candidat(){ // On récupère les anciens duels $duels = ORM::factory('duel') ->where('dateDebut', '<', DB::expr('current_date')) ->order_by('dateDebut', 'DESC') ->find_all(); $candidatsORM = ORM::factory('candidat') ->where('isCandidate', '=', 1) ->find_all(); $candidats = array(); $victoires = array(); foreach($candidatsORM as $candidat){ $candidats["$candidat->id"] = $candidat->prenom.' '.$candidat->nom; $victoires["$candidat->id"] = 0; } foreach($duels as $duel){ $votesCandidat1 = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat1_id) ->find_all() ->count(); $votesCandidat2 = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat2_id) ->find_all() ->count(); if ($votesCandidat1 > $votesCandidat2) $victoires[$duel->candidat1_id]++; else { if ($votesCandidat2 > $votesCandidat1) $victoires[$duel->candidat2_id]++; } } arsort($victoires); $votes = array(); foreach($victoires as $key => $victoire){ $votes[] = array('col3' => $key, 'col2' => $victoire, 'col1' => $candidats[$key]); } $this->template->metaDescription = ''; $this->template->metaKeywords = ''; $this->template->pageTitle = 'Victoires par candidat - Statistiques'; $this->template->content = View::factory('stats/victoires_par_candidat'); $this->template->content->votes = $votes; $this->template->content->nbDuels = $duels->count(); } public function action_victoires_par_orientation(){ // On récupère les anciens duels $duels = ORM::factory('duel') ->where('dateDebut', '<', DB::expr('current_date')) ->order_by('dateDebut', 'DESC') ->find_all(); $orientationsORM = ORM::factory('orientation') ->find_all(); $orientations = array(); $victoires = array(); foreach($orientationsORM as $orientation){ $orientations["$orientation->id"] = $orientation->nom; $victoires["$orientation->id"] = 0; } foreach($duels as $duel){ $votesCandidat1 = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat1_id) ->find_all() ->count(); $votesCandidat2 = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat2_id) ->find_all() ->count(); if ($votesCandidat1 > $votesCandidat2) $victoires[$duel->candidat1->parti->orientation_id]++; else { if ($votesCandidat2 > $votesCandidat1) $victoires[$duel->candidat2->parti->orientation_id]++; } } arsort($victoires); $votes = array(); foreach($victoires as $key => $victoire){ $votes[] = array('col3' => $key,'col2' => $victoire, 'col1' => $orientations[$key]); } $this->template->metaDescription = ''; $this->template->metaKeywords = ''; $this->template->pageTitle = 'Victoires par orientation - Statistiques'; $this->template->content = View::factory('stats/victoires_par_orientation'); $this->template->content->nbDuels = $duels->count(); $this->template->content->votes = $votes; } }