Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (3 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/availability/classes/info.php

    r136 r1331  
    312312     * @param \base_logger $logger Logger for any warnings
    313313     * @param int $dateoffset Date offset to be added to any dates (0 = none)
    314      */
    315     public function update_after_restore($restoreid, $courseid, \base_logger $logger, $dateoffset) {
     314     * @param \base_task $task Restore task
     315     */
     316    public function update_after_restore($restoreid, $courseid, \base_logger $logger,
     317            $dateoffset, \base_task $task) {
    316318        $tree = $this->get_availability_tree();
    317319        // Set static data for use by get_restore_date_offset function.
    318         self::$restoreinfo = array('restoreid' => $restoreid, 'dateoffset' => $dateoffset);
     320        self::$restoreinfo = array('restoreid' => $restoreid, 'dateoffset' => $dateoffset,
     321                'task' => $task);
    319322        $changed = $tree->update_after_restore($restoreid, $courseid, $logger,
    320323                $this->get_thing_name());
    321324        if ($changed) {
    322325            // Save modified data.
    323             $structure = $tree->save();
    324             $this->set_in_database(json_encode($structure));
     326            if ($tree->is_empty()) {
     327                // If the tree is empty, but the tree has changed, remove this condition.
     328                $this->set_in_database(null);
     329            } else {
     330                $structure = $tree->save();
     331                $this->set_in_database(json_encode($structure));
     332            }
    325333        }
    326334    }
     
    342350        }
    343351        return self::$restoreinfo['dateoffset'];
     352    }
     353
     354    /**
     355     * Gets the restore task (specifically, the task that calls the
     356     * update_after_restore method) for the current restore.
     357     *
     358     * @param string $restoreid Restore identifier
     359     * @return \base_task Restore task
     360     * @throws coding_exception If not in a restore (or not in that restore)
     361     */
     362    public static function get_restore_task($restoreid) {
     363        if (!self::$restoreinfo) {
     364            throw new coding_exception('Only valid during restore');
     365        }
     366        if (self::$restoreinfo['restoreid'] !== $restoreid) {
     367            throw new coding_exception('Data not available for that restore id');
     368        }
     369        return self::$restoreinfo['task'];
    344370    }
    345371
     
    609635        $tree = $this->get_availability_tree();
    610636        $checker = new capability_checker($this->get_context());
     637
     638        // Filter using availability tree.
    611639        $this->modinfo = get_fast_modinfo($this->get_course());
    612         $result = $tree->filter_user_list($users, false, $this, $checker);
     640        $filtered = $tree->filter_user_list($users, false, $this, $checker);
    613641        $this->modinfo = null;
     642
     643        // Include users in the result if they're either in the filtered list,
     644        // or they have viewhidden. This logic preserves ordering of the
     645        // passed users array.
     646        $result = array();
     647        $canviewhidden = $checker->get_users_by_capability($this->get_view_hidden_capability());
     648        foreach ($users as $userid => $data) {
     649            if (array_key_exists($userid, $filtered) || array_key_exists($userid, $canviewhidden)) {
     650                $result[$userid] = $users[$userid];
     651            }
     652        }
     653
    614654        return $result;
    615655    }
     656
     657    /**
     658     * Gets the capability used to view hidden activities/sections (as
     659     * appropriate).
     660     *
     661     * @return string Name of capability used to view hidden items of this type
     662     */
     663    protected abstract function get_view_hidden_capability();
    616664
    617665    /**
     
    619667     * by the conditions applied in the availability API, similar to calling
    620668     * get_enrolled_users and then filter_user_list. As for filter_user_list,
    621      * this ONLY filteres out users with conditions that are marked as applying
     669     * this ONLY filters out users with conditions that are marked as applying
    622670     * to user lists. For example, group conditions are included but date
    623671     * conditions are not included.
     
    641689            return array('', array());
    642690        }
     691
     692        // Get SQL for the availability filter.
    643693        $tree = $this->get_availability_tree();
    644         return $tree->get_user_list_sql(false, $this, $onlyactive);
     694        list ($filtersql, $filterparams) = $tree->get_user_list_sql(false, $this, $onlyactive);
     695        if ($filtersql === '') {
     696            // No restrictions, so return empty query.
     697            return array('', array());
     698        }
     699
     700        // Get SQL for the view hidden list.
     701        list ($viewhiddensql, $viewhiddenparams) = get_enrolled_sql(
     702                $this->get_context(), $this->get_view_hidden_capability(), 0, $onlyactive);
     703
     704        // Result is a union of the two.
     705        return array('(' . $filtersql . ') UNION (' . $viewhiddensql . ')',
     706                array_merge($filterparams, $viewhiddenparams));
    645707    }
    646708
     
    652714     * object.
    653715     *
    654      * @param string $info Info string
     716     * @param \renderable|string $inforenderable Info string or renderable
    655717     * @param int|\stdClass $courseorid
    656718     * @return string Correctly formatted info string
    657719     */
    658     public static function format_info($info, $courseorid) {
     720    public static function format_info($inforenderable, $courseorid) {
     721        global $PAGE;
     722
     723        // Use renderer if required.
     724        if (is_string($inforenderable)) {
     725            $info = $inforenderable;
     726        } else {
     727            $renderer = $PAGE->get_renderer('core', 'availability');
     728            $info = $renderer->render($inforenderable);
     729        }
     730
    659731        // Don't waste time if there are no special tags.
    660732        if (strpos($info, '<AVAILABILITY_') === false) {
Note: See TracChangeset for help on using the changeset viewer.