Exemplo n.º 1
0
    /**
     * If dynamic data for this course-module is not yet available, gets it.
     *
     * This function is automatically called when requesting any course_modinfo property
     * that can be modified by modules (have a set_xxx method).
     *
     * Dynamic data is data which does not come directly from the cache but is calculated at
     * runtime based on the current user. Primarily this concerns whether the user can access
     * the module or not.
     *
     * As part of this function, the module's _cm_info_dynamic function from its lib.php will
     * be called (if it exists).
     * @return void
     */
    private function obtain_dynamic_data() {
        global $CFG;
        $userid = $this->modinfo->get_user_id();
        if ($this->state >= self::STATE_BUILDING_DYNAMIC || $userid == -1) {
            return;
        }
        $this->state = self::STATE_BUILDING_DYNAMIC;

        if (!empty($CFG->enableavailability)) {
            require_once($CFG->libdir. '/conditionlib.php');
            // Get availability information
            $ci = new condition_info($this);
            // Note that the modinfo currently available only includes minimal details (basic data)
            // but we know that this function does not need anything more than basic data.
            $this->available = $ci->is_available($this->availableinfo, true,
                    $userid, $this->modinfo);

            // Check parent section
            $parentsection = $this->modinfo->get_section_info($this->sectionnum);
            if (!$parentsection->available) {
                // Do not store info from section here, as that is already
                // presented from the section (if appropriate) - just change
                // the flag
                $this->available = false;
            }
        } else {
            $this->available = true;
        }

        // Update visible state for current user
        $this->update_user_visible();

        // Let module make dynamic changes at this point
        $this->call_mod_function('cm_info_dynamic');
        $this->state = self::STATE_DYNAMIC;
    }
Exemplo n.º 2
0
 /**
  * If dynamic data for this course-module is not yet available, gets it.
  *
  * This function is automatically called when constructing course_modinfo, so users don't
  * need to call it.
  *
  * Dynamic data is data which does not come directly from the cache but is calculated at
  * runtime based on the current user. Primarily this concerns whether the user can access
  * the module or not.
  *
  * As part of this function, the module's _cm_info_dynamic function from its lib.php will
  * be called (if it exists).
  * @return void
  */
 public function obtain_dynamic_data()
 {
     global $CFG;
     if ($this->state >= self::STATE_DYNAMIC) {
         return;
     }
     $userid = $this->modinfo->get_user_id();
     if (!empty($CFG->enableavailability)) {
         // Get availability information
         $ci = new condition_info($this);
         // Note that the modinfo currently available only includes minimal details (basic data)
         // so passing it to this function is a bit dangerous as it would cause infinite
         // recursion if it tried to get dynamic data, however we know that this function only
         // uses basic data.
         $this->available = $ci->is_available($this->availableinfo, true, $userid, $this->modinfo);
         // Check parent section
         $parentsection = $this->modinfo->get_section_info($this->sectionnum);
         if (!$parentsection->available) {
             // Do not store info from section here, as that is already
             // presented from the section (if appropriate) - just change
             // the flag
             $this->available = false;
         }
     } else {
         $this->available = true;
     }
     // Update visible state for current user
     $this->update_user_visible();
     // Let module make dynamic changes at this point
     $this->call_mod_function('cm_info_dynamic');
     $this->state = self::STATE_DYNAMIC;
 }