Beispiel #1
0
/**
 * External function for retrieving module data.
 *
 * Using external method so we can cache results
 * to improve performance for all page_module
 * instances.
 *
 * @param int $cmid Course Module ID
 * @return array
 **/
function block_page_module_init($cmid)
{
    global $COURSE, $CFG, $PAGE, $BLOCK_PAGE_MODULE;
    static $page = false, $baseurl = '';
    if (!$page) {
        if (!empty($PAGE) and get_class($PAGE) == 'format_page') {
            $page = $PAGE->get_formatpage();
        } else {
            require_once $CFG->dirroot . '/course/format/page/lib.php';
            if (!($page = page_get_current_page())) {
                $page = new stdClass();
                $page->id = 0;
            }
        }
        if ($COURSE->id == SITEID) {
            $baseurl = "{$CFG->wwwroot}/index.php?id={$COURSE->id}&page={$page->id}";
        } else {
            $baseurl = "{$CFG->wwwroot}/course/view.php?id={$COURSE->id}&page={$page->id}";
        }
        if (!empty($page->id)) {
            // Since we know what page will be printed, lets
            // get all of our records in bulk and cache the results
            if ($cms = get_records_sql("SELECT c.*\n                                           FROM {$CFG->prefix}course_modules c,\n                                                {$CFG->prefix}format_page p,\n                                                {$CFG->prefix}format_page_items i\n                                          WHERE i.cmid = c.id\n                                            AND p.id = i.pageid\n                                            AND p.id = {$page->id}")) {
                // Save for later
                $BLOCK_PAGE_MODULE['cms'] = $cms;
                if ($modules = get_records('modules')) {
                    // Save for later
                    $BLOCK_PAGE_MODULE['modules'] = $modules;
                    $mods = array();
                    foreach ($cms as $cm) {
                        $mods[$modules[$cm->module]->name][] = $cm->instance;
                    }
                    $instances = array();
                    foreach ($mods as $modname => $instanceids) {
                        if ($records = get_records_list($modname, 'id', implode(',', $instanceids))) {
                            $instances[$modname] = $records;
                        }
                    }
                    // Save for later
                    $BLOCK_PAGE_MODULE['instances'] = $instances;
                }
            }
        } else {
            // OK, we cannot do anything cool, make sure we dont break rest of the script
            $BLOCK_PAGE_MODULE = array('cms' => array(), 'modules' => array(), 'instances' => array());
        }
    }
    if (!($cm = block_page_module_get_cm($cmid, $page->id))) {
        return false;
    }
    if (!($module = block_page_module_get_module($cm->module))) {
        return false;
    }
    if (!($moduleinstance = block_page_module_get_instance($module->name, $cm->instance))) {
        return false;
    }
    return array($cm, $module, $moduleinstance, $COURSE, $page, $baseurl);
}
Beispiel #2
0
 /**
  * Local method - returns the current
  * format_page
  *
  * @return object
  **/
 function get_formatpage()
 {
     if ($this->formatpage == NULL) {
         global $CFG;
         require_once $CFG->dirroot . '/course/format/page/lib.php';
         if (!empty($this->courserecord)) {
             $courseid = $this->courserecord->id;
         } else {
             $courseid = 0;
         }
         if ($currentpage = page_get_current_page($courseid)) {
             $this->formatpage = $currentpage;
         } else {
             $this->formatpage = new stdClass();
             $this->formatpage->id = 0;
         }
     }
     return $this->formatpage;
 }
 /**
  * Compared passed ID to see if it
  * is the current page ID in the course
  *
  * @param int $pageid Page ID
  * @return boolean
  **/
 protected function is_current($pageid)
 {
     if ($this->currentpageid === NULL) {
         if ($currentpage = page_get_current_page(0, false)) {
             $this->currentpageid = $currentpage->id;
         } else {
             $this->currentpageid = 0;
         }
     }
     if ($pageid == $this->currentpageid) {
         $this->active = true;
         return true;
     } else {
         return false;
     }
 }
Beispiel #4
0
/**
 * Prints the "Back to X" where is is the name
 * of a page format page.
 *
 * @return void
 **/
function page_theme_print_backto_button()
{
    global $CFG, $SESSION, $COURSE;
    if (page_theme_config('page_backtobutton')) {
        if (isset($COURSE->format) and $COURSE->format == 'page') {
            $url = qualified_me();
            $url = strip_querystring($url);
            // URLs where the format could be displayed
            $locations = array($CFG->wwwroot, $CFG->wwwroot . '/', $CFG->wwwroot . '/index.php', $CFG->wwwroot . '/course/view.php', $CFG->wwwroot . '/course/format/page/format.php');
            // See if we aren't on a course format page already
            if (!in_array($url, $locations)) {
                require_once $CFG->dirroot . '/course/format/page/lib.php';
                // Make sure we have a page to go to
                if ($page = page_get_current_page($COURSE->id)) {
                    echo '<p><span class="button"><a href="' . $CFG->wwwroot . '/course/view.php?id=' . $page->courseid . '&amp;page=' . $page->id . '">' . get_string('backtopage', 'theme_page', page_get_name($page)) . '</a></span></p>';
                }
            }
        }
    }
}
Beispiel #5
0
/// Could be set by course/view.php
if (!isset($course)) {
    if (!($course = get_record('course', 'id', $id))) {
        error(get_string('invalidcourseid', 'format_page'));
    }
    if ($course->id != SITEID or $CFG->forcelogin) {
        require_login($course->id);
    }
}
/// Load up the context for calling has_capability later
$context = get_context_instance(CONTEXT_COURSE, $course->id);
/// Set course display
if ($pageid > 0) {
    $pageid = page_set_current_page($course->id, $pageid);
} else {
    if ($page = page_get_current_page($course->id)) {
        $displayid = $page->id;
    } else {
        $displayid = 0;
    }
    $pageid = page_set_current_page($course->id, $displayid);
}
/// Check out the $pageid - set? valid? belongs to this course?
if (!empty($pageid)) {
    if (empty($page) or $page->id != $pageid) {
        // Didn't get the page above or we got the wrong one...
        if (!($page = page_get($pageid))) {
            error('Invalid page ID');
        }
    }
    // Ensure this page is with this course
/**
 * Prints or returns the code for the "Back to X" where is is the name
 * of a page format page.
 *
 * @return void
 **/
function page_theme_print_backto_button($return = false)
{
    global $CFG, $SESSION, $COURSE;
    if (page_theme_config('page_backtobutton')) {
        if ($COURSE->format == 'page') {
            $url = qualified_me();
            $url = strip_querystring($url);
            // URLs where the format could be displayed
            $locations = array($CFG->wwwroot, $CFG->wwwroot . '/', $CFG->wwwroot . '/index.php', $CFG->wwwroot . '/course/view.php', $CFG->wwwroot . '/course/format/page/format.php');
            // See if we aren't on a course format page already
            if (!in_array($url, $locations)) {
                require_once $CFG->dirroot . '/course/format/page/lib.php';
                // Make sure we have a page to go to
                if ($page = page_get_current_page($COURSE->id)) {
                    if ($COURSE->id == SITEID) {
                        $baseurl = $CFG->wwwroot . '/index.php';
                    } else {
                        $baseurl = "{$CFG->wwwroot}/course/view.php";
                    }
                    $output = print_single_button($baseurl, array('id' => $page->courseid, 'page' => $page->id), get_string('backtopage', 'format_page', page_get_name($page)), 'get', '_self', true);
                    if ($return) {
                        return $output;
                    }
                    print $output;
                }
            }
        }
    }
}