1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
<?php
class Stat {
private $resultat_total;
private $reference = NULL;
private $somme = 0;
private $resultat_pour100 = array();
private $bdd;
public $im;
public $white;
public $red;
public $blue;
public function __construct() {
//header("Content-type: image/png");
$this->bdd = new PDO('mysql:host=localhost;dbname=moodle_mdl', 'root', 'test');
$this->im = imagecreatetruecolor(1000, 2000);
$this->white = imagecolorallocate($this->im, 255, 255, 255);
$this->red = imagecolorallocate($this->im, 255, 0, 0);
$this->bleu = imagecolorallocate($this->im, 51, 100, 255);
}
public function creerImage() {
$total = $this->statTotalMouvActivite();
$resultat = $this->getResultatP100();
imagestring($this->$this->im, 30, 30, 30, $total, $this->white);
$depart_x = 0;
$depart_y = 50;
$fin_x = 1000;
$nb_bar = 10;
$decade_y = 40;
$point_y = 0;
foreach ($resultat as $R) {
$chiffre = round($R['chiffre'], 2, PHP_ROUND_HALF_UP);
echo $R['nom'];
imagefilledrectangle($this->im, 0, $point_y, $chiffre * 100, $point_y + 25, $this->red);
imagestring($this->im, 7, 15, $point_y, $chiffre . '%', $this->white);
imagestring($this->im, 10, $chiffre * 100 + 20, $point_y, $R['nom'] . ' viste =>' . $R['brut'] . ' : loggin', $this->bleu);
$point_y = $point_y + $decade_y;
}
imagepng($this->im);
imagedestroy($this->im);
}
public function proportion($resulat) {
return ($resulat * 100) / $this->reference;
}
public function rectificatif($diviseur) {
$this->reference = $this->reference / $diviseur;
}
public function statTotalMouvActivite() {//nombre total de ressource vu ou ajouter
$query = "SELECT COUNT(*) as nb
FROM mdl_user U
INNER JOIN mdl_log L
ON U.id = L.userid
AND L.module = 'user' AND L.action='login'
AND L.time > 1346495708";
$prep = $this->bdd->query($query);
$prep->execute();
$data = $prep->fetch();
$this->reference = $data['nb'];
}
public function statActiviteEcho() {
$query = ("SELECT COUNT(*) as nb ,U.lastname
FROM mdl_user U
INNER JOIN mdl_log L
ON U.id = L.userid
AND L.module = 'user' AND L.action='login'
AND L.time > 1346495708
GROUP BY L.userid order by nb desc");
$bdd = Bdd::getIntance();
$prep = $bdd->query($query);
$prep->execute();
echo '<table>
<th>nombre activitée</th><th>nom</th>';
while ($data = $prep->fetch(PDO::FETCH_OBJ)) {
echo '<tr>
<td> nb => ' . $data->nb . ' <td>
<td>' .
$this->proportion($data->nb)
. '% <td>
<td>' . $data->lastname . '<td></tr>';
$this->somme = $this->proportion($data->nb) + $this->somme;
$this->resultat_pour100[] = array(
"chiffre" => $this->proportion($data->nb),
"nom" => $data->lastname);
}
echo '</table>';
}
public function statActivite() {
$query = ("SELECT COUNT(*) as nb ,U.lastname
FROM mdl_user U
INNER JOIN mdl_log L
ON U.id = L.userid
AND L.module = 'user' AND L.action='login'
AND L.time > 1346495708
GROUP BY L.userid order by nb desc");
$prep = $this->bdd->query($query);
$prep->execute();
while ($data = $prep->fetch(PDO::FETCH_OBJ)) {
$this->resultat_pour100[] = array(
"brut" => $data->nb,
"chiffre" => $this->proportion($data->nb),
"nom" => $data->lastname);
}
}
public function getSommeP() {
return $this->somme;
}
public function getResultatP100() {
return $this->resultat_pour100;
}
}
?> |
Partager