Exemplo n.º 1
0
 public static function myReservations($userid = null)
 {
     global $DB, $USER, $OUTPUT;
     if ($userid == null) {
         $user_id = $USER->id;
     } else {
         $user_id = $userid;
     }
     $table = new html_table();
     $table->head = array(get_string('date', 'local_bookingrooms'), get_string('campus', 'local_bookingrooms'), get_string('building', 'local_bookingrooms'), get_string('rooms', 'local_bookingrooms'), get_string('module', 'local_bookingrooms'), get_string('confirm', 'local_bookingrooms'), get_string('cancel', 'local_bookingrooms'));
     $reservas = $DB->get_records('bookingrooms_reservas', array('student_id' => $user_id, 'active' => '1'));
     foreach ($reservations as $reservation) {
         if ($userid == null) {
             $con_url = new moodle_url('myreservations.php', array('action' => 'confirm', 'idreservation' => $reservation->id, 'sesskey' => sesskey()));
             //('confirm.php?idconfirmar='. $reservation->id);
             $del_url = new moodle_url('myreservations.php', array('action' => 'cancel', 'idreservation' => $reservation->id, 'sesskey' => sesskey()));
         } else {
             $con_url = new moodle_url('usersreservation.php', array('action' => 'confirm', 'idreservation' => $reservation->id, 'sesskey' => sesskey()));
             //('confirm.php?idconfirm='. $reservation->id);
             $del_url = new moodle_url('usersreservation.php', array('action' => 'cancel', 'idreservation' => $reservation->id, 'sesskey' => sesskey()));
         }
         $room = $DB->get_record('bookingrooms_rooms', array('id' => $reservation->rooms_id));
         $building = $DB->get_record('bookingrooms_buildings', array('id' => $room->buildings_id));
         $campus = $DB->get_record('bookingrooms_campus', array('id' => $building->campus_id));
         $module = $DB->get_record('bookingrooms_modules', array('id' => $reservation->module));
         $hourmodule = hour_module($reservation->module);
         $actualtime = time();
         $starttime = $hourmodule[0];
         $endtime = $hourmodule[1];
         $starttime = $starttime->modify('-5 minutes');
         $before = $starttime->getTimestamp();
         $starttime = $starttime->modify('+20 minutes');
         $despues = $starttime->getTimestamp();
         $starttime = $starttime->modify('-80 minutes');
         $cancelhour = $starttime->getTimestamp();
         if ($reservation->confirm) {
             $confaction_reservation = 'Confirm';
         } else {
             if ($actualtime < $after && $actualtime > $before) {
                 $confurl_reservation = $con_url;
                 $conficon_reservation = new pix_icon('i/valid', get_string('confirm', 'local_bookingrooms'));
                 $confaction_reservation = $OUTPUT->action_icon($confurl_reservation, $conficon_reservation);
             } else {
                 if ($actualtime > $after && $reservation->confirm == 0) {
                     $confaction_reservation = get_string('thetimetoconfirm', 'local_bookingrooms');
                 } else {
                     $confaction_reservation = $OUTPUT->pix_icon('t/block', get_string('stillcannotconfirm', 'local_bookingrooms'));
                 }
             }
         }
         if ($actualtime < $cancelhour) {
             $delurl_reservation = $del_url;
             $delicon_reservation = new pix_icon('i/invalid', get_string('cancel', 'local_bookingrooms'));
             $delaction_reservation = $OUTPUT->action_icon($delurl_reservation, $delicon_reservation, new confirm_action(get_string('areyousuretocancel', 'local_bookingrooms')));
         } else {
             $delaction_reservation = get_string('timetocancel', 'local_bookingrooms');
         }
         $table->data[] = array($reservation->date_reservation, $campus->nome, $building->name, $room->name, $module->name_module . "<br>(" . $module->hour_start . " - " . $module->hour_end . ")", $confaction_reservation, $delaction_reservatio);
     }
     $table->align = array('center', 'center', 'center', 'center', 'center', 'center', 'center');
     $table->size = array('12%', '16%', '14%', '14%', '16%', '14%', '14%');
     return $table;
 }
Exemplo n.º 2
0
 public static function myReservations($userid = null)
 {
     global $DB, $USER, $OUTPUT;
     if ($userid == null) {
         $user_id = $USER->id;
     } else {
         $user_id = $userid;
     }
     $table = new html_table();
     $table->head = array(get_string("date", "local_bookingrooms"), get_string("campus", "local_bookingrooms"), get_string("building", "local_bookingrooms"), get_string("rooms", "local_bookingrooms"), get_string("module", "local_bookingrooms"), get_string("confirm", "local_bookingrooms"), get_string("cancel", "local_bookingrooms"));
     $reservations = $DB->get_records("bookingrooms_reservas", array("student_id" => $user_id, "active" => "1"));
     foreach ($reservations as $reservation) {
         if ($userid == null) {
             $con_url = new moodle_url("myreservations.php", array("action" => "confirm", "idreservation" => $reservation->id, "sesskey" => sesskey()));
             //("confirm.php?idconfirmar=". $reservation->id);
             $del_url = new moodle_url("myreservations.php", array("action" => "cancel", "idreservation" => $reservation->id, "sesskey" => sesskey()));
         } else {
             $con_url = new moodle_url("usersreservation.php", array("action" => "confirm", "idreservation" => $reservation->id, "sesskey" => sesskey()));
             //("confirm.php?idconfirm=". $reservation->id);
             $del_url = new moodle_url("usersreservation.php", array("action" => "cancel", "idreservation" => $reservation->id, "sesskey" => sesskey()));
         }
         $room = $DB->get_record("bookingrooms_rooms", array("id" => $reservation->rooms_id));
         $building = $DB->get_record("bookingrooms_buildings", array("id" => $room->buildings_id));
         $campus = $DB->get_record("bookingrooms_campus", array("id" => $building->campus_id));
         $module = $DB->get_record("bookingrooms_modules", array("id" => $reservation->module));
         //find the start and end time of the module
         $hourmodule = hour_module($reservation->module);
         $starttime = $hourmodule[0];
         $endtime = $hourmodule[1];
         //find the date of reserve
         $datereservation = $reservation->date_reserve;
         //use the same steps for time before, time after and time to cancel the confirmation
         $actualtime = time();
         $actualtimeanddate = date("Y-m-d H:i:s", $actualtime);
         //create the start time of the confirmation (5 min before the module)
         $starttime = $starttime->modify("-5 minutes");
         $timebefore = $starttime->getTimestamp();
         //get the start time of the confirmation
         $timebeforehour = date("H:i:s", $timebefore);
         // create a variable with reservation date and confirmation time
         $timebeforedateandhour = $datereservation . " " . $timebeforehour;
         //create the end time of the confirmation (20 min after the start module)
         $starttime = $starttime->modify("+20 minutes");
         $timeafter = $starttime->getTimestamp();
         $timeafterhour = date("H:i:s", $timeafter);
         $timeafterdateandhour = $datereservation . " " . $timeafterhour;
         //create the cancel time of reservation (until 120 min before the module)
         $starttime = $starttime->modify("-80 minutes");
         $timecancel = $starttime->getTimestamp();
         $timecancelhour = date("H:i:s", $timecancel);
         $timecanceldateandhour = $datereservation . " " . $timecancelhour;
         //check if it confirmed the room
         if ($reservation->confirm) {
             $confaction_reservation = get_string("confirm", "local_bookingrooms");
         } else {
             if ($actualtimeanddate < $timeafterdateandhour && $actualtimeanddate > $timebeforedateandhour) {
                 $confurl_reservation = $con_url;
                 $conficon_reservation = new pix_icon("i/valid", get_string("confirm", "local_bookingrooms"));
                 $confaction_reservation = $OUTPUT->action_icon($confurl_reservation, $conficon_reservation);
             } else {
                 if ($actualtimeanddate > $timeafterdateandhour && $reservation->confirm == 0) {
                     $confaction_reservation = get_string("thetimetoconfirm", "local_bookingrooms");
                 } else {
                     $confaction_reservation = $OUTPUT->pix_icon("t/block", get_string("stillcannotconfirm", "local_bookingrooms"));
                 }
             }
         }
         //check the time to cancel the reserve
         if ($actualtimeanddate < $timecanceldateandhour) {
             $delurl_reservation = $del_url;
             $delicon_reservation = new pix_icon("i/invalid", get_string("cancel", "local_bookingrooms"));
             $delaction_reservation = $OUTPUT->action_icon($delurl_reservation, $delicon_reservation, new confirm_action(get_string("areyousuretocancel", "local_bookingrooms")));
         } else {
             $delaction_reservation = get_string("timetocancel", "local_bookingrooms");
         }
         $table->data[] = array($datereservation, $campus->name, $building->name, $room->name, $module->name_module . "<br>(" . $module->hour_start . " - " . $module->hour_end . ")", $confaction_reservation, $delaction_reservation);
     }
     $table->align = array("center", "center", "center", "center", "center", "center", "center");
     $table->size = array("12%", "16%", "14%", "14%", "16%", "14%", "14%");
     return $table;
 }