Permalink
Browse files

My moodle sticky block config now generic, can be used for any pagetype.

Currently implemented: course-view (and my moodle, of course)
  • Loading branch information...
mjollnir_
mjollnir_ committed Oct 16, 2005
1 parent b32145b commit 12177083634d78ccc47e4102dacc27a5d06d4684
Showing with 130 additions and 78 deletions.
  1. +2 −2 admin/index.php
  2. +0 −55 admin/mymoodle.php
  3. +90 −0 admin/stickyblocks.php
  4. +1 −1 course/view.php
  5. +5 −0 lang/en/admin.php
  6. +1 −0 lang/en/moodle.php
  7. +18 −3 lib/pagelib.php
  8. +13 −17 my/pagelib.php
View
@@ -411,8 +411,8 @@
"<font size=\"+1\">&nbsp;</font>".get_string("adminhelplogs"));
$table->data[] = array("<font size=\"+1\"><b><a href=\"../files/index.php?id=$site->id\">".get_string("sitefiles")."</a></b></font>",
"<font size=\"+1\">&nbsp;</font>".get_string("adminhelpsitefiles"));
- $table->data[] = array("<font size=+1><b><a href=\"mymoodle.php\">".get_string('mymoodle','my')."</a></b>",
- "<font size=+1>&nbsp;</font>".get_string("adminhelpmymoodle"));
+ $table->data[] = array("<font size=+1><b><a href=\"stickyblocks.php\">".get_string('stickyblocks','admin')."</a></b>",
+ "<font size=+1>&nbsp;</font>".get_string("adminhelpstickyblocks"));
if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) {
$table->data[] = array("<font size=\"+1\"><b><a href=\"$CFG->dbtype/frame.php\">".get_string("managedatabase")."</a></b></font>",
"<font size=\"+1\">&nbsp;</font>".get_string("adminhelpmanagedatabase"));
View
@@ -1,55 +0,0 @@
-<?
-{
- require_once(dirname(dirname(__FILE__)).'/config.php');
- require_once($CFG->dirroot.'/my/pagelib.php');
- require_once($CFG->dirroot.'/lib/blocklib.php');
-
- require_login();
-
- if (!isadmin()) {
- error("Only the admin can use this page");
- }
-
- define('OVERRIDE_PAGE_TYPE',PAGE_MY_MOODLE);
-
- $PAGE = page_create_object(PAGE_MY_MOODLE,0);
-
- $blocks = blocks_setup($PAGE,BLOCKS_PINNED_TRUE);
-
- $strtitle = get_string('pinblocks','my');
-
- print_header($strtitle,$strtitle,'<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/index.php">'.
- get_string('admin').'</a> -> '.$strtitle);
-
- echo '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">';
- echo '<tr valign="top">';
-
-
- $blocks_preferred_width = bounded_number(180, blocks_preferred_width($blocks[BLOCK_POS_LEFT]), 210);
-
-
- echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="left-column">';
- blocks_print_group($PAGE, $blocks, BLOCK_POS_LEFT);
- echo '</td>';
-
- echo '<td valign="top" width="*" id="middle-column">';
- print_simple_box_start('center');
- print_heading($strtitle);
- print_string('pinblocksexplan','my');
- print_simple_box_end();
- echo '</td>';
-
-
- echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="left-column">';
- blocks_print_group($PAGE, $blocks, BLOCK_POS_RIGHT);
- echo '</td>';
-
- echo '</tr></table>';
-
- print_footer();
-
-
-}
-
-
-?>
View
@@ -0,0 +1,90 @@
+<?
+{
+
+ require_once(dirname(dirname(__FILE__)).'/config.php');
+ require_once($CFG->dirroot.'/my/pagelib.php');
+ require_once($CFG->dirroot.'/lib/pagelib.php');
+ require_once($CFG->dirroot.'/lib/blocklib.php');
+
+ $pt = optional_param('pt',null,PARAM_CLEAN);
+
+ $pagetypes = array(PAGE_MY_MOODLE => array('id' => PAGE_MY_MOODLE,
+ 'lib' => '/my/pagelib.php',
+ 'name' => get_string('stickyblocksmymoodle','admin')),
+ PAGE_COURSE_VIEW => array('id' => PAGE_COURSE_VIEW,
+ 'lib' => '/lib/pagelib.php',
+ 'name' => get_string('stickyblockscourseview','admin'))
+ // ... more?
+ );
+
+ // for choose_from_menu
+ $options = array();
+ foreach ($pagetypes as $p) {
+ $options[$p['id']] = $p['name'];
+ }
+
+ require_login();
+
+ if (!isadmin()) {
+ error("Only the admin can use this page");
+ }
+
+ // first thing to do is print the dropdown menu
+
+ $strtitle = get_string('stickyblocks','admin');
+ $strheading = get_string('adminhelpstickyblocks');
+
+ print_header($strtitle,$strtitle,'<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/index.php">'.
+ get_string('admin').'</a> -> '.$strtitle);
+
+ echo '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">';
+ echo '<tr valign="top">';
+
+
+ if (!empty($pt)) {
+ require_once($CFG->dirroot.$pagetypes[$pt]['lib']);
+
+ define('ADMIN_STICKYBLOCKS',$pt);
+
+ $PAGE = page_create_object($pt);
+
+ $blocks = blocks_setup($PAGE,BLOCKS_PINNED_TRUE);
+
+ $blocks_preferred_width = bounded_number(180, blocks_preferred_width($blocks[BLOCK_POS_LEFT]), 210);
+ echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="left-column">';
+
+ blocks_print_group($PAGE, $blocks, BLOCK_POS_LEFT);
+ } else {
+ echo '<td style="vertical-align: top;" id="left-column">';
+ }
+ echo '</td>';
+
+
+ echo '<td valign="top" width="*" id="middle-column">';
+ print_simple_box_start('center');
+ print_heading($strheading);
+ echo '<form method="post" action="'.$CFG->wwwroot.'/admin/stickyblocks.php">'
+ .'<p align="center">'.get_string('stickyblockspagetype','admin').': ';
+ choose_from_menu($options,'pt',$pt,'choose','this.form.submit();');
+ echo '</p></form>';
+ echo get_string('stickyblocksduplicatenotice','admin');
+ print_simple_box_end();
+ echo '</td>';
+
+
+ if (!empty($pt)) {
+ echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="left-column">';
+ blocks_print_group($PAGE, $blocks, BLOCK_POS_RIGHT);
+ }
+ echo '<td style="vertical-align: top;" id="left-column">';
+ echo '</td>';
+
+ echo '</tr></table>';
+
+ print_footer();
+
+
+}
+
+
+?>
View
@@ -54,7 +54,7 @@
}
$PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id);
- $pageblocks = blocks_setup($PAGE);
+ $pageblocks = blocks_setup($PAGE,BLOCKS_PINNED_BOTH);
if (!isset($USER->editing)) {
$USER->editing = false;
View
@@ -152,6 +152,11 @@
$string['sitemaintenanceoff'] = 'Maintenance mode has been disabled and the site is running normally again';
$string['sitemaintenanceon'] = 'Your site is currently in maintenance mode (only admins can log in or use the site).';
$string['sitemaintenancewarning'] = 'Your site is currently in maintenance mode (only admins can log in). To return this site to normal operation, <a href=\"maintenance.php\">disable maintenance mode</a>.';
+$string['stickyblocks'] = 'Sticky blocks';
+$string['stickyblocksduplicatenotice'] = 'If any block you add here is already present in a particular page, it will result in a duplicate.<br />Only the pinned block will be non-editable, the duplicate will still be editable.';
+$string['stickyblockspagetype'] = 'Page type to configure';
+$string['stickyblocksmymoodle'] = 'My moodle';
+$string['stickyblockscourseview'] = 'Course page';
$string['tabselectedtofront'] = 'On tables with tabs, should the row with the currently selected tag be placed at the front';
$string['therewereerrors'] = 'There were errors in your data';
$string['timezoneforced'] = 'This is forced by the site administrator';
View
@@ -61,6 +61,7 @@
$string['adminhelpreports'] = 'Ranking of courses for various criteria';
$string['adminhelpsitefiles'] = 'For publishing general files or uploading external backups';
$string['adminhelpsitesettings'] = 'Define how the front page of the site looks';
+$string['adminhelpstickyblocks'] = 'Configure moodle wide sticky blocks';
$string['adminhelpthemes'] = 'Choose how the site looks (colours, fonts etc)';
$string['adminhelpuploadusers'] = 'Import new user accounts from a text file';
$string['adminhelpusers'] = 'Define your users and set up authentication';
View
@@ -297,7 +297,7 @@ function init_full() {
// is this page always editable, regardless of anything else?
function edit_always() {
- return false;
+ return (isadmin() && defined('ADMIN_STICKYBLOCKS'));
}
}
@@ -319,7 +319,7 @@ class page_course extends page_base {
// Do any validation of the officially recognized bits of the data and forward to parent.
// Do NOT load up "expensive" resouces (e.g. SQL data) here!
function init_quick($data) {
- if(empty($data->pageid)) {
+ if(empty($data->pageid) && !defined('ADMIN_STICKYBLOCKS')) {
error('Cannot quickly initialize page: empty course id');
}
parent::init_quick($data);
@@ -333,8 +333,11 @@ function init_full() {
if($this->full_init_done) {
return;
}
+ if (empty($this->id)) {
+ $this->id = 0; // avoid db errors
+ }
$this->courserecord = get_record('course', 'id', $this->id);
- if(empty($this->courserecord)) {
+ if(empty($this->courserecord) && !defined('ADMIN_STICKYBLOCKS')) {
error('Cannot fully initialize page: invalid course id '. $this->id);
}
$this->full_init_done = true;
@@ -345,12 +348,18 @@ function init_full() {
// When is a user said to have "editing rights" in this page? This would have something
// to do with roles, in the future.
function user_allowed_editing() {
+ if (isadmin() && defined('ADMIN_STICKYBLOCKS')) {
+ return true;
+ }
return isteacheredit($this->id);
}
// Is the user actually editing this page right now? This would have something
// to do with roles, in the future.
function user_is_editing() {
+ if (isadmin() && defined('ADMIN_STICKYBLOCKS')) {
+ return true;
+ }
return isediting($this->id);
}
@@ -423,6 +432,9 @@ function get_format_name() {
// This should return a fully qualified path to the URL which is responsible for displaying us.
function url_get_path() {
global $CFG;
+ if (defined('ADMIN_STICKYBLOCKS')) {
+ return $CFG->wwwroot.'/admin/stickyblocks.php';
+ }
if($this->id == SITEID) {
return $CFG->wwwroot .'/index.php';
}
@@ -434,6 +446,9 @@ function url_get_path() {
// This should return an associative array of any GET/POST parameters that are needed by the URL
// which displays us to make it work. If none are needed, return an empty array.
function url_get_parameters() {
+ if (defined('ADMIN_STICKYBLOCKS')) {
+ return array('pt' => ADMIN_STICKYBLOCKS);
+ }
if($this->id == SITEID) {
return array();
}
View
@@ -12,23 +12,17 @@ function get_type() {
function user_allowed_editing() {
page_id_and_class($id,$class);
- if (isadmin() && $id == PAGE_ADMIN_MY_MOODLE) {
+ if ($id == PAGE_MY_MOODLE) {
return true;
- } elseif ($id == PAGE_MY_MOODLE) {
+ } else if (isadmin() && defined('ADMIN_STICKYBLOCKS')) {
return true;
}
return false;
}
- function edit_always() {
- page_id_and_class($id,$class);
- return ($id == PAGE_ADMIN_MY_MOODLE && isadmin());
- }
-
function user_is_editing() {
global $USER;
- page_id_and_class($id,$class);
- if (isadmin() && $id == PAGE_ADMIN_MY_MOODLE) {
+ if (isadmin() && defined('ADMIN_STICKYBLOCKS')) {
return true;
}
return (!empty($USER->editing));
@@ -51,10 +45,17 @@ function print_header($title) {
function url_get_path() {
page_id_and_class($id,$class);
- if ($id == PAGE_ADMIN_MY_MOODLE) {
- return $GLOBALS['CFG']->wwwroot.'/admin/mymoodle.php';
+ if ($id == PAGE_MY_MOODLE) {
+ return $GLOBALS['CFG']->wwwroot.'/my/index.php';
+ } elseif (defined('ADMIN_STICKYBLOCKS')){
+ return $GLOBALS['CFG']->wwwroot.'/admin/stickyblocks.php';
+ }
+ }
+
+ function url_get_parameters() {
+ if (defined('ADMIN_STICKYBLOCKS')) {
+ return array('pt' => ADMIN_STICKYBLOCKS);
}
- return $GLOBALS['CFG']->wwwroot.'/my/index.php';
}
function blocks_default_position() {
@@ -81,13 +82,8 @@ function get_format_name() {
define('PAGE_MY_MOODLE', 'my-index');
-define('PAGE_ADMIN_MY_MOODLE', 'admin-mymoodle');
define('MY_MOODLE_FORMAT', 'my'); //doing this so we don't run into problems with applicable formats.
page_map_class(PAGE_MY_MOODLE, 'page_my_moodle');
-page_map_class(PAGE_ADMIN_MY_MOODLE,'page_my_moodle');
-
-
-
?>

0 comments on commit 1217708

Please sign in to comment.