Skip to content

Commit

Permalink
My moodle sticky block config now generic, can be used for any pagetype.
Browse files Browse the repository at this point in the history
Currently implemented: course-view (and my moodle, of course)
  • Loading branch information
mjollnir_ committed Oct 16, 2005
1 parent b32145b commit 1217708
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 78 deletions.
4 changes: 2 additions & 2 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
55 changes: 0 additions & 55 deletions admin/mymoodle.php

This file was deleted.

90 changes: 90 additions & 0 deletions admin/stickyblocks.php
Original file line number Diff line number Diff line change
@@ -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();


}


?>
2 changes: 1 addition & 1 deletion course/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
21 changes: 18 additions & 3 deletions lib/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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';
}
Expand All @@ -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();
}
Expand Down
30 changes: 13 additions & 17 deletions my/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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() {
Expand All @@ -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.