芝麻web文件管理V1.00
编辑当前文件:/home/p/r/i/prismawe/www/resupres/application/classes/controller/mobile/duel.php
request->redirect('mobile/duel/consulter'); } public function action_consulter() { $duel = ORM::factory('duel') ->where('id', '=', $this->request->param('id')) ->and_where('dateDebut', '<=', DB::expr('current_date')) ->find(); $duelDuJour = ORM::factory('duel') ->where('dateDebut', '<=', DB::expr('current_date')) ->and_where('dateFin', '>=', DB::expr('current_date')) ->find(); if ($duel->loaded()) { //URL DOIT etre sous la forme /duel/consulter/id-c1Nom-c1Prenom-contre-c2Nom-c2Prenom $c1Nom = URL::title($duel->candidat1->nom, '_', true); $c1Prenom = URL::title($duel->candidat1->prenom, '_', true); $c2Nom = URL::title($duel->candidat2->nom, '_', true); $c2Prenom = URL::title($duel->candidat2->prenom, '_', true); /* if ($this->request->param('c1Nom') != $c1Nom OR $this->request->param('c1Prenom') != $c1Prenom OR $this->request->param('c2Nom') != $c2Nom OR $this->request->param('c2Prenom') != $c2Prenom) { $this->request->redirect('duel/consulter/' . $duel->id . '-' . $c1Nom . '-' . $c1Prenom . '-contre-' . $c2Nom . '-' . $c2Prenom); } * */ $votesCandidat1 = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat1_id) ->find_all(); $votesCandidat2 = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat2_id) ->find_all(); $votesCandidatBlanc = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', 0) ->find_all(); //Recupère les duels suivant et précédent. //On récupère le duel suivant if ($duel->id != $duelDuJour->id) { if (!$duel->dateFin) { $dateFin = $duel->dateDebut; } else { $dateFin = $duel->dateFin; } $duelSuivant = ORM::factory('duel') ->where('dateDebut', '>', $dateFin) ->order_by('dateDebut') ->find(); } else { //pas de duel suivant $duelSuivant = null; } //avant le duel 74 il n'y a pas de stats donc pas d'affichage des liste déroulantes if($duel->id > 74){ // On récupère le duel d'hier $duelPrecedent = ORM::factory('duel') ->where('dateDebut', '<', $duel->dateDebut) ->order_by('dateDebut', 'DESC') ->find(); $regions = ORM::factory('region') ->find_all(); $ages = ORM::factory('age') ->find_all(); $categSocProcs = ORM::factory('categoriesocio') ->find_all(); //On prépare les requetes pour les résultats de chaque candidats $votesCandidat1 = ORM::factory('vote')->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat1_id); // ->find_all(); $votesCandidat2 = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat2_id); // ->find_all(); $votesCandidatBlanc = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', 0); //->find_all(); if (count($_POST)>0) { //Si une region a été saisie if ($this->request->post('region_id') !== '-1') { //On le rajoute à toute les requêtes $votesCandidat1->and_where('region_id', '=', $this->request->post('region_id')); $votesCandidat2->and_where('region_id', '=', $this->request->post('region_id')); $votesCandidatBlanc->and_where('region_id', '=', $this->request->post('region_id')); } //Si un age a été saisi if ($this->request->post('age_id') !== '-1') { //On le rajoute à toute les requêtes $votesCandidat1->and_where('age_id', '=', $this->request->post('age_id')); $votesCandidat2->and_where('age_id', '=', $this->request->post('age_id')); $votesCandidatBlanc->and_where('age_id', '=', $this->request->post('age_id')); } //Si une categ a été saisie if ($this->request->post('categoriesocio_id') !=='-1') { //On le rajoute à toute les requêtes $votesCandidat1->and_where('categoriesocio_id', '=', $this->request->post('categoriesocio_id')); $votesCandidat2->and_where('categoriesocio_id', '=', $this->request->post('categoriesocio_id')); $votesCandidatBlanc->and_where('categoriesocio_id', '=', $this->request->post('categoriesocio_id')); } } $votesCandidat1 = $votesCandidat1->find_all(); $votesCandidat2 = $votesCandidat2->find_all(); $votesCandidatBlanc = $votesCandidatBlanc->find_all(); //Pour afficher le nombre de votant dans chaque catégorie $nombreVotantAge = ''; foreach ($ages as $age) { $req = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('age_id', '=', $age->id); if(count($_POST)>0){ if ($this->request->post('region_id') !== '-1') { $req->and_where('region_id', '=', $this->request->post('region_id')); } if ($this->request->post('age_id') !== '-1') { $req->and_where('age_id', '=', $this->request->post('age_id')); } if ($this->request->post('categoriesocio_id') !== '-1') { $req->and_where('categoriesocio_id', '=', $this->request->post('categoriesocio_id')); } } $req = $req->find_all(); $nombreVotantAge[$age->id] = count($req); } $nombreVotantCat = ''; foreach ($categSocProcs as $cat) { $req = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('categoriesocio_id', '=', $cat->id); if(count($_POST)>0){ if ($this->request->post('region_id') !== '-1') { $req->and_where('region_id', '=', $this->request->post('region_id')); } if ($this->request->post('age_id') !== '-1') { $req->and_where('age_id', '=', $this->request->post('age_id')); } if ($this->request->post('categoriesocio_id') !== '-1') { $req->and_where('categoriesocio_id', '=', $this->request->post('categoriesocio_id')); } } $req = $req->find_all(); $nombreVotantCat[$cat->id] = count($req); } $nombreVotantRegion = ''; foreach ($regions as $region) { $req = ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('region_id', '=', $region->id); if(count($_POST)>0){ if ($this->request->post('region_id') !== '-1') { $req->and_where('region_id', '=', $this->request->post('region_id')); } if ($this->request->post('age_id') !== '-1') { $req->and_where('age_id', '=', $this->request->post('age_id')); } if ($this->request->post('categoriesocio_id') !== '-1') { $req->and_where('categoriesocio_id', '=', $this->request->post('categoriesocio_id')); } } $req = $req->find_all(); $nombreVotantRegion[$region->id] = count($req); } } $totalVotes = count($votesCandidat1) + count($votesCandidat2) + count($votesCandidatBlanc); if ($totalVotes > 0) { $pourcentage1 = count($votesCandidat1) / $totalVotes * 100; $pourcentage2 = count($votesCandidat2) / $totalVotes * 100; $pourcentageBlanc = count($votesCandidatBlanc) / $totalVotes * 100; } else { $pourcentage1 = 0; $pourcentage2 = 0; $pourcentageBlanc = 0; } $this->template->metaDescription = 'Résultat du sondage opposant : ' . $duel->candidat1->nom . ' ' . $duel->candidat1->prenom . ' à ' . $duel->candidat2->nom . ' ' . $duel->candidat2->prenom; $this->template->metaKeywords = 'Duels politiques, primaires 2012,Statistiques, sondages, présidentielles 2012, candidats 2012, election 2012,' . $duel->candidat1->nom . ' ' . $duel->candidat1->prenom . ', sarkozy 2012, le pen 2012, ségolène royale 2012, 2012,' . $duel->candidat2->nom . ' ' . $duel->candidat2->prenom . ''; $this->template->pageTitle = $duel->candidat1->prenom . ' ' . $duel->candidat1->nom . ' VS ' . $duel->candidat2->prenom . ' ' . $duel->candidat2->nom; $this->template->content = View::factory('mobile/consulter'); $this->template->content->duel = $duel; $this->template->content->totalVotes = $totalVotes; $this->template->content->pourcentage1 = round($pourcentage1, 2); $this->template->content->pourcentage2 = round($pourcentage2, 2); $this->template->content->pourcentageBlanc = round($pourcentageBlanc, 2); $this->template->content->duelSuivant = $duelSuivant; $this->template->content->duelPrecedent = $duelPrecedent; if($duel->id > 74){ $this->template->content->regions = $regions; $this->template->content->ages = $ages; $this->template->content->categSocProcs = $categSocProcs; $this->template->content->nbVotantAge = $nombreVotantAge; $this->template->content->nbVotantCat = $nombreVotantCat; $this->template->content->nbVotantRegion = $nombreVotantRegion; } } else $this->request->redirect('mobile/accueil'); } public function action_rss() { $duels = ORM::factory('duel') ->where('dateDebut', '<=', DB::expr('current_date')) ->order_by('dateDebut', 'DESC') ->find_all(); $this->template = View::factory('duel/rss'); $this->template->duels = $duels; } public function action_consulter_json(){ $duel = ORM::factory('duel'); if ($this->request->param('id')) $duel->where('id', '=', $this->request->param('id')) ->and_where('dateDebut', '<', DB::expr('current_date')) ->and_where('dateFin', '<', DB::expr('current_date')) ->find(); if (!$duel->loaded()){ $duel->where('dateFin', '<', DB::expr('current_date')) ->order_by('id', 'DESC') ->find(); } $precedent = ORM::factory('duel') ->where('dateDebut', '<', $duel->dateDebut) ->order_by('dateDebut', 'DESC') ->find(); $suivant = ORM::factory('duel') ->where('dateDebut', '>', $duel->dateFin) ->and_where('dateFin', '<', DB::expr('current_date')) ->order_by('dateDebut') ->find(); $votesCandidat1 = count(ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat1_id) ->find_all()); $votesCandidat2 = count(ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', $duel->candidat2_id) ->find_all()); $votesCandidatBlanc = count(ORM::factory('vote') ->where('duel_id', '=', $duel->id) ->and_where('candidat_id', '=', 0) ->find_all()); $dateDebut = new DateTime($duel->dateDebut); $dateFin= new DateTime($duel->dateFin); $votes = $votesCandidat1 + $votesCandidat2 + $votesCandidatBlanc; $this->template = View::factory('mobile/duel/consulter_json'); $this->template->dateDebut = $dateDebut->format('d/m/Y'); $this->template->dateFin = $dateFin->format('d/m/Y'); $this->template->duel = $duel; $this->template->precedent = $precedent; $this->template->suivant = $suivant; $this->template->votesCandidat1 = round($votesCandidat1 / $votes * 100); $this->template->votesCandidat2 = round($votesCandidat2 / $votes * 100); $this->template->votesCandidatBlanc = round($votesCandidatBlanc / $votes * 100); } }