All pastes #994905 Raw Edit

Something

public text v1 · immutable
#994905 ·published 2008-04-23 18:56 UTC
rendered paste body
/**
	 * Gets All of the venues for this PackageOption
	 * 
	 * // TODO: this function is stupid
	 *
	 * @param string $date
	 * @return array of related Venue objects
	 */
	function getAllVenues() {
		$dao = new DAO();
		$query = "SELECT ven.* FROM venues ven
					LEFT JOIN optionvenues ov ON ov.venue_id=ven.id
					WHERE ven.option_id='$this->id'
					ORDER BY rank";
		$dao->exec($query);
		if ($dao->error_message != 0) {
			$this->errors[] = "Error getting venues: " . $dao->error_message;
			return null;
		}
		
		//$sql = "SELECT venue_id FROM optionvenues 
		//		WHERE option_id = '" . $this->id . "'
		//		ORDER BY rank";
		//$dao->query($sql);
		$venue_list = array();		
		
		while($row = $dao->getObject()) {
		//	$venue = new Venue();
		//	$venue->get($row->venue_id);	
			array_push($venue_list, $venue);
		}
		return $venue_list;
	}

/**
	 * Vinny says "This function is not suppose to be used. If you want to 
	 * check the avaiability of a venue use isAvailable()"
	 *
	 * @param string $date
	 * @param string $time
	 * @param int $num_people
	 * @return true if available, false if not
	 */
	function isDateAvailable($date='', $time='', $num_people) {
		$dao  = new DAO();
		$dao2 = new DAO();
		
		
		$sql = "SELECT * FROM esp_venue_availability WHERE date = '" . $date . "' AND venue_id = " . $this->id;					
		$dao->query($sql);
		if(!$dao->numRows()) {
			$week_day = strtolower(date("D", strtotime($date)));
			$sql = "SELECT * FROM def_venue_availability WHERE day = '" . $week_day . "' AND venue_id = " . $this->id;
			$dao->query($sql);
		}

		if($dao->numRows()) {
			// Checks to see if the reservation time will be at least half-hour before the slot end time
			$time_arr = explode(":", $time);
			$time_minute = $time_arr[1] - 30;
			if($time_minute < 0) {
				$extra_hour = -1;
				$time_minute = 60 + $time_minute;
			} else {
				$extra_hour = 0;
			}			
			$time_hour = ($time_arr[0] + $extra_hour) > 0 ? ($time_arr[0] + $extra_hour) : 24 + ($time_arr[0] + $extra_hour);		
			$time_end = str_pad($time_hour,2,'0',STR_PAD_LEFT) . ":" . str_pad($time_minute,2,'0',STR_PAD_LEFT);
			$row = $dao->getObject();
			$available_slot = 0;
			
			// Fix problems when time is after 24:00
			// Checks to see which time slot this reservation matches
			for($i = 1; $i <= 5; $i++) {
				$start_time = "start_time".$i;
				$end_time = "end_time".$i;
				$start_time = explode(":",$row->$start_time);
				$end_time = explode(":",$row->$end_time);
				if($start_time[0] < 10) {
					$start_time[0] += 24;
				}
				if($end_time[0] < 10) {
					$end_time[0] += 24;
				}
				$start_time = str_pad($start_time[0],2,'0',STR_PAD_LEFT) . ":" . str_pad($start_time[1],2,'0',STR_PAD_LEFT);
				$end_time   = str_pad($end_time[0]  ,2,'0',STR_PAD_LEFT) . ":" . str_pad($end_time[1],2,'0',STR_PAD_LEFT);
				if($time >= $start_time && $time <= $end_time && $time_end <= $end_time) {
					$available_slot = "total".$i;
				}
				
			}
			// Check to see if the time matches any of the available slots
			if($available_slot) {
				
				$max_available = $row->$available_slot;
				$sql = "SELECT SUM(num_people) AS total_people FROM venuebookings 
								WHERE 
								venue_id = " . $this->id . " AND 
								time_arrive >= '" . $time . "' AND
								time_arrive <= '" . $time . "' ";
				$dao2->query($sql);
				$row2 = $dao2->getObject();
				$booked_places = $row2->total_people;
				// Checks to see if the total booked places + the number of people we want to put thet doesn't exceed to total available
				
				if($max_available - $booked_places - $num_people >= 0) {
					return true;
				}
				else {
					return false;
				}									
			}
			else {
				return false;
			}
		} 
		else {
			return false;
		}
	}