コード例 #1
0
ファイル: accesslib.php プロジェクト: rolandovanegas/moodle
/**
 * Gets a string for sql calls, searching for stuff in this context or above
 *
 * NOTE: use $DB->get_in_or_equal($context->get_parent_context_ids()...
 *
 * @deprecated since 2.2, $context->use get_parent_context_ids() instead
 * @param context $context
 * @return string
 */
function get_related_contexts_string(context $context)
{
    if ($parents = $context->get_parent_context_ids()) {
        return ' IN (' . $context->id . ',' . implode(',', $parents) . ')';
    } else {
        return ' =' . $context->id;
    }
}
コード例 #2
0
/**
 * Gets a string for sql calls, searching for stuff in this context or above.
 *
 * @deprecated since 2.2
 * @see context::get_parent_context_ids()
 * @param context $context
 * @return string
 */
function get_related_contexts_string(context $context)
{
    debugging('get_related_contexts_string() is deprecated, please use $context->get_parent_context_ids(true) instead.', DEBUG_DEVELOPER);
    if ($parents = $context->get_parent_context_ids()) {
        return ' IN (' . $context->id . ',' . implode(',', $parents) . ')';
    } else {
        return ' =' . $context->id;
    }
}
コード例 #3
0
ファイル: accesslib.php プロジェクト: rwijaya/moodle
/**
 * Counts all the users assigned this role in this context or higher
 *
 * @param int|array $roleid either int or an array of ints
 * @param context $context
 * @param bool $parent if true, get list of users assigned in higher context too
 * @return int Returns the result count
 */
function count_role_users($roleid, context $context, $parent = false) {
    global $DB;

    if ($parent) {
        if ($contexts = $context->get_parent_context_ids()) {
            $parentcontexts = ' OR r.contextid IN ('.implode(',', $contexts).')';
        } else {
            $parentcontexts = '';
        }
    } else {
        $parentcontexts = '';
    }

    if ($roleid) {
        list($rids, $params) = $DB->get_in_or_equal($roleid, SQL_PARAMS_QM);
        $roleselect = "AND r.roleid $rids";
    } else {
        $params = array();
        $roleselect = '';
    }

    array_unshift($params, $context->id);

    $sql = "SELECT COUNT(u.id)
              FROM {role_assignments} r
              JOIN {user} u ON u.id = r.userid
             WHERE (r.contextid = ? $parentcontexts)
                   $roleselect
                   AND u.deleted = 0";

    return $DB->count_records_sql($sql, $params);
}
コード例 #4
0
/**
 * Check if cohort exists and user is allowed to access it from the given context.
 *
 * @param stdClass|int $cohortorid cohort object or id
 * @param context $currentcontext current context (course) where visibility is checked
 * @return boolean
 */
function meditraxcohort_can_view_cohort($cohortorid, $currentcontext)
{
    global $DB;
    if (is_numeric($cohortorid)) {
        $cohort = $DB->get_record('cohort', array('id' => $cohortorid), 'id, contextid, visible');
    } else {
        $cohort = $cohortorid;
    }
    if ($cohort && in_array($cohort->contextid, $currentcontext->get_parent_context_ids())) {
        if ($cohort->visible) {
            return true;
        }
        $cohortcontext = context::instance_by_id($cohort->contextid);
        if (has_capability('moodle/cohort:view', $cohortcontext)) {
            return true;
        }
    }
    return false;
}