Beispiel #1
0
 /**
  * Get the user dashboard report view.
  *
  * @uses $CFG, $CURMAN
  * @param none
  * @return string The HTML for the dashboard report.
  */
 function get_dashboard()
 {
     global $CFG, $CURMAN;
     require_once CURMAN_DIRLOCATION . '/lib/curriculumstudent.class.php';
     //needed for AJAX calls
     require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_connection', "{$CFG->wwwroot}/curriculum/js/util.js", "{$CFG->wwwroot}/curriculum/js/dashboard.js"), true);
     if (optional_param('tab', '', PARAM_CLEAN) == 'archivedlp') {
         $tab = 'archivedlp';
         $show_archived = 1;
     } else {
         $tab = 'currentlp';
         $show_archived = 0;
     }
     $content = '';
     $archive_var = '_elis_curriculum_archive';
     $totalcourses = 0;
     $totalcurricula = 0;
     $completecourses = 0;
     $curriculas = array();
     $classids = array();
     $sql = 'SELECT curstu.id, curstu.curriculumid as curid, cur.name as name
               FROM ' . $CURMAN->db->prefix_table(CURASSTABLE) . ' curstu
               JOIN ' . $CURMAN->db->prefix_table(CURTABLE) . ' cur
                 ON cur.id = curstu.curriculumid
              WHERE curstu.userid = \'' . $this->id . '\' ORDER BY cur.priority ASC, cur.name ASC';
     if ($usercurs = get_records_sql($sql)) {
         foreach ($usercurs as $usercur) {
             // Check if this curricula is set as archived and whether we want to display it
             $crlm_context = get_context_instance(context_level_base::get_custom_context_level('curriculum', 'block_curr_admin'), $usercur->curid);
             $data_array = field_data::get_for_context_and_field($crlm_context, $archive_var);
             $crlm_archived = 0;
             if (is_array($data_array) && !empty($data_array)) {
                 foreach ($data_array as $data_key => $data_obj) {
                     $crlm_archived = !empty($data_obj->data) ? 1 : 0;
                 }
             }
             if ($show_archived == $crlm_archived) {
                 $totalcurricula++;
                 $curriculas[$usercur->curid]['id'] = $usercur->curid;
                 $curriculas[$usercur->curid]['name'] = $usercur->name;
                 $data = array();
                 if ($courses = curriculumcourse_get_listing($usercur->curid, 'curcrs.position, crs.name', 'ASC')) {
                     foreach ($courses as $course) {
                         $totalcourses++;
                         $course_obj = new course($course->courseid);
                         $coursedesc = $course_obj->syllabus;
                         if ($cdata = student_get_class_from_course($course->courseid, $this->id)) {
                             foreach ($cdata as $classdata) {
                                 if (!in_array($classdata->id, $classids)) {
                                     $classids[] = $classdata->id;
                                 }
                                 if ($classdata->completestatusid == STUSTATUS_PASSED) {
                                     $completecourses++;
                                 }
                                 if ($mdlcrs = moodle_get_course($classdata->id)) {
                                     $coursename = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $mdlcrs . '">' . $course->coursename . '</a>';
                                 } else {
                                     $coursename = $course->coursename;
                                 }
                                 $data[] = array($coursename, $coursedesc, $classdata->grade, $classdata->completestatusid == STUSTATUS_PASSED ? get_string('yes') : get_string('no'), $classdata->completestatusid == STUSTATUS_PASSED && !empty($classdata->completetime) ? date('M j, Y', $classdata->completetime) : get_string('na', 'block_curr_admin'));
                             }
                         } else {
                             $data[] = array($course->coursename, $coursedesc, 0, get_string('no'), get_string('na', 'block_curr_admin'));
                         }
                     }
                 }
                 $curriculas[$usercur->curid]['data'] = $data;
             } else {
                 // Keep note of the classid's regardless if set archived or not for later use in determining non-curricula courses
                 if ($courses = curriculumcourse_get_listing($usercur->curid, 'curcrs.position, crs.name', 'ASC')) {
                     foreach ($courses as $course) {
                         if ($cdata = student_get_class_from_course($course->courseid, $this->id)) {
                             foreach ($cdata as $classdata) {
                                 if (!in_array($classdata->id, $classids)) {
                                     $classids[] = $classdata->id;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Show different css for IE below version 8
     if (check_browser_version('MSIE', 7.0) && !check_browser_version('MSIE', 8.0)) {
         // IEs that are lower than version 8 do not get the float because it messes up the tabs at the top of the page for some reason
         $float_style = 'text-align:right;';
     } else {
         // Sane browsers get the float tag
         $float_style = 'text-align:right; float:right;';
     }
     // Tab header
     $field_exists = field::get_for_context_level_with_name('curriculum', $archive_var);
     if (!empty($field_exists)) {
         $tabrow = array();
         $tabrow[] = new tabobject('currentlp', $CFG->wwwroot . '/curriculum/index.php?tab=currentlp', get_string('tab_current_learning_plans', 'block_curr_admin'));
         $tabrow[] = new tabobject('archivedlp', $CFG->wwwroot . '/curriculum/index.php?tab=archivedlp', get_string('tab_archived_learning_plans', 'block_curr_admin'));
         $tabrows = array($tabrow);
         print_tabs($tabrows, $tab);
     }
     $content .= print_heading_block(get_string('learningplanwelcome', 'block_curr_admin', fullname($this)), '', true);
     if ($totalcurricula === 0) {
         $blank_lang = $tab == 'archivedlp' ? 'noarchivedplan' : 'nolearningplan';
         $content .= '<br /><center>' . get_string($blank_lang, 'block_curr_admin') . '</center>';
     }
     // Load the user preferences for hide/show button states
     if ($collapsed = get_user_preferences('crlm_learningplan_collapsed_curricula')) {
         $collapsed_array = explode(',', $collapsed);
     } else {
         $collapsed = '';
         $collapsed_array = array();
     }
     $content .= '<input type="hidden" name="collapsed" id="collapsed" value="' . $collapsed . '">';
     if (!empty($usercurs)) {
         foreach ($usercurs as $usercur) {
             if (!isset($curriculas[$usercur->curid])) {
                 continue;
             }
             $curricula = $curriculas[$usercur->curid];
             $table = new stdClass();
             $table->head = array(get_string('class', 'block_curr_admin'), get_string('description', 'block_curr_admin'), get_string('score', 'block_curr_admin'), get_string('completed_label', 'block_curr_admin'), get_string('date', 'block_curr_admin'));
             $table->data = $curricula['data'];
             $curricula_name = empty($CURMAN->config->disablecoursecatalog) ? '<a href="index.php?s=crscat&section=curr&showcurid=' . $curricula['id'] . '">' . $curricula['name'] . '</a>' : $curricula['name'];
             $header_curr_name = get_string('learningplanname', 'block_curr_admin', $curricula_name);
             if (in_array($curricula['id'], $collapsed_array)) {
                 $button_label = get_string('showcourses', 'block_curr_admin');
                 $extra_class = ' hide';
             } else {
                 $button_label = get_string('hidecourses', 'block_curr_admin');
                 $extra_class = '';
             }
             $heading = '<div class="clearfix"></div>' . '<div style="' . $float_style . '">' . '<script id="curriculum' . $curricula['id'] . 'script" type="text/javascript">toggleVisibleInitWithState("curriculum' . $curricula['id'] . 'script", "curriculum' . $curricula['id'] . 'button", "' . $button_label . '", "' . get_string('hidecourses', 'block_curr_admin') . '", "' . get_string('showcourses', 'block_curr_admin') . '", "curriculum-' . $curricula['id'] . '");</script></div>' . $header_curr_name;
             $content .= '<div class="dashboard_curricula_block">';
             $content .= print_heading($heading, 'left', 2, 'main', true);
             $content .= '<div id="curriculum-' . $curricula['id'] . '" class="yui-skin-sam ' . $extra_class . '">';
             if (empty($curricula['data'])) {
                 $content .= get_string('nocourseassoc', 'block_curr_admin');
             } else {
                 $content .= print_table($table, true);
             }
             $content .= '</div>';
             $content .= '</div>';
         }
     }
     /// Completed non-curricula course data
     if ($tab != 'archivedlp') {
         if (!empty($classids)) {
             $sql = "SELECT stu.id, stu.classid, crs.name as coursename, stu.completetime, stu.grade, stu.completestatusid\n                        FROM " . $CURMAN->db->prefix_table(STUTABLE) . " stu\n                        INNER JOIN " . $CURMAN->db->prefix_table(CLSTABLE) . " cls ON cls.id = stu.classid\n                        INNER JOIN " . $CURMAN->db->prefix_table(CRSTABLE) . " crs ON crs.id = cls.courseid\n                        WHERE userid = {$this->id}\n                        AND classid " . (count($classids) == 1 ? "!= " . current($classids) : "NOT IN (" . implode(", ", $classids) . ")") . "\n                        ORDER BY crs.name ASC, stu.completetime ASC";
         } else {
             $sql = "SELECT stu.id, stu.classid, crs.name as coursename, stu.completetime, stu.grade, stu.completestatusid\n                        FROM " . $CURMAN->db->prefix_table(STUTABLE) . " stu\n                        INNER JOIN " . $CURMAN->db->prefix_table(CLSTABLE) . " cls ON cls.id = stu.classid\n                        INNER JOIN " . $CURMAN->db->prefix_table(CRSTABLE) . " crs ON crs.id = cls.courseid\n                        WHERE userid = {$this->id}\n                        ORDER BY crs.name ASC, stu.completetime ASC";
         }
         if ($classes = get_records_sql($sql)) {
             $table = new stdClass();
             $table->head = array(get_string('class', 'block_curr_admin'), get_string('score', 'block_curr_admin'), get_string('completed_label', 'block_curr_admin'), get_string('date', 'block_curr_admin'));
             $table->data = array();
             foreach ($classes as $class) {
                 if ($mdlcrs = moodle_get_course($class->classid)) {
                     $coursename = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $mdlcrs . '">' . $class->coursename . '</a>';
                 } else {
                     $coursename = $class->coursename;
                 }
                 $table->data[] = array($coursename, $class->grade, $class->completestatusid == STUSTATUS_PASSED ? get_string('yes') : get_string('no'), $class->completestatusid == STUSTATUS_PASSED && !empty($class->completetime) ? date('M j, Y', $class->completetime) : get_string('na', 'block_curr_admin'));
             }
             $header_curr_name = get_string('noncurriculacourses', 'block_curr_admin');
             if (in_array('na', $collapsed_array)) {
                 $button_label = get_string('showcourses', 'block_curr_admin');
                 $extra_class = ' hide';
             } else {
                 $button_label = get_string('hidecourses', 'block_curr_admin');
                 $extra_class = '';
             }
             $heading = '<div class="clearfix"></div>' . '<div style="' . $float_style . '">' . '<script id="noncurriculascript" type="text/javascript">toggleVisibleInitWithState("noncurriculascript", "noncurriculabutton", "' . $button_label . '", "' . get_string('hidecourses', 'block_curr_admin') . '", "' . get_string('showcourses', 'block_curr_admin') . '", "curriculum-na");</script></div>' . $header_curr_name;
             $content .= '<div class="dashboard_curricula_block">';
             $content .= print_heading($heading, 'left', 2, 'main', true);
             $content .= '<div id="curriculum-na" class="yui-skin-sam ' . $extra_class . '">';
             $content .= print_table($table, true);
             $content .= '</div>';
             $content .= '</div>';
         }
     }
     return $content;
 }
Beispiel #2
0
 /**
  * Perform all necessary tasks to remove a student enrolment from the system.
  */
 function delete()
 {
     /// Remove any grade records for this enrolment.
     $result = student_grade::delete_for_user_and_class($this->userid, $this->classid);
     /// Unenrol them from the Moodle class.
     if ($moodlecourseid = moodle_get_course($this->classid)) {
         if (($mcourse = $this->_db->get_record('course', array('id' => $moodlecourseid))) && ($muser = $this->users->get_moodleuser())) {
             $sql = 'SELECT enrol.*
                       FROM {user_enrolments} enrolments
                       JOIN {enrol} enrol ON enrol.id = enrolments.enrolid
                      WHERE enrol.courseid = ?
                        AND enrolments.userid = ?';
             $enrolments = $this->_db->get_recordset_sql($sql, array($moodlecourseid, $muser->id));
             foreach ($enrolments as $enrolment) {
                 $plugin = enrol_get_plugin($enrolment->enrol);
                 $plugin->unenrol_user($enrolment, $muser->id);
             }
             unset($enrolments);
         }
     }
     parent::delete();
     if ($this->completestatusid == STUSTATUS_NOTCOMPLETE) {
         $pmclass = $this->pmclass;
         if (empty($pmclass->maxstudents) || $pmclass->maxstudents > static::count_enroled($pmclass->id)) {
             $wlst = waitlist::get_next($this->classid);
             if (!empty($wlst)) {
                 $wlst->enrol();
             }
         }
     }
     return $result;
 }
Beispiel #3
0
 /**
  * Convert a listing of non-program courses to a data table
  *
  * @param array $classes A listing of table entries for non-program courses
  * @return object the table that can be used to display this information
  */
 function get_dashboard_nonprogram_table($classes)
 {
     global $CFG;
     $status_mapping = array(STUSTATUS_PASSED => get_string('passed', 'local_elisprogram'), STUSTATUS_FAILED => get_string('failed', 'local_elisprogram'), STUSTATUS_NOTCOMPLETE => get_string('n_completed', 'local_elisprogram'));
     $table = new html_table();
     $table->head = array(get_string('course', 'local_elisprogram'), get_string('class', 'local_elisprogram'), get_string('score', 'local_elisprogram'), get_string('student_status', 'local_elisprogram'), get_string('date', 'local_elisprogram'));
     $table->data = array();
     if ($classes != false) {
         //have one or more classes
         foreach ($classes as $class) {
             if ($mdlcrs = moodle_get_course($class->classid)) {
                 $coursename = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $mdlcrs . '">' . $class->coursename . '</a>';
             } else {
                 $coursename = $class->coursename;
             }
             $table->data[] = array($coursename, $class->idnumber, pm_display_grade($class->grade), $status_mapping[$class->completestatusid], $class->completestatusid == STUSTATUS_PASSED && !empty($class->completetime) ? userdate($class->completetime, get_string('pm_date_format', 'local_elisprogram')) : get_string('na', 'local_elisprogram'));
         }
     }
     return $table;
 }
 /**
  * Perform all necessary tasks to add a student enrolment to the system.
  *
  * @param array $checks what checks to perform before adding enrolling the
  * user.  e.g. array('prereq' => 1, 'waitlist' => 1) will check that
  * prerequisites are satisfied, and that the class is not full
  * @param boolean $notify whether or not notifications should be sent if a
  * check fails
  */
 function add($checks = array(), $notify = false)
 {
     global $CURMAN, $CFG, $USER;
     $status = true;
     if ($CURMAN->db->record_exists(STUTABLE, 'userid', $this->userid, 'classid', $this->classid)) {
         // already enrolled -- pretend we succeeded
         return true;
     }
     // check that the student can be enrolled first
     if (!empty($checks['prereq'])) {
         // check prerequisites
         $cmclass = new cmclass($this->classid);
         // get all the curricula that the user is in
         $curricula = curriculumstudent::get_curricula($this->userid);
         foreach ($curricula as $curriculum) {
             $curcrs = new curriculumcourse();
             $curcrs->courseid = $cmclass->courseid;
             $curcrs->curriculumid = $curriculum->curid;
             if (!$curcrs->prerequisites_satisfied($this->userid)) {
                 // prerequisites not satisfied
                 if ($notify) {
                     $data = new stdClass();
                     $data->userid = $this->userid;
                     $data->classid = $this->classid;
                     //$data->trackid = $trackid;
                     events_trigger('crlm_prereq_unsatisfied', $data);
                 }
                 $status = new Object();
                 $status->message = get_string('unsatisfiedprereqs', 'block_curr_admin');
                 $status->code = 'unsatisfiedprereqs';
                 return $status;
             }
         }
     }
     if (!empty($checks['waitlist'])) {
         // check class enrolment limit
         $cmclass = new cmclass($this->classid);
         $limit = $cmclass->maxstudents;
         if (!empty($limit) && $limit <= student::count_enroled($this->classid)) {
             // class is full
             // put student on wait list
             $wait_list = new waitlist($this);
             $wait_list->timecreated = time();
             $wait_list->position = 0;
             $wait_list->add();
             if ($notify) {
                 $subject = get_string('user_waitlisted', 'block_curr_admin');
                 $a = new object();
                 $a->user = $this->user->idnumber;
                 $a->cmclass = $cmclass->idnumber;
                 $message = get_string('user_waitlisted_msg', 'block_curr_admin', $a);
                 $from = $user = get_admin();
                 notification::notify($message, $user, $from);
                 email_to_user($user, $from, $subject, $message);
             }
             $status = new Object();
             $status->message = get_string('user_waitlisted', 'block_curr_admin');
             $status->code = 'user_waitlisted';
             return $status;
         }
     }
     //set end time based on class duration
     $studentclass = new cmclass($this->classid);
     if (empty($this->endtime)) {
         if (isset($studentclass->duration) && $studentclass->duration) {
             $this->endtime = $this->enrolmenttime + $studentclass->duration;
         } else {
             // no class duration -> no end time
             $this->endtime = 0;
         }
     }
     $status = $this->data_insert_record();
     // TBD: we should check this!
     /// Get the Moodle user ID or create a new account for this user.
     if (!($muserid = cm_get_moodleuserid($this->userid))) {
         $user = new user($this->userid);
         if (!($muserid = $user->synchronize_moodle_user(true, true))) {
             $status = new Object();
             $status->message = get_string('errorsynchronizeuser', 'block_curr_admin');
             $muserid = false;
         }
     }
     /// Enrol them into the Moodle class.
     if ($moodlecourseid = moodle_get_course($this->classid)) {
         if ($mcourse = get_record('course', 'id', $moodlecourseid)) {
             $enrol = $mcourse->enrol;
             if (!$enrol) {
                 $enrol = $CFG->enrol;
             }
             if ($CURMAN->config->restrict_to_elis_enrolment_plugin && $enrol != 'elis') {
                 $status = new Object();
                 $status->message = get_string('error_not_using_elis_enrolment', 'block_curr_admin');
                 return $status;
             }
             $timestart = $this->enrolmenttime;
             $timeend = $this->endtime;
             if ($role = get_default_course_role($mcourse)) {
                 $context = get_context_instance(CONTEXT_COURSE, $mcourse->id);
                 if (!empty($muserid)) {
                     if (!role_assign($role->id, $muserid, 0, $context->id, $timestart, $timeend, 0, 'manual')) {
                         $status = new Object();
                         $status->message = get_string('errorroleassign', 'block_curr_admin');
                     }
                 }
             }
         }
     } else {
         if (!empty($muserid)) {
             $sturole = $CURMAN->config->enrolment_role_sync_student_role;
             // ELIS-2776: must still trigger events for notifications
             $ra = new stdClass();
             $ra->roleid = !empty($sturole) ? $sturole : get_field('role', 'id', 'shortname', 'student');
             $ra->contextid = context_level_base::get_custom_context_level('class', 'block_curr_admin');
             // TBD
             $ra->userid = $muserid;
             $ra->component = '';
             // TBD: 'enrol_elis'
             $ra->itemid = $this->classid;
             // TBD
             $ra->timemodified = time();
             $ra->modifierid = empty($USER->id) ? 0 : $USER->id;
             events_trigger('role_assigned', $ra);
         }
     }
     return $status;
 }
 /**
  * Method to return timeofday data
  * @param string $column Name of the column
  * @param object $item the ELIS Class Instance object id
  * @return string Class name possibly containing link at end
  * @uses $CFG
  */
 function get_item_display_classname($column, $item)
 {
     global $CFG;
     $this->get_class($item);
     $classid = $this->current_class->idnumber;
     if ($mdlcrs = moodle_get_course($this->current_class->id)) {
         $classid .= ' - <a href="' . $CFG->wwwroot . '/course/view.php?id=' . $mdlcrs . '">' . get_string('moodlecourse', 'local_elisprogram') . '</a>';
     }
     return $classid;
 }
Beispiel #6
0
 function definition()
 {
     global $USER, $CFG, $DB, $PAGE;
     parent::definition();
     if (!empty($this->_customdata['obj'])) {
         $obj = $this->_customdata['obj'];
         if (empty($obj->startdate) || $obj->startdate == 0) {
             $this->set_data(array('disablestart' => '1'));
         }
         if (empty($obj->enddate) || $obj->enddate == 0) {
             $this->set_data(array('disableend' => '1'));
         }
         if (isset($obj->starttimeminute) && isset($obj->starttimehour) && $obj->starttimeminute < 61 && $obj->starttimehour < 25) {
             $this->set_data(array('starttime' => array('minute' => $obj->starttimeminute, 'hour' => $obj->starttimehour)));
         }
         if (isset($obj->endtimeminute) && isset($obj->endtimehour) && $obj->endtimeminute < 61 && $obj->endtimehour < 25) {
             $this->set_data(array('endtime' => array('minute' => $obj->endtimeminute, 'hour' => $obj->endtimehour)));
         }
     }
     $mform =& $this->_form;
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     // If there is no custom data for the course, create some
     if (empty($this->_customdata['obj']->course->name) || empty($this->_customdata['obj']->id)) {
         $courses = array();
         if (!empty($USER->id)) {
             // This is necessary for creating a new class instance but will prevent a parent course from appearing
             // when the user has class edit permissions but not class creation permission -- ELIS-5954
             $contexts = get_contexts_by_capability_for_user('course', 'local/elisprogram:class_create', $USER->id);
             // get listing of available ELIS courses
             $courses = course_get_listing('name', 'ASC', 0, 0, '', '', $contexts);
             // Detect if we are editing an existing class instance by checking for an value in the 'id' element
             $elm = $mform->_elements[$mform->_elementIndex['id']];
             $id = $elm->getValue();
             if (!empty($id)) {
                 // Make sure that the parent course for this class is always included otherwise the display is messed up
                 // and hitting the form Cancel button causes a DB error -- ELIS-5954
                 $pmclass = new pmclass($id);
                 $courses = array_merge($courses, course_get_listing('name', 'ASC', 0, 0, $pmclass->course->idnumber));
             }
         }
         // Add course select
         $attributes = array('onchange' => 'update_trk_multiselect(); update_crs_template();');
         $selections = array();
         if (!empty($courses)) {
             foreach ($courses as $course) {
                 $selections[$course->id] = '(' . $course->idnumber . ')' . $course->name;
             }
         }
         $mform->addElement('select', 'courseid', get_string('course', 'local_elisprogram') . ':', $selections, $attributes);
         $mform->addHelpButton('courseid', 'pmclassform:course', 'local_elisprogram');
         $firstcourse = reset($courses);
         $this->firstcourse = $firstcourse;
         if (false !== $firstcourse && empty($this->_customdata['obj']->id)) {
             $this->add_track_multi_select($firstcourse->id);
         } elseif (!empty($courses)) {
             $this->add_track_multi_select($this->_customdata['obj']->courseid);
         }
     } else {
         $extra_params = array();
         $mform->addElement('static', 'courseid', get_string('course', 'local_elisprogram') . ':');
         // Get current action and set param accordingly
         $current_action = optional_param('action', 'view', PARAM_ALPHA);
         $extra_params['action'] = $current_action;
         $extra_params['s'] = 'crs';
         // Want to set the url for the course
         $extra_params['id'] = $this->_customdata['obj']->courseid;
         // Course id
         $course_url = $this->get_moodle_url($extra_params);
         $course_name = '(' . $this->_customdata['obj']->course->idnumber . ')' . '<a href="' . $course_url . '" >' . $this->_customdata['obj']->course->name . '</a>';
         $this->set_data(array('courseid' => $course_name));
         $mform->addHelpButton('courseid', 'pmclassform:course', 'local_elisprogram');
         $this->add_track_multi_select($this->_customdata['obj']->courseid);
     }
     if (!empty($this->_customdata['obj']->courseid)) {
         $mform->freeze('courseid');
     } else {
         $mform->addRule('courseid', get_string('required'), 'required', NULL, 'client');
     }
     // Done adding course select
     // Set any associated Moodle course for this class instance
     if (empty($this->_customdata['obj']->moodlecourseid) && !empty($this->_customdata['obj']->id)) {
         $this->_customdata['obj']->moodlecourseid = moodle_get_course($this->_customdata['obj']->id);
     }
     $mform->addElement('text', 'idnumber', get_string('class_idnumber', 'local_elisprogram') . ':');
     $mform->setType('idnumber', PARAM_TEXT);
     $mform->addRule('idnumber', get_string('required'), 'required', NULL, 'client');
     $mform->addRule('idnumber', null, 'maxlength', 100, 'client');
     $mform->addHelpButton('idnumber', 'pmclassform:class_idnumber', 'local_elisprogram');
     $mform->addElement('date_selector', 'startdate', get_string('class_startdate', 'local_elisprogram') . ':', array('optional' => true, 'disabled' => 'disabled'));
     $mform->addHelpButton('startdate', 'pmclassform:class_startdate', 'local_elisprogram');
     $mform->addElement('date_selector', 'enddate', get_string('class_enddate', 'local_elisprogram') . ':', array('optional' => true));
     if (!isset($obj->starttimehour) || $obj->starttimehour >= 25 || !isset($obj->starttimeminute) || $obj->starttimeminute >= 61) {
         $mform->addElement('time_selector', 'starttime', get_string('class_starttime', 'local_elisprogram') . ':', array('optional' => true, 'checked' => 'checked', 'display_12h' => elis::$config->local_elisprogram->time_format_12h));
     } else {
         $mform->addElement('time_selector', 'starttime', get_string('class_starttime', 'local_elisprogram') . ':', array('optional' => true, 'checked' => 'unchecked', 'display_12h' => elis::$config->local_elisprogram->time_format_12h));
     }
     $mform->addHelpButton('starttime', 'pmclassform:class_starttime', 'local_elisprogram');
     // Do the same thing for the endtime
     if (!isset($obj->endtimehour) || $obj->endtimehour >= 25 || !isset($obj->endtimeminute) || $obj->endtimeminute >= 61) {
         $mform->addElement('time_selector', 'endtime', get_string('class_endtime', 'local_elisprogram') . ':', array('optional' => true, 'checked' => 'checked', 'display_12h' => elis::$config->local_elisprogram->time_format_12h));
     } else {
         $mform->addElement('time_selector', 'endtime', get_string('class_endtime', 'local_elisprogram') . ':', array('optional' => true, 'checked' => 'unchecked', 'display_12h' => elis::$config->local_elisprogram->time_format_12h));
     }
     $mform->addElement('text', 'maxstudents', get_string('class_maxstudents', 'local_elisprogram') . ':');
     $mform->setType('maxstudents', PARAM_INT);
     $mform->addHelpButton('maxstudents', 'pmclassform:class_maxstudents', 'local_elisprogram');
     // Course selector
     if (empty($this->_customdata['obj']->moodlecourseid)) {
         $this->add_moodle_course_select();
     } else {
         $PAGE->requires->js('/local/elisprogram/js/classform.js');
         $courseSelected = array();
         $coursename = $DB->get_field('course', 'fullname', array('id' => $this->_customdata['obj']->moodlecourseid));
         $courseSelected[] = $mform->createElement('static', 'class_attached_course', get_string('class_attached_course', 'local_elisprogram') . ':', "<a href=\"{$CFG->wwwroot}/course/view.php?id={$this->_customdata['obj']->moodlecourseid}\">{$coursename}</a>");
         //only show checkbox if current action is edit
         $current_action = optional_param('action', 'view', PARAM_ALPHA);
         if ($current_action == 'edit') {
             $options = array();
             //set group to null
             $options['group'] = null;
             $options['onclick'] = "return class_confirm_unlink(this,'" . get_string('class_unlink_confirm', 'local_elisprogram') . "')";
             $courseSelected[] = $mform->createElement('advcheckbox', 'unlink_attached_course', get_string('class_unlink_attached_course', 'local_elisprogram') . ':', get_string('class_unlink_attached_course', 'local_elisprogram'), $options);
         }
         $mform->addGroup($courseSelected, 'courseSelected', get_string('class_attached_course', 'local_elisprogram') . ':');
         $mform->addHelpButton('courseSelected', 'pmclassform:moodlecourse', 'local_elisprogram');
         $mform->addElement('hidden', 'moodlecourseid');
         $mform->setType('moodlecourseid', PARAM_INT);
     }
     $mform->addElement('advcheckbox', 'enrol_from_waitlist', get_string('waitlistenrol', 'local_elisprogram') . ':');
     $mform->addHelpButton('enrol_from_waitlist', 'pmclassform:waitlistenrol', 'local_elisprogram');
     // custom fields
     $this->add_custom_fields('class', 'local/elisprogram:class_edit', 'local/elisprogram:class_view', 'course');
     $this->add_action_buttons();
 }
Beispiel #7
0
 /**
  * Send an email to the user when they are enroled.
  *
  * @param student $student The student object of for the enrolment.
  * @return bool Success/Failure.
  */
 public function newenrolmentemail(student $student)
 {
     global $DB;
     if (!empty($student->no_moodle_enrol)) {
         return false;
     }
     // Look for attached Moodle course, and get the course info.
     $moodlecourseid = moodle_get_course($student->classid);
     if (empty($moodlecourseid)) {
         return false;
     }
     $course = $DB->get_record('course', array('id' => $moodlecourseid));
     if (empty($course)) {
         return false;
     }
     // Get the elis user and the moodle user.
     $user = new user($student->userid);
     $muser = $user->get_moodleuser();
     if (empty($muser)) {
         return false;
     }
     // Check whether emails are enabled.
     $enabled = get_config('dhimport_version1elis', 'newenrolmentemailenabled');
     if (empty($enabled)) {
         return false;
     }
     // Check whether email text has been set.
     $template = get_config('dhimport_version1elis', 'newenrolmentemailtemplate');
     if (empty($template)) {
         return false;
     }
     // Ensure Moodle user has an email address.
     if (empty($muser->email)) {
         return false;
     }
     // Get the email subject line, set an empty string if necessary.
     $subject = get_config('dhimport_version1elis', 'newenrolmentemailsubject');
     if (empty($subject) || !is_string($subject)) {
         $subject = '';
     }
     // Get the user the email will be from.
     $from = get_config('dhimport_version1elis', 'newenrolmentemailfrom');
     if ($from === 'teacher') {
         $context = context_course::instance($course->id);
         $cap = 'moodle/course:update';
         if ($users = get_users_by_capability($context, $cap, 'u.*', 'u.id ASC', '', '', '', '', false, true)) {
             $users = sort_by_roleassignment_authority($users, $context);
             $from = current($users);
         } else {
             $from = get_admin();
         }
     } else {
         $from = get_admin();
     }
     // Generate email.
     $body = $this->newenrolmentemail_generate($template, $muser, $course);
     // Send!
     return $this->sendemail($muser, $from, $subject, $body);
 }