Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.24 KB | None | 0 0
  1. <?php
  2.  
  3. class Db{
  4.     private $host = 'localhost';
  5.     private $user = 'root';
  6.     private $pass = '';
  7.     private $dbname = 'users';
  8.  
  9.     private $dbh;
  10.     private $error;
  11.     private $stmt;
  12.     private $json;
  13.     private $res = array();
  14.     public function __construct(){
  15.         $dsn = 'mysql:host='. $this->host . ';dbname=' . $this->dbname;
  16.  
  17.         $options = array(PDO::ATTR_PERSISTENT=>true,PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION);
  18.        
  19.         try{
  20.             $this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
  21.         }catch(PDOEXCEPTION $e)
  22.         {
  23.             echo 'ERROR : ' . $e->getMessage();
  24.         }
  25.  
  26.     }
  27.     public function query($query, $get){
  28.  
  29.         $this->stmt = $this->dbh->prepare($query);
  30.         $this->stmt->execute(array(':id' => $get));
  31.         //for($i = 0; $i<count($data); $i++)
  32.         //  $data[$i]. '<br/>';
  33.     }
  34.     public function rework(){
  35.         $result = $this->stmt->fetchAll(PDO::FETCH_ASSOC);
  36.         //print_r($result);
  37.         /*foreach ($result as $row) {
  38.              $this->data = array('project name: ' => $row['projectName'], 'tsis: ' => gmdate("H:i",$row['timeSpentInSeconds']), 'logTime: ' => gmdate("d-m-Y",$row['logTime']));
  39.         }*/
  40.         // NAMES DATAS--------------------------
  41.         foreach ($result as $name){
  42.             $names [] = $name['projectName'];
  43.             $datas [] = gmdate("d-m-Y",$name['logTime']);
  44.         }
  45.         $uniqueDatas = array_unique($datas);
  46.         foreach($uniqueDatas as $val){
  47.             $e = $val;
  48.             $r = [];
  49.             foreach($result as $value){
  50.                 if($e == gmdate("d-m-Y",$value['logTime'])){
  51.                     $r[] = round($value['timeSpentInSeconds']/60/60, 1);
  52.                 }else{
  53.                     $r[] = 0;
  54.                 }
  55.             }
  56.             $values[] = array('label' => $e, 'values' => $r);
  57.         }
  58.  
  59.         $this->res = array('label' => $names, 'values' => $values);
  60.         echo json_encode($this->res);
  61.     }
  62.  
  63.  
  64.     public function __get($d){
  65.         return $this->res;
  66.     }
  67.     //('project name: ' . $row['projectName'] . ' tsis: ' . gmdate("H:i",$row['timeSpentInSeconds']) . ' log time: ' . gmdate("d-m-Y",$row['logTime']))
  68. }
  69. $get = $_GET['id'];
  70. $d = array();
  71. $values;
  72. $db = new Db();
  73.  
  74. $db->query(stripslashes('SELECT `projectName`, `timeSpentInSeconds` , `logTime` FROM `projects`, `timesheets` WHERE `timesheets`.`teamuser_id`= :id AND `timesheets`.`project_id`=`projects`.`id`'), $get);
  75. $db->rework();
  76. $values = json_encode($db->__get($d));
  77. // echo $values;
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement