function action_copycurr()
 {
     global $CFG;
     // TODO: replace print_object messages with notice messages
     $sesskey = required_param('sesskey', PARAM_TEXT);
     if (!confirm_sesskey($sesskey)) {
         print_error('invalidsesskey', 'error', 'index.php');
     }
     $data = (array) data_submitted();
     $clusterid = $this->required_param('id', PARAM_INT);
     if (empty($data)) {
         notify(get_string('nodatasubmit', 'block_curr_admin'), 'red');
     }
     $targetcluster = new cluster($clusterid);
     // Retrieve all of the curriculums that need to be copied and assigned
     $prefixlen = strlen(self::CPY_CURR_PREFIX);
     foreach ($data as $datakey => $datavalue) {
         if (0 === strncmp($datakey, self::CPY_CURR_PREFIX, $prefixlen)) {
             $currid = (int) substr($datakey, $prefixlen);
             if (!$currid) {
                 continue;
             }
             $curr = new curriculum($currid);
             $options = array('targetcluster' => $targetcluster);
             if ($this->optional_param(self::CPY_CURR_TRK_PREFIX . $currid, 0, PARAM_INT)) {
                 $options['tracks'] = true;
             }
             if ($this->optional_param(self::CPY_CURR_CRS_PREFIX . $currid, 0, PARAM_INT)) {
                 $options['courses'] = true;
             }
             if ($this->optional_param(self::CPY_CURR_CLS_PREFIX . $currid, 0, PARAM_INT)) {
                 $options['classes'] = true;
             }
             if ($this->optional_param(self::CPY_CURR_TRK_PREFIX . $currid, 0, PARAM_INT)) {
                 $options['tracks'] = true;
             }
             $options['moodlecourses'] = $this->optional_param(self::CPY_CURR_MDLCRS_PREFIX . $currid, 'copyalways', PARAM_ALPHA);
             $rv = $curr->duplicate($options);
             if (!empty($rv['errors'])) {
                 foreach ($rv['errors'] as $error) {
                     notify($error);
                 }
             }
             /**
              * The following block of code performs any necessary post-processing,
              * primarily used for copying role assignments
              */
             //we need to handle curricula first in case role assignments
             //at lower levels become redundant
             if (!empty($rv['curricula'])) {
                 $curriculum = new stdClass();
                 $curriculum->id = $rv['curricula'][$curr->id];
                 curriculumpage::after_cm_entity_add($curriculum);
             }
             if (!empty($rv['tracks'])) {
                 foreach ($rv['tracks'] as $trackid) {
                     $track = new stdClass();
                     $track->id = $trackid;
                     trackpage::after_cm_entity_add($track);
                 }
             }
             if (!empty($rv['courses'])) {
                 foreach ($rv['courses'] as $courseid) {
                     $course = new stdClass();
                     $course->id = $courseid;
                     coursepage::after_cm_entity_add($course);
                 }
             }
             if (!empty($rv['classes'])) {
                 foreach ($rv['classes'] as $classid) {
                     $class = new stdClass();
                     $class->id = $classid;
                     cmclasspage::after_cm_entity_add($class);
                 }
             }
             if (!empty($rv['curricula'])) {
                 $newcurr = new curriculum($rv['curricula'][$curr->id]);
                 $curr->newname = $newcurr->name;
                 notify(get_string('clustcpycurr', 'block_curr_admin', $curr), 'notifysuccess');
             }
         }
     }
     redirect($CFG->wwwroot . '/curriculum/index.php?id=' . $data['id'] . '&s=clstcur', '', 2);
 }
示例#2
0
 /**
  * Test creating a new program entity with a default role assignment defined.
  */
 public function test_createprogramwithdefaultroleassignment()
 {
     global $DB, $USER;
     list($rcid, $reid) = $this->create_roles('program');
     // Setup the editor role to be the default role for the program context.
     elis::$config->local_elisprogram->default_curriculum_role_id = $reid;
     $sysctx = context_system::instance();
     // Assign the test user the creator role.
     role_assign($rcid, 100, $sysctx->id);
     // Create a new program entity.
     $data = array('idnumber' => 'program100', 'name' => 'program100', 'description' => 'program100');
     $obj = new curriculum($data);
     $obj->save();
     // Initialize a new program management page and invoke the code that handles default role assignments.
     $page = new curriculumpage();
     $page->after_cm_entity_add($obj);
     $programctx = \local_elisprogram\context\program::instance($obj->id);
     $params = array('roleid' => $reid, 'userid' => $USER->id, 'contextid' => $programctx->id);
     $this->assertTrue($DB->record_exists('role_assignments', $params));
 }