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


PHP cm_info::get_modinfo方法代码示例

本文整理汇总了PHP中cm_info::get_modinfo方法的典型用法代码示例。如果您正苦于以下问题:PHP cm_info::get_modinfo方法的具体用法?PHP cm_info::get_modinfo怎么用?PHP cm_info::get_modinfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cm_info的用法示例。


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

示例1: forum_is_user_group_discussion

/**
 * Returns whether the discussion group is visible by the current user or not.
 *
 * @since Moodle 2.8, 2.7.1, 2.6.4
 * @param cm_info $cm The discussion course module
 * @param int $discussiongroupid The discussion groupid
 * @return bool
 */
function forum_is_user_group_discussion(cm_info $cm, $discussiongroupid)
{
    if ($discussiongroupid == -1 || $cm->effectivegroupmode != SEPARATEGROUPS) {
        return true;
    }
    if (isguestuser()) {
        return false;
    }
    if (has_capability('moodle/site:accessallgroups', context_module::instance($cm->id)) || in_array($discussiongroupid, $cm->get_modinfo()->get_groups($cm->groupingid))) {
        return true;
    }
    return false;
}
开发者ID:abhilash1994,项目名称:moodle,代码行数:21,代码来源:lib.php

示例2: get_print_section_cm_text

/**
 * Obtains shared data that is used in print_section when displaying a
 * course-module entry.
 *
 * Calls format_text or format_string as appropriate, and obtains the correct icon.
 *
 * This data is also used in other areas of the code.
 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
 * @param object $course Moodle course object
 * @return array An array with the following values in this order:
 *   $content (optional extra content for after link),
 *   $instancename (text of link)
 */
function get_print_section_cm_text(cm_info $cm, $course)
{
    global $OUTPUT;
    // Get content from modinfo if specified. Content displays either
    // in addition to the standard link (below), or replaces it if
    // the link is turned off by setting ->url to null.
    if (($content = $cm->get_content()) !== '') {
        // Improve filter performance by preloading filter setttings for all
        // activities on the course (this does nothing if called multiple
        // times)
        filter_preload_activities($cm->get_modinfo());
        // Get module context
        $modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
        $labelformatoptions = new stdClass();
        $labelformatoptions->noclean = true;
        $labelformatoptions->overflowdiv = true;
        $labelformatoptions->context = $modulecontext;
        $content = format_text($content, FORMAT_HTML, $labelformatoptions);
    } else {
        $content = '';
    }
    // Get course context
    $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
    $stringoptions = new stdClass();
    $stringoptions->context = $coursecontext;
    $instancename = format_string($cm->name, true, $stringoptions);
    return array($content, $instancename);
}
开发者ID:numbas,项目名称:moodle,代码行数:41,代码来源:lib.php

示例3: getFollowingSib

 /**
  * For an activity LO, retrieves the moodle id of the following activity/resource (course_module) in the section of the activity
  * or null if this is the last activity in that section
  * @param \cm_info $rawData Moodle internal info for a course module
  * @return string|NULL  id of the following activity/resource (Course_module)
  */
 private function getFollowingSib($rawData)
 {
     $course_info = $rawData->get_modinfo();
     //get the course_modinfo object with all data of the course
     $section = $course_info->get_section_info($rawData->sectionnum);
     $cmsId = explode(',', $section->sequence);
     //array with the ids of the cms in that section
     $position = array_keys($cmsId, $rawData->id);
     //position of the cm in the sequence
     $pos = $position[0];
     $num_mods = count($cmsId);
     while (true) {
         // 	if($position[0]==(count($cmsId)-1)){   //it is the last in the section, not previous cm
         if ($pos == $num_mods - 1) {
             //it is the last in the section, not previous cm
             $FollowingSib = null;
             break;
         } else {
             // get the previous cm in the sequence
             $FollowingSib = $cmsId[$pos + 1];
             // check if type is ignored
             $factory = Intuitel::getAdaptorInstance()->getGuessedFactory($course_info->get_cm($FollowingSib));
             if (!$factory->toBeIgnored()) {
                 break;
             }
         }
         $pos++;
     }
     // end of while
     return $FollowingSib;
 }
开发者ID:juacas,项目名称:moodle-block_intuitel,代码行数:37,代码来源:ModuleLOFactory.php

示例4: is_user_visible

 /**
  * Checks if an activity is visible to the given user.
  *
  * Unlike other checks in the availability system, this check includes the
  * $cm->visible flag. It is equivalent to $cm->uservisible.
  *
  * If you have already checked (or do not care whether) the user has access
  * to the course, you can set $checkcourse to false to save it checking
  * course access.
  *
  * When checking for the current user, you should generally not call
  * this function. Instead, use get_fast_modinfo to get a cm_info object,
  * then simply check the $cm->uservisible flag. This function is intended
  * to obtain that information for a separate course-module object that
  * wasn't loaded with get_fast_modinfo, or for a different user.
  *
  * This function has a performance cost unless the availability system is
  * disabled, and you supply a $cm object with necessary fields, and you
  * don't check course access.
  *
  * @param int|\stdClass|\cm_info $cmorid Object or id representing activity
  * @param int $userid User id (0 = current user)
  * @param bool $checkcourse If true, checks whether the user has course access
  * @return bool True if the activity is visible to the specified user
  * @throws \moodle_exception If the cmid doesn't exist
  */
 public static function is_user_visible($cmorid, $userid = 0, $checkcourse = true)
 {
     global $USER, $DB, $CFG;
     // Evaluate user id.
     if (!$userid) {
         $userid = $USER->id;
     }
     // If this happens to be already called with a cm_info for the right user
     // then just return uservisible.
     if ($cmorid instanceof \cm_info && $cmorid->get_modinfo()->userid == $userid) {
         return $cmorid->uservisible;
     }
     // If the $cmorid isn't an object or doesn't have required fields, load it.
     if (is_object($cmorid) && isset($cmorid->course) && isset($cmorid->visible)) {
         $cm = $cmorid;
     } else {
         if (is_object($cmorid)) {
             $cmorid = $cmorid->id;
         }
         $cm = $DB->get_record('course_modules', array('id' => $cmorid));
         if (!$cm) {
             // In some error cases, the course module may not exist.
             debugging('info_module::is_user_visible called with invalid cmid ' . $cmorid, DEBUG_DEVELOPER);
             return false;
         }
     }
     // If requested, check user can access the course.
     if ($checkcourse) {
         $coursecontext = \context_course::instance($cm->course);
         if (!is_enrolled($coursecontext, $userid, '', true) && !has_capability('moodle/course:view', $coursecontext, $userid)) {
             return false;
         }
     }
     // If availability is disabled, then all we need to do is check the visible flag.
     if (!$CFG->enableavailability && $cm->visible) {
         return true;
     }
     // When availability is enabled, access can depend on 3 things:
     // 1. $cm->visible
     // 2. $cm->availability
     // 3. $section->availability (for activity section and possibly for
     //    parent sections)
     // As a result we cannot take short cuts any longer and must get
     // standard modinfo.
     $modinfo = get_fast_modinfo($cm->course, $userid);
     $cms = $modinfo->get_cms();
     if (!isset($cms[$cm->id])) {
         // In some cases this might get called with a cmid that is no longer
         // available, for example when a module is hidden at system level.
         debugging('info_module::is_user_visible called with invalid cmid ' . $cm->id, DEBUG_DEVELOPER);
         return false;
     }
     return $cms[$cm->id]->uservisible;
 }
开发者ID:adonm,项目名称:learning,代码行数:80,代码来源:info_module.php

示例5: is_user_visible

 /**
  * Checks if an activity is visible to the given user.
  *
  * Unlike other checks in the availability system, this check includes the
  * $cm->visible flag and also (if enabled) the groupmembersonly feature.
  * It is equivalent to $cm->uservisible.
  *
  * If you have already checked (or do not care whether) the user has access
  * to the course, you can set $checkcourse to false to save it checking
  * course access.
  *
  * When checking for the current user, you should generally not call
  * this function. Instead, use get_fast_modinfo to get a cm_info object,
  * then simply check the $cm->uservisible flag. This function is intended
  * to obtain that information for a separate course-module object that
  * wasn't loaded with get_fast_modinfo, or for a different user.
  *
  * This function has a performance cost unless the availability system is
  * disabled, and you supply a $cm object with necessary fields, and you
  * don't check course access.
  *
  * @param int|\stdClass|\cm_info $cmorid Object or id representing activity
  * @param int $userid User id (0 = current user)
  * @param bool $checkcourse If true, checks whether the user has course access
  * @return bool True if the activity is visible to the specified user
  * @throws \moodle_exception If the cmid doesn't exist
  */
 public static function is_user_visible($cmorid, $userid = 0, $checkcourse = true)
 {
     global $USER, $DB, $CFG;
     // Evaluate user id.
     if (!$userid) {
         $userid = $USER->id;
     }
     // If this happens to be already called with a cm_info for the right user
     // then just return uservisible.
     if ($cmorid instanceof \cm_info && $cmorid->get_modinfo()->userid == $userid) {
         return $cmorid->uservisible;
     }
     // If the $cmorid isn't an object or doesn't have required fields, load it.
     if (is_object($cmorid) && isset($cmorid->course) && isset($cmorid->visible)) {
         $cm = $cmorid;
     } else {
         if (is_object($cmorid)) {
             $cmorid = $cmorid->id;
         }
         $cm = $DB->get_record('course_modules', array('id' => $cmorid), '*', MUST_EXIST);
     }
     // Check the groupmembersonly feature.
     if (!groups_course_module_visible($cm, $userid)) {
         return false;
     }
     // If requested, check user can access the course.
     if ($checkcourse) {
         $coursecontext = \context_course::instance($cm->course);
         if (!is_enrolled($coursecontext, $userid, '', true) && !has_capability('moodle/course:view', $coursecontext, $userid)) {
             return false;
         }
     }
     // If availability is disabled, then all we need to do is check the visible flag.
     if (!$CFG->enableavailability && $cm->visible) {
         return true;
     }
     // When availability is enabled, access can depend on 3 things:
     // 1. $cm->visible
     // 2. $cm->availability
     // 3. $section->availability (for activity section and possibly for
     //    parent sections)
     // As a result we cannot take short cuts any longer and must get
     // standard modinfo.
     $modinfo = get_fast_modinfo($cm->course, $userid);
     return $modinfo->get_cm($cm->id)->uservisible;
 }
开发者ID:ruddj,项目名称:moodle,代码行数:73,代码来源:info_module.php


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