Пример #1
0
 /**
  * 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);
 }
Пример #2
0
 public function test_resolve_category_by_path()
 {
     $this->resetAfterTest(true);
     $cat1 = $this->getDataGenerator()->create_category(array('name' => 'Cat 1'));
     $cat1_1 = $this->getDataGenerator()->create_category(array('name' => 'Cat 1.1', 'parent' => $cat1->id));
     $cat1_1_1 = $this->getDataGenerator()->create_category(array('name' => 'Cat 1.1.1', 'parent' => $cat1_1->id));
     $cat1_1_2 = $this->getDataGenerator()->create_category(array('name' => 'Cat 1.1.2', 'parent' => $cat1_1->id));
     $cat1_2 = $this->getDataGenerator()->create_category(array('name' => 'Cat 1.2', 'parent' => $cat1->id));
     $cat2 = $this->getDataGenerator()->create_category(array('name' => 'Cat 2'));
     $cat2_1 = $this->getDataGenerator()->create_category(array('name' => 'Cat 2.1', 'parent' => $cat2->id, 'visible' => false));
     $cat2_1_1 = $this->getDataGenerator()->create_category(array('name' => 'Cat 2.1.1', 'parent' => $cat2_1->id));
     $cat2_1_2 = $this->getDataGenerator()->create_category(array('name' => 'Cat 2.1.2', 'parent' => $cat2_1->id));
     $cat2_2 = $this->getDataGenerator()->create_category(array('name' => 'Cat 2.2', 'parent' => $cat2->id));
     $cat3 = $this->getDataGenerator()->create_category(array('name' => 'Cat 3'));
     $cat3_1 = $this->getDataGenerator()->create_category(array('name' => 'Cat 3.1 Doubled', 'parent' => $cat3->id));
     $cat3_1b = $this->getDataGenerator()->create_category(array('name' => 'Cat 3.1 Doubled', 'parent' => $cat3->id));
     $cat3_1_1 = $this->getDataGenerator()->create_category(array('name' => 'Cat 3.1.1', 'parent' => $cat3_1->id));
     $cat3_fakedouble = $this->getDataGenerator()->create_category(array('name' => 'Cat 3.1.1', 'parent' => $cat3->id));
     // Existing categories. Doubled for cache testing.
     $path = array('Cat 1');
     $this->assertEquals($cat1->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     $this->assertEquals($cat1->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     $path = array('Cat 1', 'Cat 1.1', 'Cat 1.1.2');
     $this->assertEquals($cat1_1_2->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     $this->assertEquals($cat1_1_2->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     $path = array('Cat 1', 'Cat 1.2');
     $this->assertEquals($cat1_2->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     $this->assertEquals($cat1_2->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     $path = array('Cat 2');
     $this->assertEquals($cat2->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     $this->assertEquals($cat2->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     // Hidden category.
     $path = array('Cat 2', 'Cat 2.1');
     $this->assertEquals($cat2_1->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     $this->assertEquals($cat2_1->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     // Hidden parent.
     $path = array('Cat 2', 'Cat 2.1', 'Cat 2.1.2');
     $this->assertEquals($cat2_1_2->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     $this->assertEquals($cat2_1_2->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     // Does not exist.
     $path = array('No cat 3', 'Cat 1.2');
     $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_path($path));
     $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_path($path));
     $path = array('Cat 2', 'Cat 2.x');
     $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_path($path));
     $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_path($path));
     // Name conflict.
     $path = array('Cat 3', 'Cat 3.1 Doubled');
     $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_path($path));
     $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_path($path));
     $path = array('Cat 3', 'Cat 3.1 Doubled', 'Cat 3.1.1');
     $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_path($path));
     $this->assertEmpty(tool_uploadcourse_helper::resolve_category_by_path($path));
     $path = array('Cat 3', 'Cat 3.1.1');
     $this->assertEquals($cat3_fakedouble->id, tool_uploadcourse_helper::resolve_category_by_path($path));
     $this->assertEquals($cat3_fakedouble->id, tool_uploadcourse_helper::resolve_category_by_path($path));
 }
Пример #3
0
 /**
  * Get the directory of the object to restore.
  *
  * @return string subdirectory in $CFG->tempdir/backup/...
  */
 protected function get_restore_content_dir()
 {
     $backupfile = null;
     $shortname = null;
     if (!empty($this->restorefile)) {
         $backupfile = $this->restorefile;
     } else {
         if (!empty($this->templatecourse) || is_numeric($this->templatecourse)) {
             $shortname = $this->templatecourse;
         }
     }
     $dir = tool_uploadcourse_helper::get_restore_content_dir($backupfile, $shortname);
     return $dir;
 }