/** * Data function to insert a database record with the object contents. * * @param $record object If present, uses the contents of it rather than the object. * @return boolean Status of the operation. * @uses $CURMAN global. */ function data_insert_record($record = false) { $status = parent::data_insert_record($record); if (isset($this->track)) { $param['classid'] = $this->id; $param['courseid'] = $this->courseid; foreach ($this->track as $t) { $param['trackid'] = $t; $trackassignobj = new trackassignmentclass($param); $trackassignobj->add(); } } if (!empty($this->moodlecourseid)) { moodle_attach_class($this->id, $this->moodlecourseid); } return $status; }
/** * Clone a track * @param array $options options for cloning. Valid options are: * - 'targetcurriculum': the curriculum id to associate the clones with * (default: same as original track) * - 'classmap': a mapping of class IDs to use from the original track to * the cloned track. If a class from the original track is not mapped, a * new class will be created * - 'moodlecourse': 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 * @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 = array()) { global $CURMAN; $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 track object $clone = new track($this); unset($clone->id); if (isset($options['targetcurriculum'])) { $clone->curid = $options['targetcurriculum']; } if (isset($cluster)) { // if cluster specified, append cluster's name to track $clone->idnumber = $clone->idnumber . ' - ' . $cluster->name; $clone->name = $clone->name . ' - ' . $cluster->name; } $clone = new track(addslashes_recursive($clone)); $clone->autocreate = false; // avoid warnings if (!$clone->add()) { $objs['errors'][] = get_string('failclustcpytrk', 'block_curr_admin', $this); return $objs; } $objs['tracks'] = array($this->id => $clone->id); // associate with target cluster (if any) if (isset($cluster)) { clustertrack::associate($cluster->id, $clone->id); } // copy classes $clstrks = track_assignment_get_listing($this->id); if (!empty($clstrks)) { $objs['classes'] = array(); if (!isset($options['classmap'])) { $options['classmap'] = array(); } foreach ($clstrks as $clstrkdata) { $newclstrk = new trackassignmentclass($clstrkdata); $newclstrk->trackid = $clone->id; unset($newclstrk->id); if (isset($options['classmap'][$clstrkdata->clsid])) { // use existing duplicate class $class = new cmclass($options['classmap'][$clstrkdata->clsid]); } else { // no existing duplicate -> duplicate class $class = new cmclass($clstrkdata->clsid); $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']; } } $newclstrk->classid = $class->id; $newclstrk->courseid = $class->courseid; $newclstrk->add(); } } return $objs; }