public static function query_all_restaurants()
 {
     $sql = 'select * from restaurants';
     $query_tool = new DataAccessLayer();
     $results = $query_tool->query($sql);
     if ($results->num_rows > 0) {
         return $results;
     } else {
         throw new Exception("No registered restaurant found or database error!");
     }
 }
 public static function find_by_restaurant_id($restaurant_id)
 {
     if ($restaurant_id) {
         $sql = 'select * from reservations where restaurant_id = ' . $restaurant_id;
         $query_tool = new DataAccessLayer();
         $results = $query_tool->query($sql);
         if ($results->num_rows > 0) {
             return $results;
         } else {
             return null;
         }
     }
 }
/**
 * [newest_restaurants description]
 * @param  [type] $number [description]
 */
function newest_restaurants($number = null)
{
    if ($number) {
        $query_tool = new DataAccessLayer();
        $sql = 'select restaurant_id, name, cuisine_type, rating from restaurants where approved = 1 order by restaurant_id DESC limit 0, ' . $number;
        $newest_three_restaurant = $query_tool->query($sql);
        if ($newest_three_restaurant->num_rows > 0) {
            while ($row = $newest_three_restaurant->fetch_row()) {
                render_newest_restaurant($row);
            }
            echo '<div class="clearfix"></div>';
        }
    }
}
 } else {
     if ($_POST['operation'] == 'make_reservation') {
         // var_dump($_POST);
         $time_to_slots_hash = array('05:00PM - 06:00PM' => 'slot_5_6', '06:00PM - 07:00PM' => 'slot_6_7', '07:00PM - 08:00PM' => 'slot_7_8', '08:00PM - 09:00PM' => 'slot_8_9', '09:00PM - 10:00PM' => 'slot_9_10');
         $time_to_24_hours = array('05:00PM - 06:00PM' => 17, '06:00PM - 07:00PM' => 18, '07:00PM - 08:00PM' => 19, '08:00PM - 09:00PM' => 20, '09:00PM - 10:00PM' => 21);
         $user_email = $_POST['user_email'];
         $user_phone = $_POST['user_phone'];
         if (isset($_POST['guest_reservation']) && $_POST['guest_reservation'] == 'true') {
             $fields = array('restaurant_id' => $_POST['restaurant_id'], 'people_size' => $_POST['people_size'], 'date_of_reservation' => $_POST['date'], 'time_of_reservation' => $time_to_24_hours[$_POST['time']], 'effective' => 1, 'guest_info' => $_POST['guest_info']);
         } else {
             $fields = array('user_id' => $_POST['user_id'], 'restaurant_id' => $_POST['restaurant_id'], 'people_size' => $_POST['people_size'], 'date_of_reservation' => $_POST['date'], 'time_of_reservation' => $time_to_24_hours[$_POST['time']], 'effective' => 1);
         }
         try {
             $query_tool = new DataAccessLayer();
             $sql = 'select ' . $time_to_slots_hash[$_POST['time']] . ', date, restaurant_id from time_slots_capacity where date = "' . $fields['date_of_reservation'] . '" and restaurant_id = "' . $fields['restaurant_id'] . '"';
             $results = $query_tool->query($sql);
             if ($results->num_rows > 0) {
                 $row = $results->fetch_row();
                 $previous_capacity = $row[0];
                 if ($previous_capacity >= $fields['people_size']) {
                     $new_reservation = new Reservation();
                     $new_reservation->create($fields);
                     $next_capacity = $previous_capacity - $fields['people_size'];
                     $sql = 'update time_slots_capacity set ' . $time_to_slots_hash[$_POST['time']] . ' = ' . $next_capacity . ' where date = "' . $fields['date_of_reservation'] . '" and restaurant_id = "' . $fields['restaurant_id'] . '"';
                     if ($query_tool->query($sql)) {
                         // send email to user to confirm reservation
                         $restaurant = new Restaurant();
                         $restaurant->find($fields['restaurant_id']);
                         $mail = Mail::getInstance();
                         $mailto = $_POST['user_email'];
                         $subject = 'FineTable - Restaurant Reservation Confirmation!';
$totalRecsProcessed = 0;
$currentRecord = 0;
// SHOW ITEM BY DEFAULT on Posterous Website
$private_item = 1;
echo "Welcome. This process will attempt to move your items from SweetCron to Posterous<br/><br/>";
$db = new DataAccessLayer(DB_URL, DB_USER, DB_PASSWORD, DB_NAME);
$db->debug = false;
$totalRows = $db->nonQuery("select * FROM items where item_status = 'publish' limit 0,10");
while ($totalRows > 0) {
    $currentRecord = 0;
    if ($totalRecsProcessed > 100) {
        break;
    }
    echo "<h1>Processing " . $totalRecordsProcessed . " through " . $totalRecordsProcessed + $batchSize . "</h1>";
    $sql = "SELECT f.feed_title, f.feed_url, f.feed_domain, f.feed_icon, f.feed_data, i.* FROM items i " . " inner join feeds f on f.feed_id = i.item_feed_id " . " where i.item_status = 'publish' " . " limit 0," . $batchSize;
    $items = $db->query($sql);
    while ($obj = $items->fetch_object()) {
        $dmp = unserialize($obj->item_data);
        // load up the serialized item_data
        echo "<h3>Importing " . $obj->ID . " - " . $obj->item_title . "</h3>";
        echo "Original Date: " . $obj->item_date . "<br/>";
        echo "Item Title: " . $dmp["title"] . "<br/>";
        $itemContent = "From: " . $obj->feed_domain . "<br/>" . $dmp["content"] . "<br/>Permalink: <a href='" . $obj->item_permalink . "'>" . $obj->item_permalink . "</a><br/>";
        // Posterous values to go into curl request
        $values = array('site_id' => IMPORT_SITE_ID, 'title' => $obj->item_title, 'body' => $itemContent, 'date' => date("M d Y H:i:s", $obj->item_date), 'source' => $obj->feed_title, 'sourceLink' => $obj->item_permalink, 'private' => $private_item);
        // get tags from the database.
        // i concatenate them here as per API spec
        $itemTags = "";
        $tags = $db->query("SELECT GROUP_CONCAT(DISTINCT name SEPARATOR ',') as tags FROM tags where tag_id in (select tag_id from tag_relationships where item_id = " . $obj->ID . ")");
        // there has to be a better way to pull a single item from a result set than doing a loop
        // TO BE RESOLVED later
 public static function get_all_reviews_by_restaurant($restaurant_id)
 {
     if ($restaurant_id) {
         $sql = 'select * from reviews where restaurant_id = ' . $restaurant_id;
         // echo $sql;
         $query_tool = new DataAccessLayer();
         $results = $query_tool->query($sql);
         if ($results->num_rows > 0) {
             return $results;
         } else {
             return null;
         }
     }
 }