get_site()

get_site()

by Tim Hunt -
Number of replies: 2
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Get site is currently written

 
/**
* Returns $course object of the top-level site.
*
* @return course A {@link $COURSE} object for the site
*/
function get_site() {

global $SITE;

if (!empty($SITE->id)) { // We already have a global to use, so return that
return $SITE;
}

if ($course = get_record('course', 'category', 0)) {
return $course;
} else {
return false;
}
}


Why not change the second if to

 
if ($SITE = get_record('course', 'category', 0)) {
return $SITE;
} else {
return false;
}


So that if you call get_site once, the global is initialised for future calls.
Average of ratings: -
In reply to Tim Hunt

Re: get_site()

by Greg Lyon -
Not exactly an answer to your question, but rather another question...What is a 'site' in moodle?  seems related to courses/categories and groups but I don't get how from the brief look at the code just now.
In reply to Greg Lyon

Re: get_site()

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The site represents the entire moodle installation, which in particular means the front page. However, internally it is implemented as just another course (normally course id 1) that can have blocks and modules etc, added, but which is treated as a bit of a special case.