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


PHP moodle_exception函数代码示例

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


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

示例1: test_create_courses


//.........这里部分代码省略.........
        $this->assignUserCapability('moodle/course:visibility', $contextid, $roleid);

        $category  = self::getDataGenerator()->create_category();

        // Create base categories.
        $course1['fullname'] = 'Test course 1';
        $course1['shortname'] = 'Testcourse1';
        $course1['categoryid'] = $category->id;
        $course2['fullname'] = 'Test course 2';
        $course2['shortname'] = 'Testcourse2';
        $course2['categoryid'] = $category->id;
        $course2['idnumber'] = 'testcourse2idnumber';
        $course2['summary'] = 'Description for course 2';
        $course2['summaryformat'] = FORMAT_MOODLE;
        $course2['format'] = 'weeks';
        $course2['showgrades'] = 1;
        $course2['newsitems'] = 3;
        $course2['startdate'] = 1420092000; // 01/01/2015
        $course2['numsections'] = 4;
        $course2['maxbytes'] = 100000;
        $course2['showreports'] = 1;
        $course2['visible'] = 0;
        $course2['hiddensections'] = 0;
        $course2['groupmode'] = 0;
        $course2['groupmodeforce'] = 0;
        $course2['defaultgroupingid'] = 0;
        $course2['enablecompletion'] = 1;
        $course2['completionstartonenrol'] = 1;
        $course2['completionnotify'] = 1;
        $course2['lang'] = 'en';
        $course2['forcetheme'] = 'base';
        $courses = array($course1, $course2);

        $createdcourses = core_course_external::create_courses($courses);

        // We need to execute the return values cleaning process to simulate the web service server.
        $createdcourses = external_api::clean_returnvalue(core_course_external::create_courses_returns(), $createdcourses);

        // Check that right number of courses were created.
        $this->assertEquals(2, count($createdcourses));

        // Check that the courses were correctly created.
        foreach ($createdcourses as $createdcourse) {
            $dbcourse = $DB->get_record('course', array('id' => $createdcourse['id']));

            if ($createdcourse['shortname'] == $course2['shortname']) {
                $this->assertEquals($dbcourse->fullname, $course2['fullname']);
                $this->assertEquals($dbcourse->shortname, $course2['shortname']);
                $this->assertEquals($dbcourse->category, $course2['categoryid']);
                $this->assertEquals($dbcourse->idnumber, $course2['idnumber']);
                $this->assertEquals($dbcourse->summary, $course2['summary']);
                $this->assertEquals($dbcourse->summaryformat, $course2['summaryformat']);
                $this->assertEquals($dbcourse->format, $course2['format']);
                $this->assertEquals($dbcourse->showgrades, $course2['showgrades']);
                $this->assertEquals($dbcourse->newsitems, $course2['newsitems']);
                $this->assertEquals($dbcourse->startdate, $course2['startdate']);
                $this->assertEquals($dbcourse->numsections, $course2['numsections']);
                $this->assertEquals($dbcourse->maxbytes, $course2['maxbytes']);
                $this->assertEquals($dbcourse->showreports, $course2['showreports']);
                $this->assertEquals($dbcourse->visible, $course2['visible']);
                $this->assertEquals($dbcourse->hiddensections, $course2['hiddensections']);
                $this->assertEquals($dbcourse->groupmode, $course2['groupmode']);
                $this->assertEquals($dbcourse->groupmodeforce, $course2['groupmodeforce']);
                $this->assertEquals($dbcourse->defaultgroupingid, $course2['defaultgroupingid']);
                $this->assertEquals($dbcourse->completionnotify, $course2['completionnotify']);
                $this->assertEquals($dbcourse->lang, $course2['lang']);

                if (!empty($CFG->allowcoursethemes)) {
                    $this->assertEquals($dbcourse->theme, $course2['forcetheme']);
                }

                $this->assertEquals($dbcourse->enablecompletion, $course2['enablecompletion']);
                $this->assertEquals($dbcourse->completionstartonenrol, $course2['completionstartonenrol']);

            } else if ($createdcourse['shortname'] == $course1['shortname']) {
                $courseconfig = get_config('moodlecourse');
                $this->assertEquals($dbcourse->fullname, $course1['fullname']);
                $this->assertEquals($dbcourse->shortname, $course1['shortname']);
                $this->assertEquals($dbcourse->category, $course1['categoryid']);
                $this->assertEquals($dbcourse->summaryformat, FORMAT_HTML);
                $this->assertEquals($dbcourse->format, $courseconfig->format);
                $this->assertEquals($dbcourse->showgrades, $courseconfig->showgrades);
                $this->assertEquals($dbcourse->newsitems, $courseconfig->newsitems);
                $this->assertEquals($dbcourse->numsections, $courseconfig->numsections);
                $this->assertEquals($dbcourse->maxbytes, $courseconfig->maxbytes);
                $this->assertEquals($dbcourse->showreports, $courseconfig->showreports);
                $this->assertEquals($dbcourse->hiddensections, $courseconfig->hiddensections);
                $this->assertEquals($dbcourse->groupmode, $courseconfig->groupmode);
                $this->assertEquals($dbcourse->groupmodeforce, $courseconfig->groupmodeforce);
                $this->assertEquals($dbcourse->defaultgroupingid, 0);
            } else {
                throw moodle_exception('Unexpected shortname');
            }
        }

        // Call without required capability
        $this->unassignUserCapability('moodle/course:create', $contextid, $roleid);
        $this->setExpectedException('required_capability_exception');
        $createdsubcats = core_course_external::create_courses($courses);
    }
开发者ID:ncsu-delta,项目名称:moodle,代码行数:101,代码来源:externallib_test.php

示例2: login_user

 /**
  * Log the current user into a chat room in the given chat.
  *
  * @param int $chatid the chat instance id
  * @param int $groupid the user group id
  * @return array of warnings and the chat unique session id
  * @since Moodle 3.0
  * @throws moodle_exception
  */
 public static function login_user($chatid, $groupid = 0)
 {
     global $DB;
     $params = self::validate_parameters(self::login_user_parameters(), array('chatid' => $chatid, 'groupid' => $groupid));
     $warnings = array();
     // Request and permission validation.
     $chat = $DB->get_record('chat', array('id' => $params['chatid']), '*', MUST_EXIST);
     list($course, $cm) = get_course_and_cm_from_instance($chat, 'chat');
     $context = context_module::instance($cm->id);
     self::validate_context($context);
     require_capability('mod/chat:chat', $context);
     if (!empty($params['groupid'])) {
         $groupid = $params['groupid'];
         // Determine is the group is visible to user.
         if (!groups_group_visible($groupid, $course, $cm)) {
             throw new moodle_exception('notingroup');
         }
     } else {
         // Check to see if groups are being used here.
         if ($groupmode = groups_get_activity_groupmode($cm)) {
             $groupid = groups_get_activity_group($cm);
             // Determine is the group is visible to user (this is particullary for the group 0).
             if (!groups_group_visible($groupid, $course, $cm)) {
                 throw new moodle_exception('notingroup');
             }
         } else {
             $groupid = 0;
         }
     }
     // Get the unique chat session id.
     // Since we are going to use the chat via Web Service requests we set the ajax version (since it's the most similar).
     if (!($chatsid = chat_login_user($chat->id, 'ajax', $groupid, $course))) {
         throw moodle_exception('cantlogin', 'chat');
     }
     $result = array();
     $result['chatsid'] = $chatsid;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:48,代码来源:external.php

示例3: test_update_courses

 /**
  * Test update_courses
  */
 public function test_update_courses()
 {
     global $DB, $CFG, $USER;
     $this->resetAfterTest(true);
     // Set the required capabilities by the external function.
     $contextid = context_system::instance()->id;
     $roleid = $this->assignUserCapability('moodle/course:update', $contextid);
     $this->assignUserCapability('moodle/course:changecategory', $contextid, $roleid);
     $this->assignUserCapability('moodle/course:changefullname', $contextid, $roleid);
     $this->assignUserCapability('moodle/course:changeshortname', $contextid, $roleid);
     $this->assignUserCapability('moodle/course:changeidnumber', $contextid, $roleid);
     $this->assignUserCapability('moodle/course:changesummary', $contextid, $roleid);
     $this->assignUserCapability('moodle/course:visibility', $contextid, $roleid);
     $this->assignUserCapability('moodle/course:viewhiddencourses', $contextid, $roleid);
     // Create category and course.
     $category1 = self::getDataGenerator()->create_category();
     $category2 = self::getDataGenerator()->create_category();
     $originalcourse1 = self::getDataGenerator()->create_course();
     self::getDataGenerator()->enrol_user($USER->id, $originalcourse1->id, $roleid);
     $originalcourse2 = self::getDataGenerator()->create_course();
     self::getDataGenerator()->enrol_user($USER->id, $originalcourse2->id, $roleid);
     // Course values to be updated.
     $course1['id'] = $originalcourse1->id;
     $course1['fullname'] = 'Updated test course 1';
     $course1['shortname'] = 'Udestedtestcourse1';
     $course1['categoryid'] = $category1->id;
     $course2['id'] = $originalcourse2->id;
     $course2['fullname'] = 'Updated test course 2';
     $course2['shortname'] = 'Updestedtestcourse2';
     $course2['categoryid'] = $category2->id;
     $course2['idnumber'] = 'Updatedidnumber2';
     $course2['summary'] = 'Updaated description for course 2';
     $course2['summaryformat'] = FORMAT_HTML;
     $course2['format'] = 'topics';
     $course2['showgrades'] = 1;
     $course2['newsitems'] = 3;
     $course2['startdate'] = 1420092000;
     // 01/01/2015.
     $course2['numsections'] = 4;
     $course2['maxbytes'] = 100000;
     $course2['showreports'] = 1;
     $course2['visible'] = 0;
     $course2['hiddensections'] = 0;
     $course2['groupmode'] = 0;
     $course2['groupmodeforce'] = 0;
     $course2['defaultgroupingid'] = 0;
     $course2['enablecompletion'] = 1;
     $course2['lang'] = 'en';
     $course2['forcetheme'] = 'base';
     $courses = array($course1, $course2);
     $updatedcoursewarnings = core_course_external::update_courses($courses);
     // Check that right number of courses were created.
     $this->assertEquals(0, count($updatedcoursewarnings['warnings']));
     // Check that the courses were correctly created.
     foreach ($courses as $course) {
         $courseinfo = course_get_format($course['id'])->get_course();
         if ($course['id'] == $course2['id']) {
             $this->assertEquals($course2['fullname'], $courseinfo->fullname);
             $this->assertEquals($course2['shortname'], $courseinfo->shortname);
             $this->assertEquals($course2['categoryid'], $courseinfo->category);
             $this->assertEquals($course2['idnumber'], $courseinfo->idnumber);
             $this->assertEquals($course2['summary'], $courseinfo->summary);
             $this->assertEquals($course2['summaryformat'], $courseinfo->summaryformat);
             $this->assertEquals($course2['format'], $courseinfo->format);
             $this->assertEquals($course2['showgrades'], $courseinfo->showgrades);
             $this->assertEquals($course2['newsitems'], $courseinfo->newsitems);
             $this->assertEquals($course2['startdate'], $courseinfo->startdate);
             $this->assertEquals($course2['numsections'], $courseinfo->numsections);
             $this->assertEquals($course2['maxbytes'], $courseinfo->maxbytes);
             $this->assertEquals($course2['showreports'], $courseinfo->showreports);
             $this->assertEquals($course2['visible'], $courseinfo->visible);
             $this->assertEquals($course2['hiddensections'], $courseinfo->hiddensections);
             $this->assertEquals($course2['groupmode'], $courseinfo->groupmode);
             $this->assertEquals($course2['groupmodeforce'], $courseinfo->groupmodeforce);
             $this->assertEquals($course2['defaultgroupingid'], $courseinfo->defaultgroupingid);
             $this->assertEquals($course2['lang'], $courseinfo->lang);
             if (!empty($CFG->allowcoursethemes)) {
                 $this->assertEquals($course2['forcetheme'], $courseinfo->theme);
             }
             if (completion_info::is_enabled_for_site()) {
                 $this->assertEquals($course2['enabledcompletion'], $courseinfo->enablecompletion);
             }
         } else {
             if ($course['id'] == $course1['id']) {
                 $this->assertEquals($course1['fullname'], $courseinfo->fullname);
                 $this->assertEquals($course1['shortname'], $courseinfo->shortname);
                 $this->assertEquals($course1['categoryid'], $courseinfo->category);
                 $this->assertEquals(FORMAT_MOODLE, $courseinfo->summaryformat);
                 $this->assertEquals('topics', $courseinfo->format);
                 $this->assertEquals(5, $courseinfo->numsections);
                 $this->assertEquals(0, $courseinfo->newsitems);
                 $this->assertEquals(FORMAT_MOODLE, $courseinfo->summaryformat);
             } else {
                 throw moodle_exception('Unexpected shortname');
             }
         }
     }
//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:externallib_test.php

示例4: test_update_courses


//.........这里部分代码省略.........
             $this->assertEquals($course2['shortname'], $courseinfo->shortname);
             $this->assertEquals($course2['categoryid'], $courseinfo->category);
             $this->assertEquals($course2['idnumber'], $courseinfo->idnumber);
             $this->assertEquals($course2['summary'], $courseinfo->summary);
             $this->assertEquals($course2['summaryformat'], $courseinfo->summaryformat);
             $this->assertEquals($course2['format'], $courseinfo->format);
             $this->assertEquals($course2['showgrades'], $courseinfo->showgrades);
             $this->assertEquals($course2['newsitems'], $courseinfo->newsitems);
             $this->assertEquals($course2['startdate'], $courseinfo->startdate);
             $this->assertEquals($course2['numsections'], $courseinfo->numsections);
             $this->assertEquals($course2['maxbytes'], $courseinfo->maxbytes);
             $this->assertEquals($course2['showreports'], $courseinfo->showreports);
             $this->assertEquals($course2['visible'], $courseinfo->visible);
             $this->assertEquals($course2['hiddensections'], $courseinfo->hiddensections);
             $this->assertEquals($course2['groupmode'], $courseinfo->groupmode);
             $this->assertEquals($course2['groupmodeforce'], $courseinfo->groupmodeforce);
             $this->assertEquals($course2['defaultgroupingid'], $courseinfo->defaultgroupingid);
             $this->assertEquals($course2['lang'], $courseinfo->lang);
             if (!empty($CFG->allowcoursethemes)) {
                 $this->assertEquals($course2['forcetheme'], $courseinfo->theme);
             }
             $this->assertEquals($course2['enablecompletion'], $courseinfo->enablecompletion);
         } else {
             if ($course['id'] == $course1['id']) {
                 $this->assertEquals($course1['fullname'], $courseinfo->fullname);
                 $this->assertEquals($course1['shortname'], $courseinfo->shortname);
                 $this->assertEquals($course1['categoryid'], $courseinfo->category);
                 $this->assertEquals(FORMAT_MOODLE, $courseinfo->summaryformat);
                 $this->assertEquals('topics', $courseinfo->format);
                 $this->assertEquals(5, $courseinfo->numsections);
                 $this->assertEquals(0, $courseinfo->newsitems);
                 $this->assertEquals(FORMAT_MOODLE, $courseinfo->summaryformat);
             } else {
                 throw moodle_exception('Unexpected shortname');
             }
         }
     }
     $courses = array($course1);
     // Try update course without update capability.
     $user = self::getDataGenerator()->create_user();
     $this->setUser($user);
     $this->unassignUserCapability('moodle/course:update', $contextid, $roleid);
     self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid);
     $updatedcoursewarnings = core_course_external::update_courses($courses);
     $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), $updatedcoursewarnings);
     $this->assertEquals(1, count($updatedcoursewarnings['warnings']));
     // Try update course category without capability.
     $this->assignUserCapability('moodle/course:update', $contextid, $roleid);
     $this->unassignUserCapability('moodle/course:changecategory', $contextid, $roleid);
     $user = self::getDataGenerator()->create_user();
     $this->setUser($user);
     self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid);
     $course1['categoryid'] = $category2->id;
     $courses = array($course1);
     $updatedcoursewarnings = core_course_external::update_courses($courses);
     $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), $updatedcoursewarnings);
     $this->assertEquals(1, count($updatedcoursewarnings['warnings']));
     // Try update course fullname without capability.
     $this->assignUserCapability('moodle/course:changecategory', $contextid, $roleid);
     $this->unassignUserCapability('moodle/course:changefullname', $contextid, $roleid);
     $user = self::getDataGenerator()->create_user();
     $this->setUser($user);
     self::getDataGenerator()->enrol_user($user->id, $course1['id'], $roleid);
     $updatedcoursewarnings = core_course_external::update_courses($courses);
     $updatedcoursewarnings = external_api::clean_returnvalue(core_course_external::update_courses_returns(), $updatedcoursewarnings);
     $this->assertEquals(0, count($updatedcoursewarnings['warnings']));
开发者ID:sirromas,项目名称:lms,代码行数:67,代码来源:externallib_test.php

示例5: test_create_courses


//.........这里部分代码省略.........
     $course2['format'] = 'weeks';
     $course2['showgrades'] = 1;
     $course2['newsitems'] = 3;
     $course2['startdate'] = 1420092000;
     // 01/01/2015
     $course2['numsections'] = 4;
     $course2['maxbytes'] = 100000;
     $course2['showreports'] = 1;
     $course2['visible'] = 0;
     $course2['hiddensections'] = 0;
     $course2['groupmode'] = 0;
     $course2['groupmodeforce'] = 0;
     $course2['defaultgroupingid'] = 0;
     $course2['enablecompletion'] = 1;
     $course2['completionstartonenrol'] = 1;
     $course2['completionnotify'] = 1;
     $course2['lang'] = 'en';
     $course2['forcetheme'] = 'base';
     $course3['fullname'] = 'Test course 3';
     $course3['shortname'] = 'Testcourse3';
     $course3['categoryid'] = $category->id;
     $course3['format'] = 'topics';
     $course3options = array('numsections' => 8, 'hiddensections' => 1, 'coursedisplay' => 1);
     $course3['courseformatoptions'] = array();
     foreach ($course3options as $key => $value) {
         $course3['courseformatoptions'][] = array('name' => $key, 'value' => $value);
     }
     $courses = array($course1, $course2);
     $createdcourses = core_course_external::create_courses($courses);
     // Check that right number of courses were created.
     $this->assertEquals(2, count($createdcourses));
     // Check that the courses were correctly created.
     foreach ($createdcourses as $createdcourse) {
         $courseinfo = course_get_format($createdcourse['id'])->get_course();
         if ($createdcourse['shortname'] == $course2['shortname']) {
             $this->assertEquals($courseinfo->fullname, $course2['fullname']);
             $this->assertEquals($courseinfo->shortname, $course2['shortname']);
             $this->assertEquals($courseinfo->category, $course2['categoryid']);
             $this->assertEquals($courseinfo->idnumber, $course2['idnumber']);
             $this->assertEquals($courseinfo->summary, $course2['summary']);
             $this->assertEquals($courseinfo->summaryformat, $course2['summaryformat']);
             $this->assertEquals($courseinfo->format, $course2['format']);
             $this->assertEquals($courseinfo->showgrades, $course2['showgrades']);
             $this->assertEquals($courseinfo->newsitems, $course2['newsitems']);
             $this->assertEquals($courseinfo->startdate, $course2['startdate']);
             $this->assertEquals($courseinfo->numsections, $course2['numsections']);
             $this->assertEquals($courseinfo->maxbytes, $course2['maxbytes']);
             $this->assertEquals($courseinfo->showreports, $course2['showreports']);
             $this->assertEquals($courseinfo->visible, $course2['visible']);
             $this->assertEquals($courseinfo->hiddensections, $course2['hiddensections']);
             $this->assertEquals($courseinfo->groupmode, $course2['groupmode']);
             $this->assertEquals($courseinfo->groupmodeforce, $course2['groupmodeforce']);
             $this->assertEquals($courseinfo->defaultgroupingid, $course2['defaultgroupingid']);
             $this->assertEquals($courseinfo->completionnotify, $course2['completionnotify']);
             $this->assertEquals($courseinfo->lang, $course2['lang']);
             if (!empty($CFG->allowcoursethemes)) {
                 $this->assertEquals($courseinfo->theme, $course2['forcetheme']);
             }
             if (completion_info::is_enabled_for_site()) {
                 $this->assertEquals($courseinfo->enablecompletion, $course2['enabledcompletion']);
                 $this->assertEquals($courseinfo->completionstartonenrol, $course2['completionstartonenrol']);
             } else {
                 $this->assertEquals($courseinfo->enablecompletion, 0);
                 $this->assertEquals($courseinfo->completionstartonenrol, 0);
             }
         } else {
             if ($createdcourse['shortname'] == $course1['shortname']) {
                 $courseconfig = get_config('moodlecourse');
                 $this->assertEquals($courseinfo->fullname, $course1['fullname']);
                 $this->assertEquals($courseinfo->shortname, $course1['shortname']);
                 $this->assertEquals($courseinfo->category, $course1['categoryid']);
                 $this->assertEquals($courseinfo->summaryformat, FORMAT_HTML);
                 $this->assertEquals($courseinfo->format, $courseconfig->format);
                 $this->assertEquals($courseinfo->showgrades, $courseconfig->showgrades);
                 $this->assertEquals($courseinfo->newsitems, $courseconfig->newsitems);
                 $this->assertEquals($courseinfo->maxbytes, $courseconfig->maxbytes);
                 $this->assertEquals($courseinfo->showreports, $courseconfig->showreports);
                 $this->assertEquals($courseinfo->groupmode, $courseconfig->groupmode);
                 $this->assertEquals($courseinfo->groupmodeforce, $courseconfig->groupmodeforce);
                 $this->assertEquals($courseinfo->defaultgroupingid, 0);
             } else {
                 if ($createdcourse['shortname'] == $course3['shortname']) {
                     $this->assertEquals($courseinfo->fullname, $course3['fullname']);
                     $this->assertEquals($courseinfo->shortname, $course3['shortname']);
                     $this->assertEquals($courseinfo->category, $course3['categoryid']);
                     $this->assertEquals($courseinfo->format, $course3['format']);
                     $this->assertEquals($courseinfo->hiddensections, $course3options['hiddensections']);
                     $this->assertEquals($courseinfo->numsections, $course3options['numsections']);
                     $this->assertEquals($courseinfo->coursedisplay, $course3options['coursedisplay']);
                 } else {
                     throw moodle_exception('Unexpected shortname');
                 }
             }
         }
     }
     // Call without required capability
     $this->unassignUserCapability('moodle/course:create', $contextid, $roleid);
     $this->setExpectedException('required_capability_exception');
     $createdsubcats = core_course_external::create_courses($courses);
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:101,代码来源:externallib_test.php


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