General developer forum

What is SITEID in moodle?

 
Picture of Syed Ali
What is SITEID in moodle?
 

I am writing a php script and I used existing code one of the line in code is like this.


if ($courseid == SITEID)

and in other case I have difficult time to understand  following line.

$allowedroles = get_assignable_roles(context_system::instance(), ROLENAME_SHORT);


As I am not running my script from browser, but it will run in cron job and I am not sure how to get context_system::instance() and SITEID value.


Any help will really appreciated.

 
Average of ratings: -
Gareth J Barnard
Re: What is SITEID in moodle?
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developers

Hi Syed,

SITEID is the 'course id' of the site, i.e. the Front page itself is a 'course' with a specific 'site' course format.  I think SITEID is a global.  I'm not sure about your other question.

Gareth

 
Average of ratings: -
Picture of Syed Ali
Re: What is SITEID in moodle?
 


Other question is related to first line of uu_allowed_roles_cache().

What is context_course::instance(SITEID)


/**
 * Returns mapping of all roles using short role name as index.
 * @return array
 */
function uu_allowed_roles_cache() {
    $allowedroles = get_assignable_roles(context_course::instance(SITEID), ROLENAME_SHORT);
    foreach ($allowedroles as $rid=>$rname) {
        $rolecache[$rid] = new stdClass();
        $rolecache[$rid]->id   = $rid;
        $rolecache[$rid]->name = $rname;
        if (!is_numeric($rname)) { // only non-numeric shortnames are supported!!!
            $rolecache[$rname] = new stdClass();
            $rolecache[$rname]->id   = $rid;
            $rolecache[$rname]->name = $rname;
        }
    }
    return $rolecache;
}

 
Average of ratings: -
Davo
Re: What is SITEID in moodle?
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developers

context_course::instance(SITEID) - this is the context for the front page for the site - so the function is giving a list of the roles that can be assigned to the front page course.

 
Average of ratings: -