本文整理汇总了PHP中cm_info::create方法的典型用法代码示例。如果您正苦于以下问题:PHP cm_info::create方法的具体用法?PHP cm_info::create怎么用?PHP cm_info::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cm_info
的用法示例。
在下文中一共展示了cm_info::create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor for the base assign class.
*
* Note: For $coursemodule you can supply a stdclass if you like, but it
* will be more efficient to supply a cm_info object.
*
* @param mixed $coursemodulecontext context|null the course module context
* (or the course context if the coursemodule has not been
* created yet).
* @param mixed $coursemodule the current course module if it was already loaded,
* otherwise this class will load one from the context as required.
* @param mixed $course the current course if it was already loaded,
* otherwise this class will load one from the context as required.
*/
public function __construct($coursemodulecontext, $coursemodule, $course)
{
$this->context = $coursemodulecontext;
$this->course = $course;
// Ensure that $this->coursemodule is a cm_info object (or null).
$this->coursemodule = cm_info::create($coursemodule);
// Temporary cache only lives for a single request - used to reduce db lookups.
$this->cache = array();
$this->submissionplugins = $this->load_plugins('assignsubmission');
$this->feedbackplugins = $this->load_plugins('assignfeedback');
}
示例2: __construct
/**
* Constructor for the base assign class.
*
* Note: For $coursemodule you can supply a stdclass if you like, but it
* will be more efficient to supply a cm_info object.
*
* @param mixed $coursemodulecontext context|null the course module context
* (or the course context if the coursemodule has not been
* created yet).
* @param mixed $coursemodule the current course module if it was already loaded,
* otherwise this class will load one from the context as required.
* @param mixed $course the current course if it was already loaded,
* otherwise this class will load one from the context as required.
*/
public function __construct($coursemodulecontext, $coursemodule, $course)
{
global $SESSION;
$this->context = $coursemodulecontext;
$this->course = $course;
// Ensure that $this->coursemodule is a cm_info object (or null).
$this->coursemodule = cm_info::create($coursemodule);
// Temporary cache only lives for a single request - used to reduce db lookups.
$this->cache = array();
$this->submissionplugins = $this->load_plugins('assignsubmission');
$this->feedbackplugins = $this->load_plugins('assignfeedback');
// Extra entropy is required for uniqid() to work on cygwin.
$this->useridlistid = clean_param(uniqid('', true), PARAM_ALPHANUM);
if (!isset($SESSION->mod_assign_useridlist)) {
$SESSION->mod_assign_useridlist = [];
}
}
示例3: test_create
/**
* Tests the function for constructing a cm_info from mixed data.
*/
public function test_create()
{
global $CFG, $DB;
$this->resetAfterTest();
// Create a course and an activity.
$generator = $this->getDataGenerator();
$course = $generator->create_course();
$page = $generator->create_module('page', array('course' => $course->id, 'name' => 'Annie'));
// Null is passed through.
$this->assertNull(cm_info::create(null));
// Stdclass object turns into cm_info.
$cm = cm_info::create((object) array('id' => $page->cmid, 'course' => $course->id));
$this->assertInstanceOf('cm_info', $cm);
$this->assertEquals('Annie', $cm->name);
// A cm_info object stays as cm_info.
$this->assertSame($cm, cm_info::create($cm));
// Invalid object (missing fields) causes error.
try {
cm_info::create((object) array('id' => $page->cmid));
$this->fail();
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
// Create a second hidden activity.
$hiddenpage = $generator->create_module('page', array('course' => $course->id, 'name' => 'Annie', 'visible' => 0));
// Create 2 user accounts, one is a manager who can see everything.
$user = $generator->create_user();
$generator->enrol_user($user->id, $course->id);
$manager = $generator->create_user();
$generator->enrol_user($manager->id, $course->id, $DB->get_field('role', 'id', array('shortname' => 'manager'), MUST_EXIST));
// User can see the normal page but not the hidden one.
$cm = cm_info::create((object) array('id' => $page->cmid, 'course' => $course->id), $user->id);
$this->assertTrue($cm->uservisible);
$cm = cm_info::create((object) array('id' => $hiddenpage->cmid, 'course' => $course->id), $user->id);
$this->assertFalse($cm->uservisible);
// Manager can see the hidden one too.
$cm = cm_info::create((object) array('id' => $hiddenpage->cmid, 'course' => $course->id), $manager->id);
$this->assertTrue($cm->uservisible);
}
示例4: prepare_choice_show_results
/**
* @global object
* @param object $choice
* @param object $course
* @param object $coursemodule
* @param array $allresponses
* * @param bool $allresponses
* @return object
*/
function prepare_choice_show_results($choice, $course, $cm, $allresponses)
{
global $OUTPUT;
$display = clone $choice;
$display->coursemoduleid = $cm->id;
$display->courseid = $course->id;
if (!empty($choice->showunanswered)) {
$choice->option[0] = get_string('notanswered', 'choice');
$choice->maxanswers[0] = 0;
}
// Remove from the list of non-respondents the users who do not have access to this activity.
if (!empty($display->showunanswered) && $allresponses[0]) {
$info = new \core_availability\info_module(cm_info::create($cm));
$allresponses[0] = $info->filter_user_list($allresponses[0]);
}
//overwrite options value;
$display->options = array();
$allusers = [];
foreach ($choice->option as $optionid => $optiontext) {
$display->options[$optionid] = new stdClass();
$display->options[$optionid]->text = $optiontext;
$display->options[$optionid]->maxanswer = $choice->maxanswers[$optionid];
if (array_key_exists($optionid, $allresponses)) {
$display->options[$optionid]->user = $allresponses[$optionid];
$allusers = array_merge($allusers, array_keys($allresponses[$optionid]));
}
}
unset($display->option);
unset($display->maxanswers);
$display->numberofuser = count(array_unique($allusers));
$context = context_module::instance($cm->id);
$display->viewresponsecapability = has_capability('mod/choice:readresponses', $context);
$display->deleterepsonsecapability = has_capability('mod/choice:deleteresponses', $context);
$display->fullnamecapability = has_capability('moodle/site:viewfullnames', $context);
if (empty($allresponses)) {
echo $OUTPUT->heading(get_string("nousersyet"), 3, null);
return false;
}
return $display;
}