gestionTablePrefix = BddConstant::DEFAULT_TABLE_PREFIX ."gestion_"; $this->defaultTablePrefix = BddConstant::DEFAULT_TABLE_PREFIX; $this->pdo = $db; } private function execSQL($sql, $conditions){ $stmt = $this->pdo->prepare($sql); $stmt->execute($conditions); $data = $stmt->fetchAll(\PDO::FETCH_ASSOC); $stmt->closeCursor(); return json_encode($data); } private function execSQLNoData($sql, $conditions){ $stmt = $this->pdo->prepare($sql); $stmt->execute($conditions); $stmt->closeCursor(); } private function execSQLNoJsonReturn($sql, $conditions){ $stmt = $this->pdo->prepare($sql); $stmt->execute($conditions); $data = $stmt->fetchAll(\PDO::FETCH_ASSOC); $stmt->closeCursor(); return $data; } public function getVehicles(){ $sql = "SELECT * FROM ".$this->gestionTablePrefix."vehicle"; return $this->execSQL($sql, []); } public function createDefaultVehicle(){ $date = new DateTime(); $date = $date->format("Y-m-d"); $sql = "INSERT INTO `".$this->gestionTablePrefix."vehicle` ( `purchase_date` ) VALUES (?);"; $this->execSQLNoData($sql, array( $date ) ); } public function getVehiclePurchaseTypes(){ $sql = "SELECT * FROM ".$this->gestionTablePrefix."vehicle_purchase_type"; return $this->execSQL($sql, []); } public function getVehicleCount(){ $count = 0; $sql = "SELECT COUNT(vehicle.id) as vehicle_count FROM ".$this->gestionTablePrefix."vehicle as vehicle;"; $result = $this->execSQLNoJsonReturn($sql,[]); if(!empty($result)){ $count = $result[0]["vehicle_count"]; } return $count; } public function getAvailableVehicles(){ $sql = "SELECT * FROM ".$this->gestionTablePrefix."vehicle as vehicle WHERE vechile.fk_thanato_id IS NULL "; return $this->execSQL($sql, []); } }