<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of dealer
*
* @author imasha
*/
class Booking {
public $id;
public $vehicle;
public $start_destination;
public $end_destination;
public $phone;
public function __construct($id) {
if ($id) {
$query = "SELECT * FROM `booking` WHERE `id`=" . $id;
$db = new Database();
$result = mysql_fetch_array($db->readQuery($query));
$this->id = $result['id'];
$this->vehicle = $result['vehicle'];
$this->start_destination = $result['start_destination'];
$this->end_destination = $result['end_destination'];
$this->phone = $result['phone'];
return $this;
}
}
public function create() {
$query = "INSERT INTO `booking` (`vehicle`,`start_destination`,`end_destination`,`phone`) VALUES ('"
. $this->vehicle . "','"
. $this->start_destination . "', '"
. $this->end_destination . "', '"
. $this->phone . "')";
$db = new Database();
$result = $db->readQuery($query);
if ($result) {
$last_id = mysql_insert_id();
return $this->__construct($last_id);
} else {
return FALSE;
}
}
public function all() {
$query = "SELECT * FROM `booking` ";
$db = new Database();
$result = $db->readQuery($query);
$array_res = array();
while ($row = mysql_fetch_array($result)) {
array_push($array_res, $row);
}
return $array_res;
}
public function update() {
$query = "UPDATE `booking` SET "
. "`vehicle` ='" . $this->vehicle . "', "
. "`start_destination` ='" . $this->start_destination . "', "
. "`end_destination` ='" . $this->end_destination . "', "
. "`phone` ='" . $this->phone . "', "
. "WHERE `id` = '" . $this->id . "'";
$db = new Database();
$result = $db->readQuery($query);
if ($result) {
return $this->__construct($this->id);
} else {
return FALSE;
}
}
public function delete() {
// $this->deletePhotos();
// unlink(Helper::getSitePath() . "upload/jobsearch/" . $this->image_name);
$query = 'DELETE FROM `booking` WHERE id="' . $this->id . '"';
$db = new Database();
return $db->readQuery($query);
}
// public function deletePhotos() {
//
//
//
// $ACTIVITY_PHOTO = new ActivitiesPhoto(NULL);
//
//
//
// $allPhotos = $ACTIVITY_PHOTO->getActivitiesPhotosById($this->id);
//
//
//
// foreach ($allPhotos as $photo) {
//
//
//
// $IMG = $ACTIVITY_PHOTO->image_name = $photo["image_name"];
//
// unlink(Helper::getSitePath() . "upload/activity/gallery/" . $IMG);
//
// unlink(Helper::getSitePath() . "upload/activity/gallery/thumb/" . $IMG);
//
//
//
// $ACTIVITY_PHOTO->id = $photo["id"];
//
// $ACTIVITY_PHOTO->delete();
// }
// }
// public function arrange($key, $img) {
//
// $query = "UPDATE `jobsearch` SET `queue` = '" . $key . "' WHERE id = '" . $img . "'";
//
// $db = new Database();
//
// $result = $db->readQuery($query);
//
// return $result;
// }
}
|