芝麻web文件管理V1.00
编辑当前文件:/home/p/r/i/prismawe/www/resupres/application/classes/controller/admin/stat.php
template->content = View::factory('admin/stat/list'); /* $j = ORM::factory('vote') ->where(DB::expr('DATE(jourHeure)'), '=', DB::expr('current_date')) ->find_all(); $d1 = ORM::factory('vote') ->where(DB::expr('DATE(jourHeure)'), '=', DB::expr('ADDDATE(current_date, -1)')) ->find_all(); $d2 = ORM::factory('vote') ->where(DB::expr('DATE(jourHeure)'), '=', DB::expr('ADDDATE(current_date, -2)')) ->find_all(); $d3 = ORM::factory('vote') ->where(DB::expr('DATE(jourHeure)'), '=', DB::expr('ADDDATE(current_date, -3)')) ->find_all(); $d4 = ORM::factory('vote') ->where(DB::expr('DATE(jourHeure)'), '=', DB::expr('ADDDATE(current_date, -4)')) ->find_all(); $d5 = ORM::factory('vote') ->where(DB::expr('DATE(jourHeure)'), '=', DB::expr('ADDDATE(current_date, -5)')) ->find_all(); $d6 = ORM::factory('vote') ->where(DB::expr('DATE(jourHeure)'), '=', DB::expr('ADDDATE(current_date, -6)')) ->find_all(); $this->template->content->j = count($j); $this->template->content->d1 = count($d1); $this->template->content->d2 = count($d2); $this->template->content->d3 = count($d3); $this->template->content->d4 = count($d4); $this->template->content->d5 = count($d5); $this->template->content->d6 = count($d6); //*/ /* * Stat bar du duel par tranche d'age */ //duel du moment $duel = ORM::factory('duel') ->where('dateDebut', '<=', DB::expr('current_date')) ->and_where('dateFin', '>=', DB::expr('current_date')) ->find(); $ages = ORM::factory('age')->find_all(); $barDuelAgeC1 = array(); $barDuelAgeC2 = array(); $barDuelAgeB = array(); foreach($ages as $age){ //nb vote pour le candidat 1 $voteAge = ORM::factory('vote') ->where('age_id', '=', $age->id) ->and_where('candidat_id', '=', $duel->candidat1_id) ->and_where('duel_id', '=', $duel->id) ->find_all(); $barDuelAgeC1[$age->tranche] = count($voteAge); //nb votes pour le candidat 2 $voteAge = ORM::factory('vote') ->where('age_id', '=', $age->id) ->and_where('candidat_id', '=', $duel->candidat2_id) ->and_where('duel_id', '=', $duel->id) ->find_all(); $barDuelAgeC2[$age->tranche] = count($voteAge); //vote blanc $voteAge = ORM::factory('vote') ->where('age_id', '=', $age->id) ->and_where('candidat_id', '=', '0') ->and_where('duel_id', '=', $duel->id) ->find_all(); $barDuelAgeB[$age->tranche] = count($voteAge); } $this->template->content->barDuelAgeC1 = $barDuelAgeC1; $this->template->content->barDuelAgeC2 = $barDuelAgeC2; $this->template->content->barDuelAgeB = $barDuelAgeB; /* * Stat bar du duel par region */ //duel du moment $regions = ORM::factory('region')->find_all(); $barDuelRegionC1 = array(); $barDuelRegionC2 = array(); $barDuelRegionB = array(); foreach($regions as $region){ //nb vote pour le candidat 1 $voteRegion = ORM::factory('vote') ->where('region_id', '=', $region->id) ->and_where('candidat_id', '=', $duel->candidat1_id) ->and_where('duel_id', '=', $duel->id) ->find_all(); $barDuelRegionC1[$region->nom] = count($voteRegion); //nb votes pour le candidat 2 $voteRegion = ORM::factory('vote') ->where('region_id', '=', $region->id) ->and_where('candidat_id', '=', $duel->candidat2_id) ->and_where('duel_id', '=', $duel->id) ->find_all(); $barDuelRegionC2[$region->nom] = count($voteRegion); //vote blanc $voteRegion = ORM::factory('vote') ->where('region_id', '=', $region->id) ->and_where('candidat_id', '=', '0') ->and_where('duel_id', '=', $duel->id) ->find_all(); $barDuelRegionB[$region->nom] = count($voteRegion); } $this->template->content->barDuelRegionC1 = $barDuelRegionC1; $this->template->content->barDuelRegionC2 = $barDuelRegionC2; $this->template->content->barDuelRegionB = $barDuelRegionB; /* * Stat bar du duel par categoriesociau */ //duel du moment $sociaux = ORM::factory('categoriesocio')->find_all(); $barDuelSociauC1 = array(); $barDuelSociauC2 = array(); $barDuelSociauB = array(); foreach($sociaux as $sociau){ //nb vote pour le candidat 1 $voteSociau = ORM::factory('vote') ->where('categoriesocio_id', '=', $sociau->id) ->and_where('candidat_id', '=', $duel->candidat1_id) ->and_where('duel_id', '=', $duel->id) ->find_all(); $barDuelSociauC1[$sociau->nom] = count($voteSociau); //nb votes pour le candidat 2 $voteSociau = ORM::factory('vote') ->where('categoriesocio_id', '=', $sociau->id) ->and_where('candidat_id', '=', $duel->candidat2_id) ->and_where('duel_id', '=', $duel->id) ->find_all(); $barDuelSociauC2[$sociau->nom] = count($voteSociau); //vote blanc $voteSociau = ORM::factory('vote') ->where('categoriesocio_id', '=', $sociau->id) ->and_where('candidat_id', '=', '0') ->and_where('duel_id', '=', $duel->id) ->find_all(); $barDuelSociauB[$sociau->nom] = count($voteSociau); } $this->template->content->barDuelSociauC1 = $barDuelSociauC1; $this->template->content->barDuelSociauC2 = $barDuelSociauC2; $this->template->content->barDuelSociauB = $barDuelSociauB; $this->template->content->duel = $duel; //$this->template->content->stat = insertStatImage(1,$width,$height,$title,$legend,$data,''); } public function action_visites(){ $this->auto_render = false; if(isset($_POST)){ $startDate = $this->request->post('startDate'); $endDate = $this->request->post('endDate'); }else{ $startDate = false; $endDate = false; } // set the month //$oAnalytics->setMonth($iSelectedMonth, date('Y')); //date range if(!$startDate && !$endDate){ //on envoie les visites du 1er du mois courant à la date d'aujourd'hui $startDate = date('Y-m').'-01'; $endDate = date('Y-m-d'); $data = $this->getVisites($startDate, $endDate); }else{ //tester si on est sur plusieur mois/années $startDateTab = explode("-", $startDate); $endDateTab = explode("-", $endDate); if($startDateTab[1] === $endDateTab[1] && $startDateTab[0] === $endDateTab[0]){ //même mois et année $data = $this->getVisites($startDate, $endDate); }else{ if($startDateTab[0] === $endDateTab[0]){ //même année et pas même mois //on parcours chaque mois $data = array(); for($i = $startDateTab[1]; $i<=$endDateTab[1]; $i++){ if($i === $startDateTab[1]){ $data[$i] = $this->getVisites($startDate, $startDateTab[0].'-'.$i.'-'.date("t", mktime(0, 0, 0, $i, 1, $startDateTab[0]))); }else if($i == $endDateTab[1]){ $data[$i] = $this->getVisites($endDateTab[0].'-'.$endDateTab[1].'-01', $endDate); }else{ $data[$i] = $this->getVisites($endDateTab[0].'-'.$i.'-01', $startDateTab[0].'-'.$i.'-'.date("t", mktime(0, 0, 0, $i, 1, $startDateTab[0]))); } } $dataFormed = array(); foreach($data as $d => $value){ foreach($value as $dkey => $dvalue){ $dataFormed[$dkey.'-'.$d] = $dvalue; } } $data = $dataFormed; }else{ //pas même année $data = array(); } } } $xAxis = '['; $dataGraph = '['; foreach ($data as $key => $value) { $xAxis .= '"' . $key . '",'; $dataGraph .= $value . ','; } //on récupèr eles votes $votes = ORM::factory('vote') ->select(DB::expr('count(id) as nb')) ->where(DB::expr('DATE(jourHeure)'), '<=', DB::expr('CURRENT_DATE')) ->and_where(DB::expr('DATE(jourHeure)'), '>=', $startDate) ->group_by(DB::expr('DATE(jourHeure)')) ->find_all(); $lastWeek = false; $plotBands = '['; $iWeek = 0; $bool = true; if(count($votes)>0){ $nbVotes = '['; foreach($votes as $vote){ $nbVotes .= $vote->nb.','; if(!$lastWeek){ $lastWeek = date('W', strtotime($vote->jourHeure)); }else if($lastWeek != date('W', strtotime($vote->jourHeure))){ if($bool){ $plotBands .= '{ "from" : '.($iWeek-1).'.5, "to" : '.($iWeek+6).'.5, "color" : "rgba(68, 170, 213, .2)" },'; $bool = false; }else{ $bool = true; } $lastWeek = date('W', strtotime($vote->jourHeure)); } $iWeek++; } $nbVotes = substr($nbVotes, 0, strlen($nbVotes) - 1); $plotBands = substr($plotBands, 0, strlen($plotBands) - 1); $nbVotes .= ']'; $plotBands .= ']'; }else{ $nbVotes = '[]'; } //on supprime la dernière virgule $xAxis = substr($xAxis, 0, strlen($xAxis) - 1); $dataGraph = substr($dataGraph, 0, strlen($dataGraph) - 1); $xAxis .= ']'; $dataGraph .= ']'; $dateDepart = new DateTime($startDate); $dateFin = new DateTime($endDate); $nbVotesAndroid = '['; for($dateDepart = $dateDepart ; $dateDepart<=$dateFin; $dateDepart->add(new DateInterval('P1D'))){ $votesAndroid = ORM::factory('vote') ->where(DB::expr('DATE(jourHeure)'), '=', $dateDepart->format('Y-m-d')) ->and_where('source', '=', 'android') ->find_all(); $nbVotesAndroid .= count($votesAndroid).','; //$plotBands = substr($plotBands, 0, strlen($plotBands) - 1); } $nbVotesAndroid = substr($nbVotesAndroid, 0, strlen($nbVotesAndroid) - 1); $nbVotesAndroid .= ']'; /* //on récupèr eles votes mobile android $votesAndroid = ORM::factory('vote') ->select(DB::expr('count(id) as nb')) ->where(DB::expr('DATE(jourHeure)'), '<=', DB::expr('CURRENT_DATE')) ->and_where(DB::expr('DATE(jourHeure)'), '>=', $startDate) ->and_where('source', '=', 'android') ->and_where(DB::expr('DATE(jourHeure)'), '>=', $startDate) ->group_by(DB::expr('DATE(jourHeure)')) ->find_all(); //$lastWeek = false; //$plotBands = '['; $iWeek = 0; $bool = true; if(count($votesAndroid)>0){ $nbVotesAndroid = '['; foreach($votesAndroid as $vote){ $nbVotesAndroid .= $vote->nb.','; } $nbVotesAndroid = substr($nbVotesAndroid, 0, strlen($nbVotesAndroid) - 1); //$plotBands = substr($plotBands, 0, strlen($plotBands) - 1); $nbVotesAndroid .= ']'; //$plotBands .= ']'; }else{ $nbVotesAndroid = '[]'; } //on supprime la dernière virgule $xAxis = substr($xAxis, 0, strlen($xAxis) - 1); $dataGraph = substr($dataGraph, 0, strlen($dataGraph) - 1); $xAxis .= ']'; $dataGraph .= ']'; //*/ $returnData = '{ "xaxis" : '.$xAxis.', "dataGraph" : '.$dataGraph.', "nbVotes" : '.$nbVotes.', "nbVotesAndroid" : '.$nbVotesAndroid.', "plotBands" : '.$plotBands.' }'; echo $returnData; } public function getVisites($startDate = false, $endDate = false){ // construct the class $oAnalytics = new analytics($this->email, $this->password); // get an array with profiles (profileId => profileName) //$aProfiles = $oAnalytics->getProfileList(); //$aProfileKeys = array_keys($aProfiles); // set the profile tot the first account //$oAnalytics->setProfileById($aProfileKeys[0]); // change profileId $oAnalytics->setProfileById('ga:45108597'); //pour resupres $oAnalytics->setDateRange($startDate, $endDate); return $oAnalytics->getVisitors(); } public function action_votesage(){ $this->auto_render = false; //duel du moment $duel = ORM::factory('duel') ->where('dateDebut', '<=', DB::expr('current_date')) ->and_where('dateFin', '>=', DB::expr('current_date')) ->find(); $ages = ORM::factory('age')->find_all(); $barDuelAgeC1 = '['; $barDuelAgeC2 = '['; $barDuelAgeB = '['; $xaxis = '['; foreach($ages as $age){ $xaxis .='"'.$age->tranche.'",'; //nb vote pour le candidat 1 $voteAge = ORM::factory('vote') ->where('age_id', '=', $age->id) ->and_where('candidat_id', '=', $duel->candidat1_id) ->and_where('duel_id', '=', $duel->id) ->find_all(); $barDuelAgeC1 .= count($voteAge).','; //nb votes pour le candidat 2 $voteAge = ORM::factory('vote') ->where('age_id', '=', $age->id) ->and_where('candidat_id', '=', $duel->candidat2_id) ->and_where('duel_id', '=', $duel->id) ->find_all(); $barDuelAgeC2 .= count($voteAge).','; //vote blanc $voteAge = ORM::factory('vote') ->where('age_id', '=', $age->id) ->and_where('candidat_id', '=', '0') ->and_where('duel_id', '=', $duel->id) ->find_all(); $barDuelAgeB .= count($voteAge).','; } $xaxis = substr($xaxis, 0, strlen($xaxis) - 1); $barDuelAgeC1 = substr($barDuelAgeC1, 0, strlen($barDuelAgeC1) - 1); $barDuelAgeC2 = substr($barDuelAgeC2, 0, strlen($barDuelAgeC2) - 1); $barDuelAgeB = substr($barDuelAgeB, 0, strlen($barDuelAgeB) - 1); $xaxis .= ']'; $barDuelAgeC1 .= ']'; $barDuelAgeC2 .= ']'; $barDuelAgeB .= ']'; $returnData = '{ "c1" : "'.$duel->candidat1->nom.' '.$duel->candidat1->prenom.'", "c2" : "'.$duel->candidat2->nom.' '.$duel->candidat2->prenom.'", "duel" : "Du '.$duel->dateDebut.' au '.$duel->dateFin.'", "xaxis" : '.$xaxis.', "barDuelAgeC1" : '.$barDuelAgeC1.', "barDuelAgeC2" : '.$barDuelAgeC2.', "barDuelAgeB" : '.$barDuelAgeB.' }'; echo $returnData; } }