コード例 #1
0
 /**
  * Validate that class instance-moodle course associations can be created during a class instance update action.
  *
  * @param string $link The link attribute to use in the import, or 'auto' to auto-create from template.
  * @dataProvider link_course_provider
  */
 public function test_associate_moodle_course_during_class_update($link)
 {
     global $CFG, $DB, $USER;
     require_once $CFG->dirroot . '/course/lib.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/classmoodlecourse.class.php');
     require_once elispm::lib('data/coursetemplate.class.php');
     require_once elispm::lib('data/course.class.php');
     require_once elispm::lib('data/pmclass.class.php');
     // Make sure $USER is set up for backup/restore.
     $USER->id = $DB->get_field_select('user', 'id', "username != 'guest' AND deleted = 0", array(), IGNORE_MULTIPLE);
     // Need the moodle/backup:backupcourse capability.
     $guestroleid = create_role('guestrole', 'guestrole', 'guestrole');
     set_config('guestroleid', $guestroleid);
     set_config('siteguest', '');
     $systemcontext = context_system::instance();
     $roleid = create_role('testrole', 'testrole', 'testrole');
     assign_capability('moodle/backup:backupcourse', CAP_ALLOW, $roleid, $systemcontext->id);
     role_assign($roleid, $USER->id, $systemcontext->id);
     $coursecategory = new stdClass();
     $coursecategory->name = 'testcoursecategoryname';
     $coursecategory->id = $DB->insert_record('course_categories', $coursecategory);
     $moodlecourse = new stdClass();
     $moodlecourse->category = $coursecategory->id;
     $moodlecourse->shortname = 'testcourseshortname';
     $moodlecourse->fullname = 'testcoursefullname';
     $moodlecourse = create_course($moodlecourse);
     $course = new course(array('name' => 'testcoursename', 'idnumber' => 'testcourseidnumber', 'syllabus' => ''));
     $course->save();
     $class = new pmclass(array('courseid' => $course->id, 'idnumber' => 'testclassidnumber'));
     $class->save();
     // Need this for the 'auto' case, at the very least.
     $coursetemplate = new coursetemplate(array('courseid' => $course->id, 'location' => $moodlecourse->id, 'templateclass' => 'moodlecourseurl'));
     $coursetemplate->save();
     // Run the class instance create action.
     $record = new stdClass();
     $record->idnumber = 'testclassidnumber';
     $record->assignment = 'testcourseidnumber';
     $record->link = $link;
     $importplugin = rlip_dataplugin_factory::factory('dhimport_version1elis');
     $importplugin->fslogger = new silent_fslogger(null);
     $importplugin->class_update($record, 'bogus');
     // Validation.
     if ($record->link == 'auto') {
         $moodlecourseid = $moodlecourse->id + 1;
     } else {
         $moodlecourseid = $moodlecourse->id;
     }
     $dbautocreated = $record->link == 'auto' ? 1 : 0;
     $this->assertTrue($DB->record_exists(classmoodlecourse::TABLE, array('classid' => $class->id, 'moodlecourseid' => $moodlecourseid, 'enroltype' => 0, 'enrolplugin' => 'crlm', 'autocreated' => $dbautocreated)));
     ini_set('max_execution_time', '0');
 }
コード例 #2
0
 /**
  * adds a moodle course selection box to the form
  *
  * @uses $CFG
  * @uses $CURMAN
  * @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, $CURMAN;
     $mform =& $this->_form;
     $categoryid = $CURMAN->db->get_field('course_categories', 'id', 'parent', '0');
     $sitename = $CURMAN->db->get_field('course', 'shortname', 'id', SITEID);
     $select = 'id != \'' . SITEID . '\' AND fullname NOT LIKE \'.%\'';
     $cselect = array(get_string('none', 'block_curr_admin'));
     $crss = $CURMAN->db->get_records_select('course', $select, 'fullname', 'id,fullname');
     if (!empty($crss)) {
         foreach ($crss as $crs) {
             $cselect[$crs->id] = $crs->fullname;
         }
     }
     $moodleCourses = array();
     if (count($cselect) != 1) {
         $moodleCourses[] = $mform->createElement('select', 'moodlecourseid', get_string('moodlecourse', 'block_curr_admin'), $cselect);
     } else {
         $mform->addElement('static', 'no_moodle_courses', get_string('moodlecourse', 'block_curr_admin') . ':', get_string('no_moodlecourse', 'block_curr_admin'));
         $mform->setHelpButton('no_moodle_courses', array('cmclassform/moodlecourseid', get_string('moodlecourse', 'block_curr_admin'), 'block_curr_admin'));
     }
     // Add auto create checkbox if CM course uses a template
     if (empty($this->_customdata['obj']->courseid)) {
         $courseid = 0;
     } else {
         $courseid = $this->_customdata['obj']->courseid;
     }
     $template = new coursetemplate();
     if (empty($courseid) || false !== $template->data_load_record($courseid) && !empty($template->location)) {
         $moodleCourses[] = $mform->createElement('checkbox', 'autocreate', '', get_string('autocreate', 'block_curr_admin'));
     }
     if (count($cselect) != 1) {
         $mform->addGroup($moodleCourses, 'moodleCourses', get_string('moodlecourse', 'block_curr_admin') . ':');
         $mform->disabledIf('moodleCourses', 'moodleCourses[autocreate]', 'checked');
         $mform->setHelpButton('moodleCourses', array('cmclassform/moodlecourseid', get_string('moodlecourse', 'block_curr_admin'), 'block_curr_admin'));
     }
 }
コード例 #3
0
 /**
  * Clone a course.
  * @param array $options options for cloning.  Valid options are:
  * - 'classes': whether or not to clone classes (default: false)
  * - 'moodlecourses': whether or not to clone Moodle courses (if they were
  *   autocreated).  Values can be (default: "copyalways"):
  *   - "copyalways": always copy course
  *   - "copyautocreated": only copy autocreated courses
  *   - "autocreatenew": autocreate new courses from course template
  *   - "link": link to existing course
  * - 'targetcluster': the cluster id or cluster object (if any) to
  *   associate the clones with (default: none)
  * @return array array of array of object IDs created.  Key in outer array
  * is type of object (plural).  Key in inner array is original object ID,
  * value is new object ID.  Outer array also has an entry called 'errors',
  * which is an array of any errors encountered when duplicating the
  * object.
  */
 function duplicate($options)
 {
     global $CURMAN;
     require_once CURMAN_DIRLOCATION . '/lib/cmclass.class.php';
     require_once CURMAN_DIRLOCATION . '/lib/coursetemplate.class.php';
     $objs = array('errors' => array());
     if (isset($options['targetcluster'])) {
         $cluster = $options['targetcluster'];
         if (!is_object($cluster) || !is_a($cluster, 'cluster')) {
             $options['targetcluster'] = $cluster = new cluster($cluster);
         }
     }
     // clone main course object
     $clone = new course($this);
     unset($clone->id);
     if (isset($cluster)) {
         // if cluster specified, append cluster's name to course
         $clone->name = $clone->name . ' - ' . $cluster->name;
         $clone->idnumber = $clone->idnumber . ' - ' . $cluster->name;
     }
     $clone = new course(addslashes_recursive($clone));
     if (!$clone->add()) {
         $objs['errors'][] = get_string('failclustcpycurrcrs', 'block_curr_admin', $this);
         return $objs;
     }
     $objs['courses'] = array($this->id => $clone->id);
     $options['targetcourse'] = $clone->id;
     // copy completion elements
     $compelems = $this->get_completion_elements();
     if (!empty($compelems)) {
         foreach ($compelems as $compelem) {
             $compelem = addslashes_recursive($compelem);
             unset($compelem->id);
             $clone->save_completion_element($compelem);
         }
     }
     // copy template
     $template = $CURMAN->db->get_record(CTTABLE, 'courseid', $this->id);
     $template = new coursetemplate($template);
     unset($template->id);
     $template->courseid = $clone->id;
     $template->add();
     // FIXME: copy tags
     // copy the classes
     if (!empty($options['classes'])) {
         $classes = cmclass_get_record_by_courseid($this->id);
         if (!empty($classes)) {
             $objs['classes'] = array();
             foreach ($classes as $class) {
                 $class = new cmclass($class);
                 $rv = $class->duplicate($options);
                 if (isset($rv['errors']) && !empty($rv['errors'])) {
                     $objs['errors'] = array_merge($objs['errors'], $rv['errors']);
                 }
                 if (isset($rv['classes'])) {
                     $objs['classes'] = $objs['classes'] + $rv['classes'];
                 }
             }
         }
     }
     return $objs;
 }
コード例 #4
0
/**
 * Attach a class record from this system to an existing Moodle course.
 *
 * @uses $CURMAN
 * @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)
{
    global $CURMAN;
    $result = true;
    $moodlecourseid = $mdlid;
    /// Look for an existing link for this class.
    if (!($clsmdl = $CURMAN->db->get_record(CLSMDLTABLE, '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 cmclass($clsid);
            $temp = new coursetemplate();
            $temp->data_load_record($cls->courseid);
            // no template defined, so do nothing
            if (empty($temp->id) || empty($temp->location)) {
                print_error('notemplate', 'block_curr_admin');
            }
            $classname = $temp->templateclass;
            $obj = new $classname();
            $courseId = $temp->location;
            //$obj->parseCourseId($temp->location);//print_object($courseid);die();
            $moodlecourseid = content_rollover($courseId, $cls->startdate);
            // Rename the fullname, shortname and idnumber of the restored course
            $restore->id = $moodlecourseid;
            $restore->fullname = addslashes($cls->course->name . '_' . $cls->idnumber);
            $restore->shortname = addslashes($cls->idnumber);
            $CURMAN->db->update_record('course', $restore);
        }
        $newrec = array('classid' => $clsid, 'moodlecourseid' => $moodlecourseid, 'siteconfig' => $siteconfig, 'autocreated' => $autocreate ? 1 : 0);
        $clsmdl = new classmoodlecourse($newrec);
        $result = $clsmdl->data_insert_record() === true;
    } else {
        $clsmdl = new classmoodlecourse($clsmdl->id);
    }
    if ($enrolinstructor) {
        $result = $result && $clsmdl->data_enrol_instructors();
    }
    if ($enrolstudent) {
        $result = $result && $clsmdl->data_enrol_students();
    }
    events_trigger('crlm_class_associated', $clsmdl);
    return $result;
}
コード例 #5
0
ファイル: track.class.php プロジェクト: jamesmcq/elis
 /**
  * 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);
 }
コード例 #6
0
ファイル: coursetemplateid.php プロジェクト: jamesmcq/elis
 * 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}";
}
コード例 #7
0
ファイル: pmclassform.class.php プロジェクト: jamesmcq/elis
    /**
     * 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);
            }
        }
    }
コード例 #8
0
/**
 * 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;
}
コード例 #9
0
ファイル: course.class.php プロジェクト: jamesmcq/elis
 /**
  * Clone a course.
  * @param array $options options for cloning.  Valid options are:
  * - 'classes': whether or not to clone classes (default: false)
  * - 'moodlecourses': whether or not to clone Moodle courses (if they were
  *   autocreated).  Values can be (default: "copyalways"):
  *   - "copyalways": always copy course
  *   - "copyautocreated": only copy autocreated courses
  *   - "autocreatenew": autocreate new courses from course template
  *   - "link": link to existing course
  * - 'targetcluster': the cluster id or cluster object (if any) to
  *   associate the clones with (default: none)
  * @return array array of array of object IDs created.  Key in outer array
  * is type of object (plural).  Key in inner array is original object ID,
  * value is new object ID.  Outer array also has an entry called 'errors',
  * which is an array of any errors encountered when duplicating the
  * object.
  */
 function duplicate(array $options)
 {
     require_once elispm::lib('data/pmclass.class.php');
     require_once elispm::lib('data/coursetemplate.class.php');
     $objs = array('errors' => array());
     if (isset($options['targetcluster'])) {
         $userset = $options['targetcluster'];
         if (!is_object($userset) || !is_a($userset, 'userset')) {
             $options['targetcluster'] = $userset = new userset($userset);
         }
     }
     // Due to lazy loading, we need to pre-load this object
     $this->load();
     // clone main course object
     $clone = new course($this);
     unset($clone->id);
     $idnumber = $clone->idnumber;
     $name = $clone->name;
     if (isset($userset)) {
         $to_append = ' - ' . $userset->name;
         // if cluster specified, append cluster's name to course
         $idnumber = append_once($idnumber, $to_append, array('maxlength' => 95));
         $name = append_once($name, $to_append, array('maxlength' => 250));
     }
     //get a unique idnumber
     $clone->idnumber = generate_unique_identifier(course::TABLE, 'idnumber', $idnumber, array('idnumber' => $idnumber));
     if ($clone->idnumber != $idnumber) {
         //get the suffix appended and add it to the name
         $parts = explode('.', $clone->idnumber);
         $suffix = end($parts);
         $clone->name = $name . '.' . $suffix;
     } else {
         $clone->name = $name;
     }
     $clone->save();
     $objs['courses'] = array($this->id => $clone->id);
     $options['targetcourse'] = $clone->id;
     // copy completion elements
     $compelems = $this->get_completion_elements();
     foreach ($compelems as $compelem) {
         unset($compelem->id);
         $clone->save_completion_element($compelem);
     }
     unset($compelems);
     // copy template
     $template = $this->_db->get_record(coursetemplate::TABLE, array('courseid' => $this->id));
     $template = new coursetemplate($template);
     unset($template->id);
     $template->courseid = $clone->id;
     $template->save();
     // copy the classes
     if (!empty($options['classes'])) {
         $classes = pmclass_get_record_by_courseid($this->id);
         if (!empty($classes)) {
             $objs['classes'] = array();
             foreach ($classes as $class) {
                 $class = new pmclass($class);
                 $rv = $class->duplicate($options);
                 if (isset($rv['errors']) && !empty($rv['errors'])) {
                     $objs['errors'] = array_merge($objs['errors'], $rv['errors']);
                 }
                 if (isset($rv['classes'])) {
                     $objs['classes'] = $objs['classes'] + $rv['classes'];
                 }
             }
         }
     }
     return $objs;
 }
コード例 #10
0
ファイル: version1elis.class.php プロジェクト: jamesmcq/elis
 /**
  * Associate a course description to a Moodle template course, if necessary
  *
  * @param object $record The import record containing information about the moodle course
  * @param int $courseid The id of the course description
  */
 function associate_course_to_moodle_course($record, $courseid)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/setup.php';
     require_once elispm::lib('data/coursetemplate.class.php');
     if (isset($record->link)) {
         //attempt to associate this course description to a Moodle course
         if ($mdlcourseid = $DB->get_field('course', 'id', array('shortname' => $record->link))) {
             //valid Moodle course, so associate
             $coursetemplate = new coursetemplate(array('courseid' => $courseid, 'location' => $mdlcourseid, 'templateclass' => 'moodlecourseurl'));
             $coursetemplate->save();
         }
     }
     //TODO: return a status, add error handling
 }
コード例 #11
0
ファイル: courseform.class.php プロジェクト: jamesmcq/elis
 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();
 }
コード例 #12
0
ファイル: approvepage.class.php プロジェクト: jamesmcq/elis
 /**
  * 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();
             }
         }
     }
 }