예제 #1
0
 public function test_get_role_names()
 {
     $this->resetAfterTest(true);
     create_role('Villain', 'villain', 'The bad guys');
     $data = array('role_student' => 'Padawan', 'role_teacher' => 'Guardian', 'role_editingteacher' => 'Knight', 'role_manager' => 'Master', 'role_villain' => 'Jabba the Hutt', 'role_android' => 'R2D2');
     // Get the role IDs, but need to force the cache reset as a new role is defined.
     $roleids = tool_uploadcourse_helper::get_role_ids(true);
     $expected = array('role_' . $roleids['student'] => 'Padawan', 'role_' . $roleids['teacher'] => 'Guardian', 'role_' . $roleids['editingteacher'] => 'Knight', 'role_' . $roleids['manager'] => 'Master', 'role_' . $roleids['villain'] => 'Jabba the Hutt');
     $errors = array();
     $actual = tool_uploadcourse_helper::get_role_names($data, $errors);
     $this->assertSame($actual, $expected);
     $this->assertArrayHasKey('invalidroles', $errors);
 }
예제 #2
0
파일: course.php 프로젝트: evltuma/moodle
 /**
  * Reset the current course.
  *
  * This does not reset any of the content of the activities.
  *
  * @param stdClass $course the course object of the course to reset.
  * @return array status array of array component, item, error.
  */
 protected function reset($course)
 {
     global $DB;
     $resetdata = new stdClass();
     $resetdata->id = $course->id;
     $resetdata->reset_start_date = time();
     $resetdata->reset_events = true;
     $resetdata->reset_notes = true;
     $resetdata->delete_blog_associations = true;
     $resetdata->reset_completion = true;
     $resetdata->reset_roles_overrides = true;
     $resetdata->reset_roles_local = true;
     $resetdata->reset_groups_members = true;
     $resetdata->reset_groups_remove = true;
     $resetdata->reset_groupings_members = true;
     $resetdata->reset_groupings_remove = true;
     $resetdata->reset_gradebook_items = true;
     $resetdata->reset_gradebook_grades = true;
     $resetdata->reset_comments = true;
     if (empty($course->startdate)) {
         $course->startdate = $DB->get_field_select('course', 'startdate', 'id = :id', array('id' => $course->id));
     }
     $resetdata->reset_start_date_old = $course->startdate;
     // Add roles.
     $roles = tool_uploadcourse_helper::get_role_ids();
     $resetdata->unenrol_users = array_values($roles);
     $resetdata->unenrol_users[] = 0;
     // Enrolled without role.
     return reset_course_userdata($resetdata);
 }