/** * Creates and associates a class with a track for every course that * belongs to the track curriculum * * TODO: return some data */ function track_auto_create() { // Had to load $this due to lazy-loading $this->load(); if (empty($this->curid) or empty($this->id)) { cm_error('trackid and curid have not been properly initialized'); return false; } $autoenrol = false; $usetemplate = false; // Pull up the curricula assignment record(s) // $curcourse = curriculumcourse_get_list_by_curr($this->curid); $sql = 'SELECT ccc.*, cc.idnumber, cc.name ' . 'FROM {' . curriculumcourse::TABLE . '} ccc ' . 'INNER JOIN {' . course::TABLE . '} cc ON cc.id = ccc.courseid ' . 'WHERE ccc.curriculumid = ? '; $params = array($this->curid); $curcourse = $this->_db->get_recordset_sql($sql, $params); $classparams = array(); // ELIS-6854: TBD - should new classes use track's start/end dates? if (!empty($this->startdate)) { $classparams['startdate'] = $this->startdate; } if (!empty($this->enddate)) { $classparams['enddate'] = $this->enddate; } // For every course of the curricula determine which ones need - // to have their auto enrol flag set foreach ($curcourse as $recid => $curcourec) { //get a unique idnumber $idnumber = $this->idnumber; if (!empty($curcourec->idnumber)) { $idnumber = append_once($idnumber, $curcourec->idnumber . '-', array('prepend' => true, 'maxlength' => 95, 'strict' => true)); } generate_unique_identifier(pmclass::TABLE, 'idnumber', $idnumber, array('idnumber' => $idnumber), 'pmclass', $classojb, array('courseid' => $curcourec->courseid, 'idnumber' => $idnumber)); // Course is required if ($curcourec->required) { $autoenrol = true; } //attempte to obtain the course template $cortemplate = coursetemplate::find(new field_filter('courseid', $curcourec->courseid)); if ($cortemplate->valid()) { $cortemplate = $cortemplate->current(); } // Course is using a Moodle template if (!empty($cortemplate->location)) { // Parse the course id from the template location $classname = $cortemplate->templateclass; $templateobj = new $classname(); $templatecorid = $cortemplate->location; $usetemplate = true; } // Create class $classparams['courseid'] = $curcourec->courseid; if (!($classid = $classojb->auto_create_class($classparams))) { cm_error(get_string('error_creating_class', 'local_elisprogram', $curcourec->name)); continue; } // attach course to moodle template if ($usetemplate) { moodle_attach_class($classid, 0, '', false, false, true); } $trackclassobj = new trackassignment(array('courseid' => $curcourec->courseid, 'trackid' => $this->id, 'classid' => $classojb->id)); // Set auto-enrol flag if ($autoenrol) { $trackclassobj->autoenrol = 1; } // Assign class to track $trackclassobj->save(); // Create and assign class to default system track // TODO: for now, use elis::$config->local_elisprogram in place of $CURMAN->config if (!empty(elis::$config->local_elisprogram->userdefinedtrack)) { $trkid = $this->create_default_track(); $trackclassobj = new trackassignment(array('courseid' => $curcourec->courseid, 'trackid' => $trkid, 'classid' => $classojb->id)); // Set auto-enrol flag if ($autoenrol) { $trackclassobj->autoenrol = 1; } // Assign class to default system track $trackclassobj->save(); } $usetemplate = false; $autoenrol = false; } unset($curcourse); }
/** * adds a moodle course selection box to the form * * @uses $CFG * @param $formid string A suffix to put on all 'id' and index for all 'name' attributes. * This should be unique if being used more than once in a form. * @param $extraclass string Any extra class information to add to the output. * * @return string The form HTML, without the form. */ function add_moodle_course_select() { global $CFG, $DB; $mform =& $this->_form; $mform->addElement('html', ' <script type="text/javascript"> //<![CDATA[ function update_crs_template() { var crselem = document.getElementById("id_courseid"); var mdlcrselem = document.getElementById("id_moodleCourses_moodlecourseid"); if (mdlcrselem && crselem && crselem.value) { var crstmpl_failure = function(o) { mdlcrselem.selectedIndex = 0; } var set_crs_tmpl = function(o) { var i; var mdlcrs = parseInt(o.responseText); mdlcrselem.selectedIndex = 0; for (i = 0; i < mdlcrselem.options.length; ++i) { if (mdlcrs == mdlcrselem.options[i].value) { mdlcrselem.selectedIndex = i; break; } } } var callback = { success:set_crs_tmpl, failure:crstmpl_failure } YAHOO.util.Connect.asyncRequest("GET", "coursetemplateid.php?courseid=" + crselem.value, callback, null); } } //]]> </script> '); $select = 'id != \'' . SITEID . '\' AND fullname NOT LIKE \'.%\''; $cselect = array(get_string('none', 'local_elisprogram')); $crss = $DB->get_recordset_select('course', $select, null, 'fullname', 'id, fullname'); if (!empty($crss) && $crss->valid()) { foreach ($crss as $crs) { $cselect[$crs->id] = $crs->fullname; } $crss->close(); } $moodleCourses = array(); if (count($cselect) > 1) { $moodleCourses[] = $mform->createElement('select', 'moodlecourseid', get_string('moodlecourse', 'local_elisprogram'), $cselect); } else { $mform->addElement('static', 'no_moodle_courses', get_string('moodlecourse', 'local_elisprogram') . ':', get_string('no_moodlecourse', 'local_elisprogram')); $mform->addHelpButton('no_moodle_courses', 'pmclassform:moodlecourse', 'local_elisprogram'); } // Add auto create checkbox if CM course uses a template if (empty($this->_customdata['obj']->courseid)) { $courseid = 0; } else { $courseid = $this->_customdata['obj']->courseid; } //attempt to retrieve the course template $template = coursetemplate::find(new field_filter('courseid', $courseid)); if ($template->valid()) { $template = $template->current(); } if (empty($courseid) || !empty($template->location)) { $moodleCourses[] = $mform->createElement('checkbox', 'autocreate', '', get_string('autocreate', 'local_elisprogram')); } if (count($cselect) > 1) { $mform->addGroup($moodleCourses, 'moodleCourses', get_string('moodlecourse', 'local_elisprogram') . ':'); $mform->disabledIf('moodleCourses', 'moodleCourses[autocreate]', 'checked'); $mform->addHelpButton('moodleCourses', 'pmclassform:moodlecourse', 'local_elisprogram'); if (!empty($template->location)) { //error_log("pmclassform::add_moodle_course_select() course template = {$template->location}"); $mform->setDefault('moodleCourses[moodlecourseid]', $template->location); } } }
* the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * @package elis * @subpackage programmanagement * @author Remote-Learner.net Inc * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net * */ require_once 'lib/setup.php'; require_once elis::lib('data/data_filter.class.php'); require_once elispm::lib('data/coursetemplate.class.php'); $courseid = required_param('courseid', PARAM_INT); if ($CFG->forcelogin) { require_login(); } if (!$courseid || !($template = coursetemplate::find(new field_filter('courseid', $courseid))) || !$template->valid()) { echo '0'; } else { $template = $template->current(); echo empty($template->location) ? '0' : "{$template->location}"; }
/** * Attach a class record from this system to an existing Moodle course. * * @param int $clsid The class ID. * @param int $mdlid The Moodle course ID. * @param string $siteconfig The full system path to a Moodle congif.php file (defaults to local). * @param bool $enrolinstructor Flag for enroling instructors into the Moodle course (optional). * @param bool $enrolstudent Flag for enroling students into the Moodle course (optional). * @return bool True on success, False otherwise. */ function moodle_attach_class($clsid, $mdlid, $siteconfig = '', $enrolinstructor = false, $enrolstudent = false, $autocreate = false) { //$CFG global is needed by the rollover lib global $DB, $CFG; $result = true; $moodlecourseid = $mdlid; /// Look for an existing link for this class. if (!($clsmdl = $DB->get_record(classmoodlecourse::TABLE, array('classid' => $clsid)))) { /// Make sure the specified Moodle site config file exists. if (!empty($siteconfig) && !file_exists($siteconfig)) { return false; } if ($autocreate) { // auto create is checked, create connect to moodle course $cls = new pmclass($clsid); //attempt to obtain the course template $template = coursetemplate::find(new field_filter('courseid', $cls->courseid)); if ($template->valid()) { $template = $template->current(); } // no template defined, so do nothing if (empty($template->id) || empty($template->location)) { print_error('notemplate', 'local_elisprogram'); } $classname = $template->templateclass; $obj = new $classname(); $courseid = $template->location; //perform the rollover require_once elis::lib('rollover/lib.php'); $moodlecourseid = course_rollover($courseid); //check that the course has rolled over successfully if (!$moodlecourseid) { return false; } //set the Moodle course name as expected $restoredcourse = new stdClass(); $restoredcourse->id = $moodlecourseid; // ELIS-2941: Don't prepend course name if already present @ start if (strpos($cls->idnumber, $cls->course->name) !== 0) { $restoredcourse->fullname = $cls->course->name . '_' . $cls->idnumber; } else { $restoredcourse->fullname = $cls->idnumber; } $restoredcourse->shortname = $cls->idnumber; $DB->update_record('course', $restoredcourse); } $newrec = array('classid' => $clsid, 'moodlecourseid' => $moodlecourseid, 'siteconfig' => $siteconfig, 'autocreated' => $autocreate ? 1 : 0); $clsmdl = new classmoodlecourse($newrec); $clsmdl->save(); } else { $clsmdl = new classmoodlecourse($clsmdl->id); } if ($enrolinstructor) { $clsmdl->data_enrol_instructors(); } if ($enrolstudent) { $clsmdl->data_enrol_students(); } events_trigger('pm_classinstance_associated', $clsmdl); return true; }
public function definition() { global $CFG, $PAGE, $DB; $locationlabel = ''; if (isset($this->_customdata['obj']->id)) { $id = $this->_customdata['obj']->id; // TO-DO: this should probably be moved to a different location $template = coursetemplate::find(new field_filter('courseid', $id)); if ($template->valid()) { $template = $template->current(); $course = $DB->get_record('course', array('id' => $template->location)); if (!empty($course)) { $locationlabel = $course->fullname . ' ' . $course->shortname; } } else { // use a blank template $template = new coursetemplate(); } } $PAGE->requires->js('/local/elisprogram/js/courseform.js'); $this->set_data($this->_customdata['obj']); $mform =& $this->_form; $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('text', 'name', get_string('course_name', 'local_elisprogram') . ':'); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', get_string('required_field', 'local_elisprogram', get_string('course_name', 'local_elisprogram')), 'required', null, 'client'); $mform->addRule('name', null, 'maxlength', 255, 'client'); $mform->addHelpButton('name', 'courseform:course_name', 'local_elisprogram'); $mform->addElement('text', 'code', get_string('course_code', 'local_elisprogram') . ':'); $mform->setType('code', PARAM_TEXT); $mform->addRule('code', null, 'maxlength', 100, 'client'); $mform->addHelpButton('code', 'courseform:course_code', 'local_elisprogram'); $mform->addElement('text', 'idnumber', get_string('course_idnumber', 'local_elisprogram') . ':'); $mform->setType('idnumber', PARAM_TEXT); $mform->addRule('idnumber', get_string('required_field', 'local_elisprogram', get_string('course_idnumber', 'local_elisprogram')), 'required', null, 'client'); $mform->addRule('idnumber', null, 'maxlength', 100, 'client'); $mform->addHelpButton('idnumber', 'courseform:course_idnumber', 'local_elisprogram'); $attributes = array('cols' => 40, 'rows' => 2); $mform->addElement('textarea', 'syllabus', get_string('course_syllabus', 'local_elisprogram') . ':', $attributes); $mform->setType('syllabus', PARAM_CLEAN); $mform->addHelpButton('syllabus', 'courseform:course_syllabus', 'local_elisprogram'); $mform->addElement('text', 'lengthdescription', get_string('length_description', 'local_elisprogram')); $mform->setType('lengthdescription', PARAM_TEXT); $mform->addRule('lengthdescription', null, 'maxlength', 100, 'client'); $mform->addHelpButton('lengthdescription', 'courseform:length_description', 'local_elisprogram'); $mform->addElement('text', 'length', get_string('duration', 'local_elisprogram') . ':'); $mform->setType('length', PARAM_INT); $mform->addHelpButton('length', 'courseform:duration', 'local_elisprogram'); $mform->addElement('text', 'credits', get_string('credits', 'local_elisprogram') . ':'); $mform->setType('credits', PARAM_TEXT); $mform->addRule('credits', null, 'maxlength', 10, 'client'); $mform->addHelpButton('credits', 'courseform:credits', 'local_elisprogram'); $grades = range(0, 100, 1); $mform->addElement('select', 'completion_grade', get_string('completion_grade', 'local_elisprogram') . ':', $grades); $mform->addHelpButton('completion_grade', 'courseform:completion_grade', 'local_elisprogram'); $mform->addElement('text', 'cost', get_string('cost', 'local_elisprogram') . ':'); $mform->setType('cost', PARAM_TEXT); $mform->addRule('cost', null, 'maxlength', 10, 'client'); $mform->addHelpButton('cost', 'courseform:cost', 'local_elisprogram'); $mform->addElement('text', 'version', get_string('course_version', 'local_elisprogram') . ':'); $mform->setType('version', PARAM_TEXT); $mform->addRule('version', null, 'maxlength', 100, 'client'); $mform->addHelpButton('version', 'courseform:course_version', 'local_elisprogram'); // Print form items for course template browsing $mform->addElement('html', '<br />'); $mform->addElement('hidden', 'templateclass', 'moodlecourseurl', array('id' => 'id_templateclass')); $mform->setType('templateclass', PARAM_TEXT); if (empty($locationlabel) || optional_param('action', '', PARAM_CLEAN) != 'view') { $mform->addElement('text', 'locationlabel', get_string('coursetemplate', 'local_elisprogram'), array('readonly' => 'readonly', 'value' => $locationlabel)); $mform->setType('locationlabel', PARAM_TEXT); $mform->addHelpButton('locationlabel', 'courseform:coursetemplate', 'local_elisprogram'); } else { $mform->addElement('static', 'locationlabellink', get_string('coursetemplate', 'local_elisprogram') . ':', "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">{$locationlabel}</a>"); $mform->addHelpButton('locationlabellink', 'courseform:coursetemplate', 'local_elisprogram'); } if (empty($id)) { $mform->addElement('hidden', 'location', '', array('id' => 'id_location')); $mform->setType('location', PARAM_INT); $mform->addElement('hidden', 'temptype', '', array('id' => 'tempid')); $mform->setType('temptype', PARAM_INT); } else { $mform->addElement('hidden', 'location', $template->location, array('id' => 'id_location')); $mform->setType('location', PARAM_INT); $mform->addElement('hidden', 'tempid', $template->id, array('id' => 'tempid')); $mform->setType('tempid', PARAM_INT); } $templateButtons = array(); $templateButtons[] =& $mform->createElement('button', 'submit1', get_string('browse', 'local_elisprogram'), array('onClick' => 'openNewWindow();')); $templateButtons[] =& $mform->createElement('button', 'submit1', get_string('clear', 'local_elisprogram'), array('onClick' => 'cleartext();')); $mform->addGroup($templateButtons, 'templateButtons', '', '', false); // Multi select box for choosing curricula (only when creating a course) if (!isset($this->_customdata['obj'])) { $mform->addElement('html', '<br />'); $cur_listings = curriculum_get_listing(); $cur_listings = $cur_listings ? $cur_listings : array(); $values = array(); foreach ($cur_listings as $key => $val) { $values[$key] = $val->name; } $strcur = get_string("curricula", "local_elisprogram"); // Set an explicit width if the select box will have no elements. $attributes = empty($values) ? array('style' => 'width: 200px;') : array(); $multiSelect =& $mform->addElement('select', 'curriculum', $strcur . ':', $values, $attributes); $multiSelect->setMultiple(true); $mform->addHelpButton('curriculum', 'courseform:curriculum', 'local_elisprogram'); $mform->addElement('submit', 'makecurcourse', get_string('makecurcourse', 'local_elisprogram')); } // custom fields $this->add_custom_fields('course', 'local/elisprogram:course_edit', 'local/elisprogram:course_view'); $this->add_action_buttons(); }
/** * For tweaking based on data, specifically for disabling the course template * functionality if not appropriate * @uses $DB */ function definition_after_data() { global $DB; $mform =& $this->_form; // get the submitted id if ($requestid = $mform->getElementValue('request')) { if ($request = $DB->get_record('block_courserequest', array('id' => $requestid))) { if (empty($request->courseid)) { // new course, so disable $mform->hardFreeze('usecoursetemplate'); // remove class-level custom fields if the request is only for a course $this->remove_class_fields(); } else { // using existing course, so disable idnumber editing $mform->hardFreeze('crsidnumber'); // don't display as required, since not editable $course_idnumber_element =& $mform->getElement('crsidnumber'); $course_idnumber_element->setLabel(get_string('courseidnumber', 'block_courserequest')); $temp = coursetemplate::find(new field_filter('courseid', $request->courseid)); if ($temp->valid()) { $temp = $temp->current(); } if (empty($temp->id) || empty($temp->location)) { // no template, so disable $mform->hardFreeze('usecoursetemplate'); } // remove course-level custom fields if the request is only for a class $this->remove_course_fields(); } } } }