function action_savenew()
 {
     $id = $this->required_param('id', PARAM_INT);
     $autounenrol = $this->optional_param('autounenrol', 1, PARAM_INT);
     $clusterid = $this->required_param('clusterid', PARAM_INT);
     $trackid = $this->required_param('trackid', PARAM_INT);
     require_once CURMAN_DIRLOCATION . '/form/' . $this->form_class . '.class.php';
     require_once CURMAN_DIRLOCATION . '/plugins/cluster_classification/clusterclassification.class.php';
     $target = $this->get_new_page(array('action' => 'savenew', 'id' => $id, 'clusterid' => $clusterid, 'trackid' => $trackid));
     $form = new $this->form_class($target->get_moodle_url(), array('id' => $id, 'clusterid' => $clusterid, 'trackid' => $trackid));
     $form->set_data(array('clusterid' => $clusterid, 'trackid' => $trackid));
     if ($data = $form->get_data()) {
         if (!isset($data->cancel)) {
             clustertrack::associate($clusterid, $trackid, $autounenrol, $data->autoenrol);
         }
         $this->action_default();
     } else {
         $cluster_classification = clusterclassification::get_for_cluster($clusterid);
         if (!empty($cluster_classification->param_autoenrol_tracks)) {
             $form->set_data(array('autoenrol' => 1));
         } else {
             $form->set_data(array('autoenrol' => 0));
         }
         $form->display();
     }
 }
Exemplo n.º 2
0
 /**
  * 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(array $options = array())
 {
     $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 track object
     $clone = new track($this);
     unset($clone->id);
     if (isset($options['targetcurriculum'])) {
         $clone->curid = $options['targetcurriculum'];
     }
     $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(track::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->autocreate = false;
     // avoid warnings
     $clone->save();
     $objs['tracks'] = array($this->id => $clone->id);
     // associate with target cluster (if any)
     if (isset($userset)) {
         clustertrack::associate($userset->id, $clone->id);
     }
     // copy classes
     $clstrks = track_assignment_get_listing($this->id);
     if ($clstrks->valid() === true) {
         $objs['classes'] = array();
         if (!isset($options['classmap'])) {
             $options['classmap'] = array();
         }
         foreach ($clstrks as $clstrkdata) {
             $newclstrk = new trackassignment($clstrkdata);
             $newclstrk->trackid = $clone->id;
             unset($newclstrk->id);
             if (isset($options['classmap'][$clstrkdata->clsid])) {
                 // use existing duplicate class
                 $class = new pmclass($options['classmap'][$clstrkdata->clsid]);
             } else {
                 // no existing duplicate -> duplicate class
                 $class = new pmclass($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->save();
         }
     }
     unset($clstrks);
     return $objs;
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * Assign tracks to the userset.
  * @param array $elements An array of track information to assign to the userset.
  * @param bool $bulkaction Whether this is a bulk-action or not.
  * @return array An array to format as JSON and return to the Javascript.
  */
 protected function _respond_to_js(array $elements, $bulkaction)
 {
     global $DB;
     $usersetid = required_param('id', PARAM_INT);
     $autoenrol = optional_param('autoenrol', 0, PARAM_INT);
     $autounenrol = optional_param('autounenrol', 1, PARAM_INT);
     foreach ($elements as $trackid => $label) {
         if ($this->can_assign($usersetid, $trackid) === true) {
             clustertrack::associate($usersetid, $trackid, $autounenrol, $autoenrol);
         }
     }
     return array('result' => 'success', 'msg' => 'Success');
 }