当前位置: 首页>>代码示例>>PHP>>正文


PHP course_modinfo类代码示例

本文整理汇总了PHP中course_modinfo的典型用法代码示例。如果您正苦于以下问题:PHP course_modinfo类的具体用法?PHP course_modinfo怎么用?PHP course_modinfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了course_modinfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_activity_tree

/**
 * get_activity_tree :: course_modinfo -> integer -> context -> array
 * @param \course_modinfo $modinfo
 * @param integer $section_number
 * @param \context $context
 * @return array
 */
function get_activity_tree(\course_modinfo $modinfo, $section_number, \context $context)
{
    $completion_info = new \completion_info($modinfo->get_course());
    return F\map(F\filter($modinfo->get_section_info_all(), function (\section_info $section_info) {
        return $section_info->visible;
    }), function (\section_info $section_info) use($completion_info, $section_number, $context) {
        $mods = F\map(F\filter($section_info->modinfo->cms, function (\cm_info $cm_info) use($section_info) {
            global $CFG;
            return ($cm_info->uservisible || $CFG->enableavailability && !empty($cm_info->availableinfo)) && (int) $cm_info->sectionnum === (int) $section_info->section;
        }), function (\cm_info $cm_info) use($completion_info, $context) {
            global $CFG;
            $canComplete = $CFG->enablecompletion && isloggedin() && !isguestuser() && (int) $completion_info->is_enabled($cm_info) === COMPLETION_TRACKING_MANUAL;
            $hasCompleted = false;
            if ($canComplete) {
                $completion_data = $completion_info->get_data($cm_info, true);
                $hasCompleted = F\contains([COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS], (int) $completion_data->completionstate);
            }
            return (object) ['id' => (int) $cm_info->id, 'name' => $cm_info->name, 'modname' => $cm_info->modname, 'current' => is_current_mod($cm_info, $context), 'available' => $cm_info->available, 'canComplete' => $canComplete, 'hasCompleted' => $hasCompleted];
        });
        return (object) ['id' => (int) $section_info->id, 'section' => (int) $section_info->section, 'name' => \get_section_name($section_info->modinfo->courseid, $section_info->section), 'current' => is_current_section($section_info, $section_number, $context), 'activities' => array_values($mods)];
    });
}
开发者ID:robologo3000,项目名称:block-activity-tree,代码行数:29,代码来源:lib.php

示例2: test_glossary_view

 public function test_glossary_view()
 {
     global $CFG;
     $origcompletion = $CFG->enablecompletion;
     $CFG->enablecompletion = true;
     $this->resetAfterTest(true);
     // Generate all the things.
     $c1 = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
     $g1 = $this->getDataGenerator()->create_module('glossary', array('course' => $c1->id, 'completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1));
     $g2 = $this->getDataGenerator()->create_module('glossary', array('course' => $c1->id, 'completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1));
     $u1 = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($u1->id, $c1->id);
     $modinfo = course_modinfo::instance($c1->id);
     $cm1 = $modinfo->get_cm($g1->cmid);
     $cm2 = $modinfo->get_cm($g2->cmid);
     $ctx1 = $cm1->context;
     $completion = new completion_info($c1);
     $this->setUser($u1);
     // Confirm what we've set up.
     $this->assertEquals(COMPLETION_NOT_VIEWED, $completion->get_data($cm1, false, $u1->id)->viewed);
     $this->assertEquals(COMPLETION_INCOMPLETE, $completion->get_data($cm1, false, $u1->id)->completionstate);
     $this->assertEquals(COMPLETION_NOT_VIEWED, $completion->get_data($cm2, false, $u1->id)->viewed);
     $this->assertEquals(COMPLETION_INCOMPLETE, $completion->get_data($cm2, false, $u1->id)->completionstate);
     // Simulate the view call.
     $sink = $this->redirectEvents();
     glossary_view($g1, $c1, $cm1, $ctx1, 'letter');
     $events = $sink->get_events();
     // Assertions.
     $this->assertCount(3, $events);
     $this->assertEquals('\\core\\event\\course_module_completion_updated', $events[0]->eventname);
     $this->assertEquals('\\core\\event\\course_module_completion_updated', $events[1]->eventname);
     $this->assertEquals('\\mod_glossary\\event\\course_module_viewed', $events[2]->eventname);
     $this->assertEquals($g1->id, $events[2]->objectid);
     $this->assertEquals('letter', $events[2]->other['mode']);
     $this->assertEquals(COMPLETION_VIEWED, $completion->get_data($cm1, false, $u1->id)->viewed);
     $this->assertEquals(COMPLETION_COMPLETE, $completion->get_data($cm1, false, $u1->id)->completionstate);
     $this->assertEquals(COMPLETION_NOT_VIEWED, $completion->get_data($cm2, false, $u1->id)->viewed);
     $this->assertEquals(COMPLETION_INCOMPLETE, $completion->get_data($cm2, false, $u1->id)->completionstate);
     // Tear down.
     $sink->close();
     $CFG->enablecompletion = $origcompletion;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:42,代码来源:lib_test.php

示例3: test_concept_fetching


//.........这里部分代码省略.........
             $this->assertEquals($entry1a1->id, $concept->id);
             $this->assertEquals($glossary1a->id, $concept->glossaryid);
             $this->assertEquals(0, $concept->category);
         } else {
             if ($concept->concept === 'prvni') {
                 $this->assertEquals($entry1a1->id, $concept->id);
                 $this->assertEquals($glossary1a->id, $concept->glossaryid);
                 $this->assertEquals(0, $concept->category);
             } else {
                 if ($concept->concept === 'erste') {
                     $this->assertEquals($entry1a1->id, $concept->id);
                     $this->assertEquals($glossary1a->id, $concept->glossaryid);
                     $this->assertEquals(0, $concept->category);
                 } else {
                     if ($concept->concept === 'A&B') {
                         $this->assertEquals($entry1a2->id, $concept->id);
                         $this->assertEquals($glossary1a->id, $concept->glossaryid);
                         $this->assertEquals(0, $concept->category);
                     } else {
                         if ($concept->concept === 'special') {
                             $this->assertEquals($cat1->id, $concept->id);
                             $this->assertEquals($glossary1a->id, $concept->glossaryid);
                             $this->assertEquals(1, $concept->category);
                         } else {
                             $this->fail('Unexpected concept: ' . $concept->concept);
                         }
                     }
                 }
             }
         }
     }
     $this->assertCount(1, $concepts1[1][$glossary1b->id]);
     foreach ($concepts1[1][$glossary1b->id] as $concept) {
         $this->assertSame(array('id', 'glossaryid', 'concept', 'casesensitive', 'category', 'fullmatch'), array_keys((array) $concept));
         if ($concept->concept === 'second') {
             $this->assertEquals($entry1b1->id, $concept->id);
             $this->assertEquals($glossary1b->id, $concept->glossaryid);
             $this->assertEquals(0, $concept->category);
         } else {
             $this->fail('Unexpected concept: ' . $concept->concept);
         }
     }
     $this->assertCount(2, $concepts1[1][$glossary3->id]);
     foreach ($concepts1[1][$glossary3->id] as $concept) {
         $this->assertSame(array('id', 'glossaryid', 'concept', 'casesensitive', 'category', 'fullmatch'), array_keys((array) $concept));
         if ($concept->concept === 'global') {
             $this->assertEquals($entry31->id, $concept->id);
             $this->assertEquals($glossary3->id, $concept->glossaryid);
             $this->assertEquals(0, $concept->category);
         } else {
             if ($concept->concept === 'globalni') {
                 $this->assertEquals($entry31->id, $concept->id);
                 $this->assertEquals($glossary3->id, $concept->glossaryid);
                 $this->assertEquals(0, $concept->category);
             } else {
                 $this->fail('Unexpected concept: ' . $concept->concept);
             }
         }
     }
     $concepts3 = \mod_glossary\local\concept_cache::get_concepts($site->id);
     $this->assertCount(1, $concepts3[0]);
     $this->arrayHasKey($concepts3[0], $glossary3->id);
     $this->assertCount(1, $concepts3[1]);
     $this->arrayHasKey($concepts3[0], $glossary3->id);
     foreach ($concepts3[1][$glossary3->id] as $concept) {
         $this->assertSame(array('id', 'glossaryid', 'concept', 'casesensitive', 'category', 'fullmatch'), array_keys((array) $concept));
         if ($concept->concept === 'global') {
             $this->assertEquals($entry31->id, $concept->id);
             $this->assertEquals($glossary3->id, $concept->glossaryid);
             $this->assertEquals(0, $concept->category);
         } else {
             if ($concept->concept === 'globalni') {
                 $this->assertEquals($entry31->id, $concept->id);
                 $this->assertEquals($glossary3->id, $concept->glossaryid);
                 $this->assertEquals(0, $concept->category);
             } else {
                 $this->fail('Unexpected concept: ' . $concept->concept);
             }
         }
     }
     $concepts2 = \mod_glossary\local\concept_cache::get_concepts($course2->id);
     $this->assertEquals($concepts3, $concepts2);
     // Test uservisible flag.
     set_config('enableavailability', 1);
     $glossary1d = $this->getDataGenerator()->create_module('glossary', array('course' => $course1->id, 'mainglossary' => 1, 'usedynalink' => 1, 'availability' => json_encode(\core_availability\tree::get_root_json(array(\availability_group\condition::get_json())))));
     $entry1d1 = $generator->create_content($glossary1d, array('concept' => 'membersonly', 'usedynalink' => 1));
     $user = $this->getDataGenerator()->create_user();
     $this->getDataGenerator()->enrol_user($user->id, $course1->id);
     $this->getDataGenerator()->enrol_user($user->id, $course2->id);
     \mod_glossary\local\concept_cache::reset_caches();
     $concepts1 = \mod_glossary\local\concept_cache::get_concepts($course1->id);
     $this->assertCount(4, $concepts1[0]);
     $this->assertCount(4, $concepts1[1]);
     $this->setUser($user);
     course_modinfo::clear_instance_cache();
     \mod_glossary\local\concept_cache::reset_caches();
     $concepts1 = \mod_glossary\local\concept_cache::get_concepts($course1->id);
     $this->assertCount(3, $concepts1[0]);
     $this->assertCount(3, $concepts1[1]);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:concept_cache_test.php

示例4: test_matching_cacherev

 public function test_matching_cacherev()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     $this->setAdminUser();
     $cache = cache::make('core', 'coursemodinfo');
     // Generate the course and pre-requisite module.
     $course = $this->getDataGenerator()->create_course(array('format' => 'topics', 'numsections' => 3), array('createsections' => true));
     // Make sure the cacherev is set.
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertGreaterThan(0, $cacherev);
     $prevcacherev = $cacherev;
     // Reset course cache and make sure cacherev is bumped up but cache is empty.
     rebuild_course_cache($course->id, true);
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertGreaterThan($prevcacherev, $cacherev);
     $this->assertEmpty($cache->get($course->id));
     $prevcacherev = $cacherev;
     // Build course cache. Cacherev should not change but cache is now not empty. Make sure cacherev is the same everywhere.
     $modinfo = get_fast_modinfo($course->id);
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertEquals($prevcacherev, $cacherev);
     $cachedvalue = $cache->get($course->id);
     $this->assertNotEmpty($cachedvalue);
     $this->assertEquals($cacherev, $cachedvalue->cacherev);
     $this->assertEquals($cacherev, $modinfo->get_course()->cacherev);
     $prevcacherev = $cacherev;
     // Little trick to check that cache is not rebuilt druing the next step - substitute the value in MUC and later check that it is still there.
     $cache->set($course->id, (object) array_merge((array) $cachedvalue, array('secretfield' => 1)));
     // Clear static cache and call get_fast_modinfo() again (pretend we are in another request). Cache should not be rebuilt.
     course_modinfo::clear_instance_cache();
     $modinfo = get_fast_modinfo($course->id);
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertEquals($prevcacherev, $cacherev);
     $cachedvalue = $cache->get($course->id);
     $this->assertNotEmpty($cachedvalue);
     $this->assertEquals($cacherev, $cachedvalue->cacherev);
     $this->assertNotEmpty($cachedvalue->secretfield);
     $this->assertEquals($cacherev, $modinfo->get_course()->cacherev);
     $prevcacherev = $cacherev;
     // Rebuild course cache. Cacherev must be incremented everywhere.
     rebuild_course_cache($course->id);
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertGreaterThan($prevcacherev, $cacherev);
     $cachedvalue = $cache->get($course->id);
     $this->assertNotEmpty($cachedvalue);
     $this->assertEquals($cacherev, $cachedvalue->cacherev);
     $modinfo = get_fast_modinfo($course->id);
     $this->assertEquals($cacherev, $modinfo->get_course()->cacherev);
     $prevcacherev = $cacherev;
     // Update cacherev in DB and make sure the cache will be rebuilt on the next call to get_fast_modinfo().
     increment_revision_number('course', 'cacherev', 'id = ?', array($course->id));
     // We need to clear static cache for course_modinfo instances too.
     course_modinfo::clear_instance_cache();
     $modinfo = get_fast_modinfo($course->id);
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertGreaterThan($prevcacherev, $cacherev);
     $cachedvalue = $cache->get($course->id);
     $this->assertNotEmpty($cachedvalue);
     $this->assertEquals($cacherev, $cachedvalue->cacherev);
     $this->assertEquals($cacherev, $modinfo->get_course()->cacherev);
     $prevcacherev = $cacherev;
     // Reset cache for all courses and make sure this course cache is reset.
     rebuild_course_cache(0, true);
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertGreaterThan($prevcacherev, $cacherev);
     $this->assertEmpty($cache->get($course->id));
     // Rebuild again.
     $modinfo = get_fast_modinfo($course->id);
     $cachedvalue = $cache->get($course->id);
     $this->assertNotEmpty($cachedvalue);
     $this->assertEquals($cacherev, $cachedvalue->cacherev);
     $this->assertEquals($cacherev, $modinfo->get_course()->cacherev);
     $prevcacherev = $cacherev;
     // Purge all caches and make sure cacherev is increased and data from MUC erased.
     purge_all_caches();
     $cacherev = $DB->get_field('course', 'cacherev', array('id' => $course->id));
     $this->assertGreaterThan($prevcacherev, $cacherev);
     $this->assertEmpty($cache->get($course->id));
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:80,代码来源:modinfolib_test.php

示例5: render_subpage

 /**
  * Render contents of main part of subpage
  * @param mod_subpage $subpage
  * @param course_modinfo $modinfo
  * @param array $sections
  * @param boolean $editing whether the user is allowed to edit this page
  * @param int $moveitem (currently not used)
  * @param boolean $movesection whether the user is allowed to move sections
  * @return string html for display
  */
 public function render_subpage($subpage, $modinfo, $sections, $editing, $moveitem, $movesection)
 {
     global $PAGE, $OUTPUT, $CFG, $USER;
     $this->subpagecm = $subpage->get_course_module()->id;
     if (!empty($USER->activitycopy) && $movesection) {
         $content = $this->render_cancel_link($this->subpagecm);
     } else {
         $content = '';
     }
     $content .= $this->render_intro($subpage);
     $streditsummary = get_string('editsummary');
     $strdelete = get_string('delete');
     if ($editing) {
         $strmoveup = get_string('moveup');
         $strmovedown = get_string('movedown');
         $strhide = get_string('hide');
         $strshow = get_string('show');
         $strstealth = get_string('stealth', 'subpage');
         $strunstealth = get_string('unstealth', 'subpage');
     }
     $coursecontext = get_context_instance(CONTEXT_COURSE, $subpage->get_course()->id);
     get_all_mods($subpage->get_course()->id, $mods, $modnames, $modnamesplural, $modnamesused);
     foreach ($mods as $modid => $unused) {
         if (!isset($modinfo->cms[$modid])) {
             rebuild_course_cache($subpage->get_course()->id);
             $modinfo =& get_fast_modinfo($subpage->get_course());
             debugging('Rebuilding course cache', DEBUG_DEVELOPER);
             break;
         }
     }
     $lastpageorder = $subpage->get_last_section_pageorder();
     if ($subpage->get_course()->format == 'weeks') {
         $content .= html_writer::start_tag('ul', array('class' => 'weeks'));
     } else {
         $content .= html_writer::start_tag('ul', array('class' => 'topics'));
     }
     foreach ($sections as $section) {
         // Check to see whether cms within the section are visible or not
         // If all cms are not visible then we don't show the section at all,
         // unless editing
         $visible = false;
         if ($section->sequence) {
             // get cm_info for this resources
             $instances = explode(',', $section->sequence);
         } else {
             $instances = array();
         }
         foreach ($instances as $instance) {
             $cm = $modinfo->get_cm($instance);
             // check to see whether cm is visible
             if ($cm->uservisible) {
                 $visible = true;
                 break;
             }
         }
         // If section is empty so should be hidden, record that in object
         $section->autohide = !$visible;
         $content .= html_writer::start_tag('li', array('class' => 'section main clearfix', 'id' => 'section-' . $section->section));
         $content .= html_writer::tag('div', ' ', array('class' => 'left side'));
         $content .= html_writer::start_tag('div', array('class' => 'right side'));
         if ($editing && has_capability('moodle/course:update', $coursecontext)) {
             // Show the hide/show eye
             if ($section->visible) {
                 $content .= html_writer::start_tag('a', array('href' => 'view.php?id=' . $subpage->get_course_module()->id . '&hide=' . $section->section . '&sesskey=' . sesskey() . '#section-' . $section->id, 'title' => $strhide));
                 $content .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/hide'), 'class' => 'icon hide', 'alt' => $strhide));
                 $content .= html_writer::end_tag('a');
             } else {
                 $content .= html_writer::start_tag('a', array('href' => 'view.php?id=' . $subpage->get_course_module()->id . '&show=' . $section->section . '&sesskey=' . sesskey() . '#section-' . $section->id, 'title' => $strshow));
                 $content .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/show'), 'class' => 'icon show', 'alt' => $strshow));
                 $content .= html_writer::end_tag('a');
             }
             // Show the stealth/unstealth section link
             if ($section->stealth) {
                 $content .= html_writer::start_tag('form', array('method' => 'post', 'action' => 'stealth.php'));
                 $content .= html_writer::start_tag('div');
                 $content .= html_writer::empty_tag('input', array('name' => 'id', 'value' => $subpage->get_course_module()->id, 'type' => 'hidden'));
                 $content .= html_writer::empty_tag('input', array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden'));
                 $content .= html_writer::empty_tag('input', array('name' => 'unstealth', 'value' => $section->id, 'type' => 'hidden'));
                 $content .= html_writer::empty_tag('input', array('name' => 'icon', 'src' => $OUTPUT->pix_url('unstealth', 'mod_subpage'), 'type' => 'image', 'title' => $strunstealth, 'alt' => $strunstealth));
                 $content .= html_writer::end_tag('div');
                 $content .= html_writer::end_tag('form');
             } else {
                 $content .= html_writer::start_tag('form', array('method' => 'post', 'action' => 'stealth.php'));
                 $content .= html_writer::start_tag('div');
                 $content .= html_writer::empty_tag('input', array('name' => 'id', 'value' => $subpage->get_course_module()->id, 'type' => 'hidden'));
                 $content .= html_writer::empty_tag('input', array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden'));
                 $content .= html_writer::empty_tag('input', array('name' => 'stealth', 'value' => $section->id, 'type' => 'hidden'));
                 $content .= html_writer::empty_tag('input', array('name' => 'icon', 'src' => $OUTPUT->pix_url('stealth', 'mod_subpage'), 'type' => 'image', 'title' => $strstealth, 'alt' => $strstealth));
                 $content .= html_writer::end_tag('div');
                 $content .= html_writer::end_tag('form');
//.........这里部分代码省略.........
开发者ID:nadavkav,项目名称:moodle-mod_subpage,代码行数:101,代码来源:renderer.php

示例6: test_get_calendar_events


//.........这里部分代码省略.........
     $this->assertEquals(5, count($events['events']));
     $this->assertEquals(0, count($events['warnings']));
     $options = array('siteevents' => true, 'userevents' => true, 'timeend' => time() + 7 * WEEKSECS);
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertEquals(5, count($events['events']));
     $this->assertEquals(0, count($events['warnings']));
     // Let's play around with caps.
     $this->setUser($user);
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertEquals(2, count($events['events']));
     // site, user.
     $this->assertEquals(2, count($events['warnings']));
     // course, group.
     $role = $DB->get_record('role', array('shortname' => 'student'));
     $this->getDataGenerator()->enrol_user($user->id, $course->id, $role->id);
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertEquals(4, count($events['events']));
     // site, user, both course events.
     $this->assertEquals(1, count($events['warnings']));
     // group.
     $options = array('siteevents' => true, 'userevents' => true, 'timeend' => time() + HOURSECS);
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertEquals(3, count($events['events']));
     // site, user, one course event.
     $this->assertEquals(1, count($events['warnings']));
     // group.
     groups_add_member($group, $user);
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertEquals(4, count($events['events']));
     // site, user, group, one course event.
     $this->assertEquals(0, count($events['warnings']));
     $paramevents = array('courseids' => array($course->id), 'groupids' => array($group->id));
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertEquals(4, count($events['events']));
     // site, user, group, one course event.
     $this->assertEquals(0, count($events['warnings']));
     $paramevents = array('groupids' => array($group->id, 23));
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertEquals(3, count($events['events']));
     // site, user, group.
     $this->assertEquals(1, count($events['warnings']));
     $paramevents = array('courseids' => array(23));
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertEquals(2, count($events['events']));
     // site, user.
     $this->assertEquals(1, count($events['warnings']));
     $paramevents = array();
     $options = array('siteevents' => false, 'userevents' => false, 'timeend' => time() + 7 * WEEKSECS);
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertEquals(0, count($events['events']));
     // nothing returned.
     $this->assertEquals(0, count($events['warnings']));
     $paramevents = array('eventids' => array($siteevent->id, $groupevent->id));
     $options = array('siteevents' => false, 'userevents' => false, 'timeend' => time() + 7 * WEEKSECS);
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertEquals(2, count($events['events']));
     // site, group.
     $this->assertEquals(0, count($events['warnings']));
     $paramevents = array('eventids' => array($siteevent->id));
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertEquals(1, count($events['events']));
     // site.
     $this->assertEquals(0, count($events['warnings']));
     // Try getting a course event by its id.
     $paramevents = array('eventids' => array($courseevent->id));
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertEquals(1, count($events['events']));
     $this->assertEquals(0, count($events['warnings']));
     // Now, create an activity event.
     $this->setAdminUser();
     $nexttime = time() + DAYSECS;
     $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id, 'duedate' => $nexttime));
     $this->setUser($user);
     $paramevents = array('courseids' => array($course->id));
     $options = array('siteevents' => true, 'userevents' => true, 'timeend' => time() + WEEKSECS);
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     $this->assertCount(5, $events['events']);
     // Hide the assignment.
     set_coursemodule_visible($assign->cmid, 0);
     // Empty all the caches that may be affected  by this change.
     accesslib_clear_all_caches_for_unit_testing();
     course_modinfo::clear_instance_cache();
     $events = core_calendar_external::get_calendar_events($paramevents, $options);
     $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
     // Expect one less.
     $this->assertCount(4, $events['events']);
 }
开发者ID:jeffthestampede,项目名称:excelsior,代码行数:101,代码来源:externallib_test.php

示例7: get_course_test_data

 /**
  * Gets the data required to fill the test plan template with the database contents.
  *
  * @param int $targetcourseid The target course id
  * @return stdClass The ids required by the test plan
  */
 protected static function get_course_test_data($targetcourseid)
 {
     global $DB, $USER;
     $data = new stdClass();
     // Getting course contents info as the current user (will be an admin).
     $course = new stdClass();
     $course->id = $targetcourseid;
     $courseinfo = new course_modinfo($course, $USER->id);
     // Getting the first page module instance.
     if (!($pages = $courseinfo->get_instances_of('page'))) {
         print_error('error_nopageinstances', 'tool_generator');
     }
     $data->pageid = reset($pages)->id;
     // Getting the first forum module instance and it's first discussion and reply as well.
     if (!($forums = $courseinfo->get_instances_of('forum'))) {
         print_error('error_noforuminstances', 'tool_generator');
     }
     $forum = reset($forums);
     // Getting the first discussion (and reply).
     if (!($discussions = forum_get_discussions($forum, 'd.timemodified ASC', false, -1, 1))) {
         print_error('error_noforumdiscussions', 'tool_generator');
     }
     $discussion = reset($discussions);
     $data->forumid = $forum->id;
     $data->forumdiscussionid = $discussion->discussion;
     $data->forumreplyid = $discussion->id;
     // According to the current test plan.
     return $data;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:35,代码来源:testplan_backend.php

示例8: moveable_modules

 /**
  * Return an array of modules that can be moved in this situation
  *    The Array is keyed first with sections (subpage or main course)
  *    and then the modules within each section by cmid
  * @param Object $subpage current subpage
  * @param Array $allsubpages
  * @param Array $coursesections
  * @param Object $modinfo
  * @param String $move to or from
  * @return Array mixed
  */
 public static function moveable_modules($subpage, $allsubpages, $coursesections, course_modinfo $modinfo, $move)
 {
     global $OUTPUT;
     get_all_mods($subpage->get_course()->id, $allmods, $modnames, $modnamesplural, $modnamesused);
     $mods = array();
     $subsections = array();
     if (!empty($allsubpages) && $move === 'to') {
         foreach ($allsubpages as $sub) {
             $subsections += $sub->get_sections();
         }
         $sections = $coursesections;
     } else {
         $subsections = $subpage->get_sections();
         $sections = $subsections;
     }
     if ($sections) {
         foreach ($sections as $section) {
             if (!empty($section->sequence)) {
                 if ($move === 'to' && array_key_exists($section->id, $subsections)) {
                     continue;
                 }
                 $sectionalt = isset($section->pageorder) ? $section->pageorder : $section->section;
                 if ($move === 'to') {
                     // Include the required course/format library.
                     global $CFG;
                     require_once "{$CFG->dirroot}/course/format/" . $subpage->get_course()->format . "/lib.php";
                     $callbackfunction = 'callback_' . $subpage->get_course()->format . '_get_section_name';
                     if (function_exists($callbackfunction)) {
                         $name = $callbackfunction($subpage->get_course(), $section);
                     } else {
                         $name = $section->name ? $section->name : get_string('section') . ' ' . $sectionalt;
                     }
                 } else {
                     $name = $section->name ? $section->name : get_string('section') . ' ' . $sectionalt;
                 }
                 $sectionmods = explode(',', $section->sequence);
                 foreach ($sectionmods as $modnumber) {
                     if (empty($allmods[$modnumber]) || $modnumber === $subpage->get_course_module()->id) {
                         continue;
                     }
                     $instancename = format_string($modinfo->cms[$modnumber]->name, true, $subpage->get_course()->id);
                     $icon = $modinfo->get_cm($modnumber)->get_icon_url();
                     $mod = $allmods[$modnumber];
                     $mods[$section->section]['section'] = $name;
                     $mods[$section->section]['pageorder'] = $sectionalt;
                     $mods[$section->section]['mods'][$modnumber] = "<span><img src='{$icon}' /> " . $instancename . "</span>";
                 }
             }
         }
     }
     return $mods;
 }
开发者ID:nadavkav,项目名称:moodle-mod_subpage,代码行数:63,代码来源:locallib.php

示例9: test_start_attempt

 /**
  * Test start_attempt
  */
 public function test_start_attempt()
 {
     global $DB;
     // Create a new quiz with attempts.
     $quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
     $data = array('course' => $this->course->id, 'sumgrades' => 1);
     $quiz = $quizgenerator->create_instance($data);
     $context = context_module::instance($quiz->cmid);
     try {
         mod_quiz_external::start_attempt($quiz->id);
         $this->fail('Exception expected due to missing questions.');
     } catch (moodle_quiz_exception $e) {
         $this->assertEquals('noquestionsfound', $e->errorcode);
     }
     // Create a question.
     $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
     $cat = $questiongenerator->create_question_category();
     $question = $questiongenerator->create_question('numerical', null, array('category' => $cat->id));
     quiz_add_quiz_question($question->id, $quiz);
     $quizobj = quiz::create($quiz->id, $this->student->id);
     // Set grade to pass.
     $item = grade_item::fetch(array('courseid' => $this->course->id, 'itemtype' => 'mod', 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id, 'outcomeid' => null));
     $item->gradepass = 80;
     $item->update();
     $this->setUser($this->student);
     // Try to open attempt in closed quiz.
     $quiz->timeopen = time() - WEEKSECS;
     $quiz->timeclose = time() - DAYSECS;
     $DB->update_record('quiz', $quiz);
     $result = mod_quiz_external::start_attempt($quiz->id);
     $result = external_api::clean_returnvalue(mod_quiz_external::start_attempt_returns(), $result);
     $this->assertEquals([], $result['attempt']);
     $this->assertCount(1, $result['warnings']);
     // Now with a password.
     $quiz->timeopen = 0;
     $quiz->timeclose = 0;
     $quiz->password = 'abc';
     $DB->update_record('quiz', $quiz);
     try {
         mod_quiz_external::start_attempt($quiz->id, array(array("name" => "quizpassword", "value" => 'bad')));
         $this->fail('Exception expected due to invalid passwod.');
     } catch (moodle_exception $e) {
         $this->assertEquals(get_string('passworderror', 'quizaccess_password'), $e->errorcode);
     }
     // Now, try everything correct.
     $result = mod_quiz_external::start_attempt($quiz->id, array(array("name" => "quizpassword", "value" => 'abc')));
     $result = external_api::clean_returnvalue(mod_quiz_external::start_attempt_returns(), $result);
     $this->assertEquals(1, $result['attempt']['attempt']);
     $this->assertEquals($this->student->id, $result['attempt']['userid']);
     $this->assertEquals($quiz->id, $result['attempt']['quiz']);
     $this->assertCount(0, $result['warnings']);
     $attemptid = $result['attempt']['id'];
     // We are good, try to start a new attempt now.
     try {
         mod_quiz_external::start_attempt($quiz->id, array(array("name" => "quizpassword", "value" => 'abc')));
         $this->fail('Exception expected due to attempt not finished.');
     } catch (moodle_quiz_exception $e) {
         $this->assertEquals('attemptstillinprogress', $e->errorcode);
     }
     // Finish the started attempt.
     // Process some responses from the student.
     $timenow = time();
     $attemptobj = quiz_attempt::create($attemptid);
     $tosubmit = array(1 => array('answer' => '3.14'));
     $attemptobj->process_submitted_actions($timenow, false, $tosubmit);
     // Finish the attempt.
     $attemptobj = quiz_attempt::create($attemptid);
     $this->assertTrue($attemptobj->has_response_to_at_least_one_graded_question());
     $attemptobj->process_finish($timenow, false);
     // We should be able to start a new attempt.
     $result = mod_quiz_external::start_attempt($quiz->id, array(array("name" => "quizpassword", "value" => 'abc')));
     $result = external_api::clean_returnvalue(mod_quiz_external::start_attempt_returns(), $result);
     $this->assertEquals(2, $result['attempt']['attempt']);
     $this->assertEquals($this->student->id, $result['attempt']['userid']);
     $this->assertEquals($quiz->id, $result['attempt']['quiz']);
     $this->assertCount(0, $result['warnings']);
     // Test user with no capabilities.
     // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles.
     assign_capability('mod/quiz:attempt', CAP_PROHIBIT, $this->studentrole->id, $context->id);
     // Empty all the caches that may be affected  by this change.
     accesslib_clear_all_caches_for_unit_testing();
     course_modinfo::clear_instance_cache();
     try {
         mod_quiz_external::start_attempt($quiz->id);
         $this->fail('Exception expected due to missing capability.');
     } catch (required_capability_exception $e) {
         $this->assertEquals('nopermissions', $e->errorcode);
     }
 }
开发者ID:rushi963,项目名称:moodle,代码行数:92,代码来源:external_test.php

示例10: test_view_submission_status

 /**
  * Test test_view_submission_status
  */
 public function test_view_submission_status()
 {
     global $DB;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
     $context = context_module::instance($assign->cmid);
     $cm = get_coursemodule_from_instance('assign', $assign->id);
     // Test invalid instance id.
     try {
         mod_assign_external::view_submission_status(0);
         $this->fail('Exception expected due to invalid mod_assign instance id.');
     } catch (moodle_exception $e) {
         $this->assertEquals('invalidrecord', $e->errorcode);
     }
     // Test not-enrolled user.
     $user = self::getDataGenerator()->create_user();
     $this->setUser($user);
     try {
         mod_assign_external::view_submission_status($assign->id);
         $this->fail('Exception expected due to not enrolled user.');
     } catch (moodle_exception $e) {
         $this->assertEquals('requireloginerror', $e->errorcode);
     }
     // Test user with full capabilities.
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $result = mod_assign_external::view_submission_status($assign->id);
     $result = external_api::clean_returnvalue(mod_assign_external::view_submission_status_returns(), $result);
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = array_shift($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_assign\\event\\submission_status_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $moodleurl = new \moodle_url('/mod/assign/view.php', array('id' => $cm->id));
     $this->assertEquals($moodleurl, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
     // Test user with no capabilities.
     // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles.
     assign_capability('mod/assign:view', CAP_PROHIBIT, $studentrole->id, $context->id);
     accesslib_clear_all_caches_for_unit_testing();
     course_modinfo::clear_instance_cache();
     try {
         mod_assign_external::view_submission_status($assign->id);
         $this->fail('Exception expected due to missing capability.');
     } catch (moodle_exception $e) {
         $this->assertEquals('requireloginerror', $e->errorcode);
     }
 }
开发者ID:jackdaniels79,项目名称:moodle,代码行数:58,代码来源:externallib_test.php

示例11: get_areas_user_accesses

 /**
  * Returns the contexts the user can access.
  *
  * The returned value is a multidimensional array because some search engines can group
  * information and there will be a performance benefit on passing only some contexts
  * instead of the whole context array set.
  *
  * @return bool|array Indexed by area identifier (component + area name). Returns true if the user can see everything.
  */
 protected function get_areas_user_accesses()
 {
     global $CFG, $USER;
     // All results for admins. Eventually we could add a new capability for managers.
     if (is_siteadmin()) {
         return true;
     }
     $areasbylevel = array();
     // Split areas by context level so we only iterate only once through courses and cms.
     $searchareas = static::get_search_areas_list(true);
     foreach ($searchareas as $areaid => $unused) {
         $classname = static::get_area_classname($areaid);
         $searcharea = new $classname();
         foreach ($classname::get_levels() as $level) {
             $areasbylevel[$level][$areaid] = $searcharea;
         }
     }
     // This will store area - allowed contexts relations.
     $areascontexts = array();
     if (!empty($areasbylevel[CONTEXT_SYSTEM])) {
         // We add system context to all search areas working at this level. Here each area is fully responsible of
         // the access control as we can not automate much, we can not even check guest access as some areas might
         // want to allow guests to retrieve data from them.
         $systemcontextid = \context_system::instance()->id;
         foreach ($areasbylevel[CONTEXT_SYSTEM] as $areaid => $searchclass) {
             $areascontexts[$areaid][] = $systemcontextid;
         }
     }
     // Get the courses where the current user has access.
     $courses = enrol_get_my_courses(array('id', 'cacherev'));
     $courses[SITEID] = get_course(SITEID);
     $site = \course_modinfo::instance(SITEID);
     foreach ($courses as $course) {
         // Info about the course modules.
         $modinfo = get_fast_modinfo($course);
         if (!empty($areasbylevel[CONTEXT_COURSE])) {
             // Add the course contexts the user can view.
             $coursecontext = \context_course::instance($course->id);
             foreach ($areasbylevel[CONTEXT_COURSE] as $areaid => $searchclass) {
                 if ($course->visible || has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
                     $areascontexts[$areaid][$coursecontext->id] = $coursecontext->id;
                 }
             }
         }
         if (!empty($areasbylevel[CONTEXT_MODULE])) {
             // Add the module contexts the user can view (cm_info->uservisible).
             foreach ($areasbylevel[CONTEXT_MODULE] as $areaid => $searchclass) {
                 // Removing the plugintype 'mod_' prefix.
                 $modulename = substr($searchclass->get_component_name(), 4);
                 $modinstances = $modinfo->get_instances_of($modulename);
                 foreach ($modinstances as $modinstance) {
                     if ($modinstance->uservisible) {
                         $areascontexts[$areaid][$modinstance->context->id] = $modinstance->context->id;
                     }
                 }
             }
         }
     }
     return $areascontexts;
 }
开发者ID:rushi963,项目名称:moodle,代码行数:69,代码来源:manager.php

示例12: block_intuitel_get_course_lang

/**
 * Retrieves the forced language of the course of null if not forced language.
 * @param course_modinfo $course_info : course_modinfo object of the course
 * @return string|NULL $lang: forced language of the course or null if not language is forced
 */
function block_intuitel_get_course_lang($course_info)
{
    $course = $course_info->get_course();
    if ($course->lang != null) {
        $lang = block_intuitel_get_parent_lang($course->lang);
    } else {
        $lang = null;
    }
    return $lang;
}
开发者ID:juacas,项目名称:moodle-block_intuitel,代码行数:15,代码来源:locallib.php

示例13: getChildren

 /**
  * Returns the LOId of the sections (not empty, with a summary or with cms) of a course
  * @param course_modinfo $rawData : course_modinfo object
  * @return \intuitel\LOId : array with LOID of children
  */
 private function getChildren($rawData)
 {
     $sections = $rawData->get_section_info_all();
     $hasChildren = array();
     foreach ($sections as $section) {
         $sectionFactory = new SectionLOFactory();
         $sectionLO = $sectionFactory->createLOFromNative($section);
         if ($sectionLO != null) {
             //empty section: no name or summary
             $sectionLOid = $sectionLO->getloId();
             $hasChildren[] = $sectionLOid;
         }
     }
     return $hasChildren;
 }
开发者ID:juacas,项目名称:moodle-block_intuitel,代码行数:20,代码来源:CourseLOFactory.php

示例14: test_view_lti

 /**
  * Test view_lti
  */
 public function test_view_lti()
 {
     global $DB;
     // Test invalid instance id.
     try {
         mod_lti_external::view_lti(0);
         $this->fail('Exception expected due to invalid mod_lti instance id.');
     } catch (moodle_exception $e) {
         $this->assertEquals('invalidrecord', $e->errorcode);
     }
     // Test not-enrolled user.
     $usernotenrolled = self::getDataGenerator()->create_user();
     $this->setUser($usernotenrolled);
     try {
         mod_lti_external::view_lti($this->lti->id);
         $this->fail('Exception expected due to not enrolled user.');
     } catch (moodle_exception $e) {
         $this->assertEquals('requireloginerror', $e->errorcode);
     }
     // Test user with full capabilities.
     $this->setUser($this->student);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $result = mod_lti_external::view_lti($this->lti->id);
     $result = external_api::clean_returnvalue(mod_lti_external::view_lti_returns(), $result);
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = array_shift($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_lti\\event\\course_module_viewed', $event);
     $this->assertEquals($this->context, $event->get_context());
     $moodlelti = new \moodle_url('/mod/lti/view.php', array('id' => $this->cm->id));
     $this->assertEquals($moodlelti, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
     // Test user with no capabilities.
     // We need a explicit prohibit since this capability is only defined in authenticated user and guest roles.
     assign_capability('mod/lti:view', CAP_PROHIBIT, $this->studentrole->id, $this->context->id);
     // Empty all the caches that may be affected by this change.
     accesslib_clear_all_caches_for_unit_testing();
     course_modinfo::clear_instance_cache();
     try {
         mod_lti_external::view_lti($this->lti->id);
         $this->fail('Exception expected due to missing capability.');
     } catch (moodle_exception $e) {
         $this->assertEquals('requireloginerror', $e->errorcode);
     }
 }
开发者ID:kevin-bruton,项目名称:moodle,代码行数:51,代码来源:externallib_test.php

示例15: get_grade_analysis_url

 /**
  * Returns URL of a page that is supposed to contain detailed grade analysis
  *
  * At the moment, only activity modules are supported. The method generates link
  * to the module's file grade.php with the parameters id (cmid), itemid, itemnumber,
  * gradeid and userid. If the grade.php does not exist, null is returned.
  *
  * @return moodle_url|null URL or null if unable to construct it
  */
 public function get_grade_analysis_url(grade_grade $grade)
 {
     global $CFG;
     /** @var array static cache of the grade.php file existence flags */
     static $hasgradephp = array();
     if (empty($grade->grade_item) or !$grade->grade_item instanceof grade_item) {
         throw new coding_exception('Passed grade without the associated grade item');
     }
     $item = $grade->grade_item;
     if (!$item->is_external_item()) {
         // at the moment, only activity modules are supported
         return null;
     }
     if ($item->itemtype !== 'mod') {
         throw new coding_exception('Unknown external itemtype: ' . $item->itemtype);
     }
     if (empty($item->iteminstance) or empty($item->itemmodule) or empty($this->modinfo)) {
         return null;
     }
     if (!array_key_exists($item->itemmodule, $hasgradephp)) {
         if (file_exists($CFG->dirroot . '/mod/' . $item->itemmodule . '/grade.php')) {
             $hasgradephp[$item->itemmodule] = true;
         } else {
             $hasgradephp[$item->itemmodule] = false;
         }
     }
     if (!$hasgradephp[$item->itemmodule]) {
         return null;
     }
     $instances = $this->modinfo->get_instances();
     if (empty($instances[$item->itemmodule][$item->iteminstance])) {
         return null;
     }
     $cm = $instances[$item->itemmodule][$item->iteminstance];
     if (!$cm->uservisible) {
         return null;
     }
     $url = new moodle_url('/mod/' . $item->itemmodule . '/grade.php', array('id' => $cm->id, 'itemid' => $item->id, 'itemnumber' => $item->itemnumber, 'gradeid' => $grade->id, 'userid' => $grade->userid));
     return $url;
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:49,代码来源:lib.php


注:本文中的course_modinfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。