public function plan() { if (isset($_POST[Session::nonceName]) && 1 === wp_verify_nonce($_POST[Session::nonceName], Session::nonceAction)) { global $current_user; wp_get_current_user(); $data = Input::all(); $this->model = new TimeslotModel(); // Get all current bookings // $current_bookings = $this->model->getForCurrentDate( $data['date'], $data['id'] ); // $this->_send_telegram_notications( $current_user, $current_bookings ); // Add new booking to the database $result = $this->model->insert($data, $current_user->ID); echo json_encode($result); exit; } if (!isset($_GET['id'])) { $allVenues = VenueModel::all(); $venuesArray = array(); foreach ($allVenues as $venue) { $venuesArray[$venue['ID']] = $venue; } } else { $venuesArray[$_GET['id']] = VenueModel::details($_GET['id']); } // Get venue details // $venueDetails = VenueModel::details($_GET['id']); // Booked slots for the venue $bookedSlots = TimeslotModel::perVenue(array_keys($venuesArray)); $hours = Config::get('application.timeslots'); $dates = array('monday' => date("Y-m-d", strtotime('next monday', strtotime('previous sunday'))), 'tuesday' => date("Y-m-d", strtotime('next tuesday', strtotime('previous sunday'))), 'wednesday' => date("Y-m-d", strtotime('next wednesday', strtotime('previous sunday'))), 'thursday' => date("Y-m-d", strtotime('next thursday', strtotime('previous sunday'))), 'friday' => date("Y-m-d", strtotime('next friday', strtotime('previous sunday'))), 'saturday' => date("Y-m-d", strtotime('next saturday', strtotime('previous sunday'))), 'sunday' => date("Y-m-d", strtotime('next sunday', strtotime('previous sunday')))); return View::make('pages.venue.plan', array('venues' => $venuesArray, 'booked_slots' => $bookedSlots, 'dates' => $dates, 'hours' => Config::get('application.timeslots'), 'highlight' => '')); }
function get_events_callback() { $filter = isset($_POST['filter']) ? $_POST['filter'] : NULL; if (!isset($_GET['id'])) { $allVenues = VenueModel::all(); $allVenuesArray = array(); foreach ($allVenues as $venue) { $temp = array(); $temp['ID'] = $venue['ID']; $temp['post_title'] = $venue['post_title']; $temp['post_name'] = $venue['post_name']; $allVenuesArray[$venue['ID']] = $temp; } $filteredVenues = VenueModel::all($filter); $filteredVenuesArray = array(); foreach ($filteredVenues as $venue) { $temp = array(); $temp['ID'] = $venue['ID']; $temp['post_title'] = $venue['post_title']; $temp['post_name'] = $venue['post_name']; $filteredVenuesArray[$venue['ID']] = $temp; } } else { $filteredVenuesArray[$_GET['id']] = VenueModel::details($_GET['id']); } // Booked slots for the venue $bookedSlots = TimeslotModel::perVenue(array_keys($filteredVenuesArray)); $slots = array(); foreach ($bookedSlots as $slot) { // if ($count > 25) $count = 0; $date = strtotime($slot['date']); $time_from = $slot['time_from']; $time_from_hour = $time_from; $time_from_minute = '00'; if ($time_from > floor($time_from)) { $time_from_hour = floor($time_from); $time_from_minute = '30'; } $time_to = $slot['time_to']; $time_to_hour = $time_to; $time_to_minute = '00'; if ($time_to > floor($time_to)) { $time_to_hour = floor($time_to); $time_to_minute = '30'; } $title = isset($slot['title']) ? $slot['title'] : NULL; $colours = array('greenLight', 'red', 'blue', 'darken', 'yellow', 'purple', 'orange'); $colour = $colours[rand(0, sizeof($colours) - 1)]; $slot_array = array(); $delete_icon = ''; global $current_user; if ($current_user->ID == $slot['timeslot_user']) { $delete_icon = "<a id='delete-event-link-" . $slot['ID'] . "' style='margin-top: 3px; float: right; margin-right: 4px; z-index: 10;' class='closeon delete-event-link'><i style=\"font-size: 12px; color: white;\" class=\"fa fa-times-circle\"></i></a>"; } $comment_icon = ''; if (isset($slot['title']) && !empty($slot['title'])) { $comment_icon = ' <i class="fa fa-comment"></i>'; } $slot_array['title'] = get_avatar($slot['timeslot_user'], 20) . ' ' . $slot['first_name'] . ' ' . $slot['last_name'] . $comment_icon . $delete_icon; $slot_array['start'] = date("Y-m-d", $date) . 'T' . $time_from_hour . ':' . $time_from_minute . ':00'; $slot_array['end'] = date("Y-m-d", $date) . 'T' . $time_to_hour . ':' . $time_to_minute . ':00'; $slot_array['allDay'] = false; $slot_array['className'] = array('event', 'bg-color-' . $colour, 'event-id-' . $slot['ID']); $slot_array['description'] = $title; $slot_array['slotWidth'] = 50; $slot_array['resourceId'] = 'venue-' . $slot['timeslot_venue']; $slot_array['id'] = $slot['ID']; $slots[] = $slot_array; } echo json_encode(array('slots' => $slots, 'all_venues' => $allVenuesArray, 'filtered_venues' => $filteredVenuesArray)); wp_die(); // this is required to terminate immediately and return a proper response }