diff --git a/datelist.php b/datelist.php index 898815b0..7b1579e0 100644 --- a/datelist.php +++ b/datelist.php @@ -89,7 +89,7 @@ $scopemenu = array('activity' => get_string('thisscheduler', 'scheduler'), 'course' => get_string('thiscourse', 'scheduler'), 'site' => get_string('thissite', 'scheduler')); - $select = $output->single_select($taburl, 'scope', $scopemenu, $scope, $nothing = array('' => 'choosedots'), null, array('scopeform')); + $select = $output->single_select($taburl, 'scope', $scopemenu, $scope, $nothing = ['' => 'choosedots'], null, ['scopeform']); echo html_writer::div(get_string($scopemenukey, 'scheduler', $select), 'dropdownmenu'); } diff --git a/export.php b/export.php index 6ab526f3..6d89aab5 100644 --- a/export.php +++ b/export.php @@ -94,7 +94,7 @@ $data->includeemptyslots, $pageperteacher, $data->meetingstart, - $data->meetingend + $data->meetingend ); $limit = 20; diff --git a/import/sessions.php b/import/sessions.php index 1ed4c41e..82ef81ab 100644 --- a/import/sessions.php +++ b/import/sessions.php @@ -30,11 +30,11 @@ require_once($CFG->dirroot . '/mod/scheduler/lib.php'); require_once($CFG->dirroot . '/mod/scheduler/locallib.php'); -//ADDED +// ADDED. require_once($CFG->dirroot . '/mod/scheduler/import/sessions_confirm.php'); require_once($CFG->dirroot . '/mod/scheduler/import/sessions_form.php'); require_once($CFG->dirroot . '/mod/scheduler/import/sessions_process.php'); -//END OF ADDED +// END OF ADDED. admin_externalpage_setup('managemodules'); $pagetitle = get_string('importsessions', 'scheduler'); diff --git a/import/sessions_process.php b/import/sessions_process.php index d100d5c4..fe3d1b45 100644 --- a/import/sessions_process.php +++ b/import/sessions_process.php @@ -206,7 +206,7 @@ public function __construct($text = null, $encoding = null, $delimiter = null, $ $session = new stdClass(); $session->course = $this->get_column_data($row, $mapping['course']); - if (empty($session->course)) { + if (empty($session->course)) { \mod_scheduler_notifyqueue::notify_problem(get_string('error:sessioncourseinvalid', 'scheduler')); continue; } @@ -250,25 +250,25 @@ public function __construct($text = null, $encoding = null, $delimiter = null, $ //check if am or pm placed $amsplit = explode(" ",$fromsplit[1]); - if(strlen($amsplit[1]) > 1){ + if (strlen($amsplit[1]) > 1) { //convert to 24 hour $time24 = date("H:i", strtotime($from)); $time24split = explode(':', $time24); $session->sestime['starthour'] = $time24split[0]; $session->sestime['startminute'] = $time24split[1]; - }else{ + } else { $session->sestime['starthour'] = $fromsplit[0]; $session->sestime['startminute'] = $fromsplit[1]; } - + $to = $this->get_column_data($row, $mapping['time']); if (empty($to)) { \mod_scheduler_notifyqueue::notify_problem(get_string('error:sessionendinvalid', 'scheduler')); continue; } - //ADD DURATION + //ADD DURATION $duration = $this->get_column_data($row, $mapping['duration']); if (empty($from)) { \mod_scheduler_notifyqueue::notify_problem(get_string('error:sessionstartinvalid', 'scheduler')); @@ -276,14 +276,14 @@ public function __construct($text = null, $encoding = null, $delimiter = null, $ } $session->duration = clean_param($duration, PARAM_INT); - + $studentname = format_text($this->get_column_data($row, $mapping['studentname']),FORMAT_PLAIN); $studentname = explode(",",$studentname); $firstname = ltrim($studentname[1]," "); $session->studentfirstname = $firstname; $session->studentlastname = $studentname[0]; - + $session->statusset = 0; $sessions[] = $session; @@ -340,7 +340,7 @@ public function import() { $programfield= $DB->get_record_sql($sql,array(),MUST_EXIST); $course = $DB->get_record_sql("SELECT id,shortname FROM mdl_course WHERE id = '{$programfield->instanceid}'"); - if ($course) { + if ($course) { // Check course has activities. if ($DB->record_exists('scheduler', array( 'course' => $course->id @@ -349,10 +349,8 @@ public function import() { $schedulerdb = $DB->get_records('scheduler', array('course' => $course->id, 'name'=>$session->scheduler), 'id', 'id'); $value = reset($schedulerdb); $schedulerdb = current( $schedulerdb); - - if(! empty($schedulerdb)) { - + if (!empty($schedulerdb)) { $scheduler = \scheduler_instance::load_by_id($schedulerdb->id); // Build the session data. @@ -364,16 +362,15 @@ public function import() { // get teacherid from course $teacher = $DB->get_record_sql(" SELECT c.id, c.shortname, u.id, u.username, u.firstname, u.lastname - FROM mdl_course c - LEFT OUTER JOIN mdl_context cx ON c.id = cx.instanceid - LEFT OUTER JOIN mdl_role_assignments ra ON cx.id = ra.contextid AND ra.roleid = '3' - LEFT OUTER JOIN mdl_user u ON ra.userid = u.id + FROM mdl_course c + LEFT OUTER JOIN mdl_context cx ON c.id = cx.instanceid + LEFT OUTER JOIN mdl_role_assignments ra ON cx.id = ra.contextid AND ra.roleid = '3' + LEFT OUTER JOIN mdl_user u ON ra.userid = u.id WHERE cx.contextlevel = '50' AND c.id =".$course->id.";"); //check if action is to add or to delete - if(strtolower($session->action) == "add"){ - + if (strtolower($session->action) == "add") { //format slot for DB add $slot = $this->construct_slot_data_for_add($session,$schedulerdb->id, $teacher->id); @@ -384,17 +381,17 @@ public function import() { 'activity' => $session->studentfirstname." ".$session->studentlastname." for ".userdate($session->sessiondate ) )))); unset($slot); - } - + } + if (! empty($slot)) { - + //Not the best method... with user id would be better $student = $DB->get_record_sql(" SELECT u.id, u.firstname, u.lastname FROM mdl_user u WHERE u.firstname = '".$session->studentfirstname."' AND u.lastname='".$session->studentlastname."';"); //Need a check to see if it is even a student in the course - if($this->student_course($course->id, $student->id)){ + if ($this->student_course($course->id, $student->id)) { //get new slot id $slotid = $this->add_slot($slot,$scheduler); @@ -410,23 +407,23 @@ public function import() { }else{ mod_scheduler_notifyqueue::notify_problem(get_string('error:invalidstudent','scheduler', ['name' => $session->studentfirstname." ".$session->studentlastname, 'course' => $session->course])); } - } - }else if(strtolower($session->action) == "delete"){ + } + }else if (strtolower($session->action) == "delete") { //format slot for DB add $slot = $this->construct_slot_data_for_add($session,$schedulerdb->id, $teacher->id); $slotid = $this->session_exists($slot); // Check if exists if not error. if ($slotid!= false) { - $slot->id=$slotid; + $slot->id = $slotid; $result = $this->delete_slot($slot, $scheduler); unset($slot); - if($result ==true){ + if ($result == true) { $deletecount++; }else{ //throw error as not matching mod_scheduler_notifyqueue::notify_problem($result." ".$session->studentfirstname." ".$session->studentlastname.": ".$session->course.": ".userdate($session->sessiondate )); - } + } } else{ //throw error as not matching mod_scheduler_notifyqueue::notify_problem(get_string('error:invaliddelete', 'scheduler', ['name' => $session->studentfirstname." ".$session->studentlastname, 'course' => $session->course, 'date'=>userdate($session->sessiondate )])); @@ -439,7 +436,7 @@ public function import() { mod_scheduler_notifyqueue::notify_problem(get_string('error:invalidschedulername','scheduler', $session->scheduler)); } } else { - mod_scheduler_notifyqueue::notify_problem(get_string('error:coursehasnoattendance','scheduler', $session->course)); + mod_scheduler_notifyqueue::notify_problem(get_string('error:coursehasnoattendance','scheduler', $session->course)); } } else { mod_scheduler_notifyqueue::notify_problem(get_string('error:coursenotfound', 'scheduler', $session->course)); @@ -463,7 +460,7 @@ public function import() { /** * Check if student is in the course * - * @param int $courseid + * @param int $courseid * @param int $studentid * @return boolean */ @@ -473,10 +470,11 @@ private function student_course($courseid, $studentid) { $students = get_role_users(5 , $context); foreach($students as $student){ - if($student->id == $studentid) - return TRUE; + if ($student->id == $studentid) { + return true; + } } - return FALSE; + return false; } /** @@ -500,7 +498,7 @@ private function session_exists(stdClass $session) { unset($check->hideuntil); $check = (array) $check; - if ($record = $DB->get_record('scheduler_slots', $check, $fields='id', $strictness=IGNORE_MISSING)) { + if ($record = $DB->get_record('scheduler_slots', $check, $fields = 'id', $strictness = IGNORE_MISSING)) { return $record->id; } return false; @@ -508,7 +506,7 @@ private function session_exists(stdClass $session) { /** - * Create the slot to be added to the DB + * Create the slot to be added to the DB * @param stdClass $formdata moodleform - attendance form. * @param int $schedulerid id of scheduler in DB * @param int $teacherid of teacher in scheduler @@ -523,7 +521,7 @@ function construct_slot_data_for_add($formdata, $schedulerid, $teacherid) { $duration = $formdata->duration; $sess = array(); - + $sess = new stdClass(); //Start with schedulerid $sess->schedulerid = $schedulerid; @@ -563,7 +561,7 @@ public function add_slot($sess, $scheduler) { global $DB; $context = get_context_instance(CONTEXT_COURSE, $scheduler->course); - + $sess->id = $DB->insert_record('scheduler_slots', $sess); //Need to add potential file slot into draft area? for notes, appointment notes, teachernote, studentnote @@ -575,7 +573,7 @@ public function add_slot($sess, $scheduler) { // Trigger a session added event. $slotobj = $scheduler->get_slot($sess->id); \mod_scheduler\event\slot_added::create_from_slot($slotobj)->trigger(); - + return $sess->id; } @@ -589,22 +587,22 @@ public function delete_slot($slot, $scheduler) { global $DB; - $context = get_context_instance(CONTEXT_COURSE, $scheduler->course); + $context = get_context_instance(CONTEXT_COURSE, $scheduler->course); $result = true; - //clear calendar + //clear calendar //for teachers calendar $tcal = "SSsup:{$slot->id}:{$scheduler->course}"; $result = $DB->delete_records('event', array('eventtype' => $tcal, "timestart" => $slot->starttime)); - if(!$result){ + if (!$result) { return get_string('error:deletecalendart', 'scheduler'); } //for student calendar $scal = "SSstu:{$slot->id}:{$scheduler->course}"; $result = $DB->delete_records('event', array('eventtype' => $scal,"timestart" => $slot->starttime)); - if(!$result){ + if (!$result) { return get_string('error:deletecalendars', 'scheduler'); } @@ -615,8 +613,8 @@ public function delete_slot($slot, $scheduler) { //need to get all scheduler appointments - $appointments = $DB->get_records("scheduler_appointment", array("slotid"=>$slot->id), $sort='', $fields='*'); - + $appointments = $DB->get_records("scheduler_appointment", array("slotid" => $slot->id), $sort = '', $fields = '*'); + foreach($appointments as $appointment){ //clear appointment storage @@ -633,7 +631,7 @@ public function delete_slot($slot, $scheduler) { //delete slot $result = $DB->delete_records("scheduler_slots", array('id' => $slot->id)); - if(!$result){ + if (!$result) { return get_string('error:deleteslot', 'scheduler'); } return $result; @@ -700,16 +698,16 @@ function construct_appointment_data_for_add($formdata, $slotid, $studentid) { */ public function add_appointment($sess,$context) { global $DB; - + $sess->id = $DB->insert_record('scheduler_appointment', $sess); - + //Need to add potential file slot into draft area? appointment notes, teachernote, studentnote $description = file_save_draft_area_files(0, $context->id, 'mod_scheduler', 'appointmentnote', $sess->id, array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $sess->appointmentnote); - + $description = file_save_draft_area_files(0, $context->id, 'mod_scheduler', 'teachernote', $sess->id, array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), @@ -719,7 +717,7 @@ public function add_appointment($sess,$context) { $context->id, 'mod_scheduler', 'studentnote', $sess->id, array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $sess->studentnote); - + return $sess->id; } diff --git a/renderable.php b/renderable.php index 3b35c0b7..f091cda3 100644 --- a/renderable.php +++ b/renderable.php @@ -54,10 +54,10 @@ class scheduler_slot_table implements renderable { /** @var bool whether to show the attended/not attended icons */ public $showattended = false; - //ADDED + // ADDED. /** @var bool whether to student the option to mark attendance */ public $studentattended = false; - //END OF ADDED + // END OF ADDED. /** @var bool whether to show action buttons (for cancelling) */ public $showactions = true; @@ -87,7 +87,7 @@ class scheduler_slot_table implements renderable { * @param bool $canedit whether the user can edit the slot/appointment * @param bool $canview whether the user can view the appointment * @param bool ADDDED $canattend whether the user can mark if appointment is attended - * @param bool ADDDED $studentcancancel whether the user can cancel an appointment + * @param bool ADDDED $studentcancancel whether the user can cancel an appointment */ public function add_slot(slot $slotmodel, appointment $appointmentmodel, $otherstudents, $cancancel = false, $canedit = false, $canview = false, $canattend = false, $studentcancancel = false) { @@ -106,21 +106,20 @@ public function add_slot(slot $slotmodel, appointment $appointmentmodel, $slot->slotnoteformat = $slotmodel->notesformat; $slot->teacher = $slotmodel->get_teacher(); $slot->appointmentid = $appointmentmodel->id; - //ADDDED - $slot->attendcheck =""; - if($canattend){ //add markable checkbox + // ADDDED. + $slot->attendcheck = ""; + if ($canattend) { // Add markable checkbox. $slot->attendcheck = html_writer::checkbox($appointmentmodel->id, $appointmentmodel->id, $appointmentmodel->studentattend, '', array('class' => 'studentattendselect')); $this->studentattended = TRUE; - } - else{ //display a disable box to show if student marked or not + } else { // Display a disable box to show if student marked or not. $slot->attendcheck = html_writer::checkbox("test", "test", false, '', array('class' => 'studentattendselect', 'disabled' => 'disabled')); $this->studentattended = TRUE; } $slot->studentcancancel = $studentcancancel; - //END of ADDED - + // END of ADDED. + if ($this->scheduler->uses_appointmentnotes()) { $slot->appointmentnote = $appointmentmodel->appointmentnote; $slot->appointmentnoteformat = $appointmentmodel->appointmentnoteformat; @@ -149,7 +148,7 @@ public function add_slot(slot $slotmodel, appointment $appointmentmodel, * @param bool $showgrades whether to show grades * @param moodle_url|null $actionurl action URL for buttons */ - public function __construct(scheduler $scheduler, $showgrades=true, $actionurl = null) { + public function __construct(scheduler $scheduler, $showgrades = true, $actionurl = null) { $this->scheduler = $scheduler; $this->showgrades = $showgrades && $scheduler->uses_grades(); $this->actionurl = $actionurl; @@ -302,7 +301,7 @@ public function add_slot(slot $slotmodel, $canbook, $bookedbyme, $groupinfo, $ot $slot->groupinfo = $groupinfo; $slot->teacher = $slotmodel->get_teacher(); $slot->otherstudents = $otherstudents; - + $this->slots[] = $slot; } diff --git a/studentview.php b/studentview.php index 4b81bc9e..4eb64a05 100644 --- a/studentview.php +++ b/studentview.php @@ -46,10 +46,10 @@ $canseefull = has_capability('mod/scheduler:viewfullslots', $context); -//ADDED Line For Student mark attendance +// ADDED Line For Student mark attendance. $canmarkattend = has_capability('mod/scheduler:studentcanmark', $context); $studentcancancel = has_capability('mod/scheduler:studentcancancel', $context); -//END of ADDED +// END of ADDED. if ($scheduler->is_group_scheduling_enabled()) { $mygroupsforscheduling = groups_get_all_groups($scheduler->courseid, $USER->id, $scheduler->bookingrouping, 'g.id, g.name'); @@ -123,33 +123,36 @@ foreach ($pastslots as $pastslot) { $appointment = $pastslot->get_student_appointment($USER->id); - //ADDDED - //If student can mark attendance - $studentCanMark =false; + // ADDDED. + // If student can mark attendance. + $student_can_mark = false; $moddate = $pastslot->starttime + 172800; - if($canmarkattend && ($pastslot->starttime<= time() && time() <= $moddate)){ - $studentCanMark =true; + if ($canmarkattend && ($pastslot->starttime <= time() && time() <= $moddate)) { + $student_can_mark = true; } - - //END OF ADDED + + // END OF ADDED. if ($pastslot->is_groupslot() && has_capability('mod/scheduler:seeotherstudentsresults', $context)) { $others = new scheduler_student_list($scheduler, true); foreach ($pastslot->get_appointments() as $otherapp) { $othermark = $scheduler->get_gradebook_info($otherapp->studentid); $gradehidden = !is_null($othermark) && ($othermark->hidden <> 0); - $others->add_student($otherapp, $otherapp->studentid == $USER->id, false,false,false, !$gradehidden); + $others->add_student($otherapp, $otherapp->studentid == $USER->id, false, false, false, !$gradehidden); } } else { $others = null; } $hasdetails = $scheduler->uses_studentdata(); - $slottable->add_slot($pastslot, $appointment, $others, false, false, $hasdetails, $studentCanMark, $studentcancancel); + $slottable->add_slot($pastslot, $appointment, $others, false, false, $hasdetails, $student_can_mark, $studentcancancel); } - echo $output->heading(get_string('attendedslots', 'scheduler').": ".count($pastslots)." ".get_string('completed', 'scheduler'), 3); + echo $output->heading(get_string('')); + echo $output->heading( + get_string('attendedslots', 'scheduler') . ": " . count($pastslots) . " " . get_string('completed', 'scheduler') + ); echo $output->render($slottable); } @@ -161,17 +164,17 @@ foreach ($upcomingslots as $slot) { $appointment = $slot->get_student_appointment($USER->id); - //ADDDED - $studentCanMark =false; - //if student has the ability to mark if attend and if the meeting was within the last 24 hrs. - - $moddate = $slot->starttime + 172800; + // ADDDED. + $student_can_mark = false; + // If student has the ability to mark if attend and if the meeting was within the last 24 hrs. + + $moddate = $slot->starttime + 172800; + + if ($canmarkattend && ($slot->starttime<= time() && time() <= $moddate)) { + $student_can_mark = true; + } - if($canmarkattend && ($slot->starttime<= time() && time() <= $moddate)){ - $studentCanMark =true; - } - - //END OF ADDED + // END OF ADDED. if ($slot->is_groupslot() && has_capability('mod/scheduler:seeotherstudentsbooking', $context)) { $showothergrades = has_capability('mod/scheduler:seeotherstudentsresults', $context); @@ -192,10 +195,12 @@ if ($scheduler->is_group_scheduling_enabled()) { $cancancel = $cancancel && ($appointgroup >= 0); } - $slottable->add_slot($slot, $appointment, $others, $cancancel, $canedit, $canview, $studentCanMark, $studentcancancel); + $slottable->add_slot($slot, $appointment, $others, $cancancel, $canedit, $canview, $student_can_mark, $studentcancancel); } - echo $output->heading(get_string('upcomingslots', 'scheduler').": ".count($upcomingslots)." ".get_string('left', 'scheduler'), 3); + echo $output->heading( + get_string('upcomingslots', 'scheduler') . ": " . count($upcomingslots) . " " . get_string('left', 'scheduler') + ); echo $output->render($slottable); }