本文整理匯總了PHP中course_modinfo::get_instances方法的典型用法代碼示例。如果您正苦於以下問題:PHP course_modinfo::get_instances方法的具體用法?PHP course_modinfo::get_instances怎麽用?PHP course_modinfo::get_instances使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類course_modinfo
的用法示例。
在下文中一共展示了course_modinfo::get_instances方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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;
}
示例2: get_activity_link
private function get_activity_link($element)
{
global $CFG;
$itemtype = $element['object']->itemtype;
$itemmodule = $element['object']->itemmodule;
$iteminstance = $element['object']->iteminstance;
// Links only for module items that have valid instance, module and are
// called from grade_tree with valid modinfo
if ($itemtype != 'mod' || !$iteminstance || !$itemmodule || !$this->modinfo) {
return null;
}
// Get $cm efficiently and with visibility information using modinfo
$instances = $this->modinfo->get_instances();
if (empty($instances[$itemmodule][$iteminstance])) {
return null;
}
$cm = $instances[$itemmodule][$iteminstance];
// Do not add link if activity is not visible to the current user
if (!$cm->uservisible) {
return null;
}
// If module has grade.php, link to that, otherwise view.php
$dir = $CFG->dirroot . '/mod/' . $itemmodule;
if (file_exists($dir . '/grade.php')) {
return new moodle_url('/mod/' . $itemmodule . '/grade.php', array('id' => $cm->id));
} else {
return new moodle_url('/mod/' . $itemmodule . '/view.php', array('id' => $cm->id));
}
}