MyMoodle: new /my/ page, contains course overview (module based, forum done). User defined blocks on /my/ page, admin defined stickyblocks. Needs lots of testing. Held off bumping version.php for blocks because of the postgres upgrade fixes Patrick is putting in.

This commit is contained in:
mjollnir_ 2005-08-16 00:25:39 +00:00
parent f209eb9d34
commit 0d6b9d4f4d
28 changed files with 624 additions and 47 deletions

View File

@ -411,6 +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"));
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"));

65
admin/mymoodle.php Normal file
View File

@ -0,0 +1,65 @@
<?
{
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);
$blockaction = optional_param('blockaction');
$blocks = blocks_get_pinned($PAGE);
if (!empty($blockaction)) {
blocks_execute_url_action($PAGE, $blocks,true);
// This re-query could be eliminated by judicious programming in blocks_execute_action(),
// but I 'm not sure if it's worth the complexity increase...
$blocks = blocks_get_pinned($PAGE);
}
$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 File

@ -32,6 +32,11 @@ class block_activity_modules extends block_list {
return $this->content;
}
function applicable_formats() {
require_once($GLOBALS['CFG']->dirroot.'/my/pagelib.php');
return array('all' => true, 'mod' => false, MY_MOODLE_FORMAT => false);
}
}
?>

View File

@ -195,6 +195,11 @@ class block_admin extends block_list {
}
}
}
function applicable_formats() {
require_once($GLOBALS['CFG']->dirroot.'/my/pagelib.php');
return array('all' => true, 'mod' => false, MY_MOODLE_FORMAT => false);
}
}
?>

View File

@ -31,8 +31,12 @@ class block_calendar_month extends block_base {
$filtercourse = array();
} else {
$courseshown = $this->instance->pageid;
if (!empty($this->instance->pageid)) {
$courseshown = $this->instance->pageid;
}
else {
$courseshown = SITEID;
}
if($courseshown == SITEID) {
// Being displayed at site level. This will cause the filter to fall back to auto-detecting

View File

@ -27,8 +27,12 @@ class block_calendar_upcoming extends block_base {
$this->content->footer = '';
} else {
$courseshown = $this->instance->pageid;
if (!empty($this->instance->pageid)) {
$courseshown = $this->instance->pageid;
}
else {
$courseshown = SITEID;
}
$this->content->footer = '<br /><a href="'.$CFG->wwwroot.
'/calendar/view.php?view=upcoming&amp;course='.$courseshown.'">'.
get_string('gotocalendar', 'calendar').'</a>...';

View File

@ -1,5 +1,7 @@
<?PHP //$Id$
include_once($CFG->dirroot . '/course/lib.php');
class block_course_list extends block_list {
function init() {
$this->title = get_string('courses');

View File

@ -23,6 +23,9 @@ class block_course_summary extends block_base {
return '';
}
if (empty($this->instance->pageid)) {
$this->instance->pageid = SITEID;
}
$course = get_record('course', 'id', $this->instance->pageid);
$this->content = New stdClass;

View File

@ -143,6 +143,19 @@ global $CFG;
}
}
if ($oldversion < 2005081600) {
$result = $result && modify_database('',"CREATE TABLE `prefix_block_pinned` (
`id` int(10) not null auto_increment,
`blockid` int(10) not null default '0',
`pagetype` varchar(20) not null default '',
`position` varchar(10) not null default '',
`weight` tinyint(3) not null default '0',
`visible` tinyint(1) not null default '0',
`configdata` text not null default '',
PRIMARY KEY(`id`)
) TYPE=MyISAM;");
}
//Finally, return result
return $result;
}

View File

@ -26,4 +26,18 @@ CREATE TABLE `prefix_block_instance` (
PRIMARY KEY(`id`),
INDEX pageid(`pageid`)
) TYPE=MyISAM;
CREATE TABLE `prefix_block_pinned` (
`id` int(10) not null auto_increment,
`blockid` int(10) not null default '0',
`pagetype` varchar(20) not null default '',
`position` varchar(10) not null default '',
`weight` tinyint(3) not null default '0',
`visible` tinyint(1) not null default '0',
`configdata` text not null default '',
PRIMARY KEY(`id`)
) TYPE=MyISAM;
# --------------------------------------------------------

View File

@ -146,6 +146,18 @@ global $CFG;
modify_database('','ALTER TABLE prefix_block_instance ALTER position SET NOT NULL');
}
if ($oldversion < 2005081600) {
$result = $result && modify_database('',"CREATE TABLE prefix_block_pinned (
id SERIAL8 PRIMARY KEY,
blockid INT8 NOT NULL default 0,
pagetype varchar(20) NOT NULL default '',
position varchar(10) NOT NULL default '',
weight INT NOT NULL default 0,
visible INT NOT NULL default 0,
configdata text NOT NULL default 0
);");
}
//Finally, return result
return $result;
}

View File

@ -23,7 +23,16 @@ CREATE TABLE prefix_block_instance (
visible int not null default '0',
configdata text not null default ''
) ;
CREATE INDEX prefix_block_instance_pageid_idx ON prefix_block_instance (pageid);
CREATE TABLE prefix_block_pinned (
id SERIAL8 PRIMARY KEY,
blockid INT8 NOT NULL default 0,
pagetype varchar(20) NOT NULL default '',
position varchar(10) NOT NULL default '',
weight INT NOT NULL default 0,
visible INT NOT NULL default 0,
configdata text NOT NULL default 0
) ;
# --------------------------------------------------------

View File

@ -411,7 +411,8 @@ class block_base {
*/
function applicable_formats() {
// Default case: the block can be used in courses and site index, but not in activities
return array('all' => true, 'mod' => false);
require_once($GLOBALS['CFG']->dirroot.'/my/pagelib.php');
return array('all' => true, 'mod' => false, MY_MOODLE_FORMAT => true);
}
@ -529,10 +530,14 @@ class block_base {
* @return boolean
* @todo finish documenting this function
*/
function instance_config_save($data) {
function instance_config_save($data,$pinned=false) {
$data = stripslashes_recursive($data);
$this->config = $data;
return set_field('block_instance', 'configdata', base64_encode(serialize($data)), 'id', $this->instance->id);
$table = 'block_instance';
if (!empty($pinned)) {
$table = 'block_pinned';
}
return set_field($table, 'configdata', base64_encode(serialize($data)), 'id', $this->instance->id);
}
/**
@ -540,8 +545,12 @@ class block_base {
* @return boolean
* @todo finish documenting this function
*/
function instance_config_commit() {
return set_field('block_instance', 'configdata', base64_encode(serialize($this->config)), 'id', $this->instance->id);
function instance_config_commit($pinned=false) {
$table = 'block_instance';
if (!empty($pinned)) {
$table = 'block_pinned';
}
return set_field($table, 'configdata', base64_encode(serialize($this->config)), 'id', $this->instance->id);
}
/**

View File

@ -22,6 +22,9 @@ class block_news_items extends block_base {
}
if ($this->instance->pageid == 0) {
$this->instance->pageid = SITEID;
}
$course = get_record('course', 'id', $this->instance->pageid);
if ($course->newsitems) { // Create a nice listing of recent postings

View File

@ -23,6 +23,10 @@ class block_participants extends block_list {
$this->content->footer = '';
if (empty($this->instance->pageid)) {
$this->instance->pageid = SITEID;
}
if ($this->instance->pageid != SITEID ||
$CFG->showsiteparticipantslist > 1 ||
($CFG->showsiteparticipantslist == 1 && isteacherinanycourse()) ||
@ -37,6 +41,12 @@ class block_participants extends block_list {
return $this->content;
}
// my moodle can only have SITEID and it's redundant here, so take it away
function applicable_formats() {
require_once($GLOBALS['CFG']->dirroot.'/my/pagelib.php');
return array('all' => true, MY_MOODLE_FORMAT => false);
}
}
?>

View File

@ -1,5 +1,8 @@
<?PHP //$Id$
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once($CFG->dirroot.'/mod/forum/lib.php');
class block_search_forums extends block_base {
function init() {
$this->title = get_string('blocktitle', 'block_search_forums');
@ -34,6 +37,10 @@ class block_search_forums extends block_base {
return $this->content;
}
function applicable_formats() {
return array('site' => true, 'course' => true);
}
}
?>

View File

@ -1057,7 +1057,10 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU
// The first time we get in here, retrieve all groupmodes at once
if($groupmodes === NULL) {
$groupmodes = get_records_list('course', 'id', implode(',', $groupcourses), '', 'id, groupmode, groupmodeforce');
$count = count($groupcourses);
if ($count && ($count != 1 || !empty($count[0]))) {
$groupmodes = get_records_list('course', 'id', implode(',', $groupcourses), '', 'id, groupmode, groupmodeforce');
}
}
// If this course has groups, show events from all of them

View File

@ -648,6 +648,34 @@ function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
}
function print_overview($course) {
global $CFG, $USER;
if (!$lastaccess = get_record("user_teachers","userid",$USER->id,"course",$course->id)) {
if (!$lastaccess = get_record("user_students","userid",$USER->id,"course",$course->id)) {
return false;
}
}
$lastaccess = $lastaccess->timeaccess;
print_simple_box_start("center", '400', '', 5, "coursebox");
print_heading('<a title="'.$course->fullname.'" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->fullname.'</a>');
if ($mods = get_course_mods($course->id)) {
foreach ($mods as $mod) {
if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->modname.'/lib.php')) {
require_once(dirname(dirname(__FILE__)).'/mod/'.$mod->modname.'/lib.php');
$fname = $mod->modname.'_print_overview';
if (function_exists($fname)) {
$fname($course,$mod,$lastaccess);
}
}
}
}
print_simple_box_end();
}
function print_recent_activity($course) {
// $course is an object

View File

@ -113,6 +113,8 @@ $string['oldertopics'] = 'Older topics';
$string['openmode0'] = 'No discussions, no replies';
$string['openmode1'] = 'No discussions, but replies are allowed';
$string['openmode2'] = 'Discussions and replies are allowed';
$string['overviewnumpostssince'] = '$a posts since last login';
$string['overviewnumunread'] = '$a total unread';
$string['parent'] = 'Show parent';
$string['parentofthispost'] = 'Parent of this post';
$string['postadded'] = '<p>Your post was successfully added.</p>

View File

@ -53,6 +53,7 @@ $string['adminhelpmanageblocks'] = 'Manage installed blocks and their settings';
$string['adminhelpmanagedatabase'] = 'Access the database directly (be careful!)';
$string['adminhelpmanagefilters'] = 'Choose text filters and related settings';
$string['adminhelpmanagemodules'] = 'Manage installed modules and their settings';
$string['adminhelpmymoodle'] = 'Configure the my moodle blocks for users';
$string['adminhelpsitefiles'] = 'For publishing general files or uploading external backups';
$string['adminhelpsitesettings'] = 'Define how the front page of the site looks';
$string['adminhelpthemes'] = 'Choose how the site looks (colours, fonts etc)';
@ -1070,6 +1071,8 @@ $string['up'] = 'Up';
$string['update'] = 'Update';
$string['updated'] = 'Updated $a';
$string['updatemyprofile'] = 'Update profile';
$string['updatemymoodleon'] = 'Edit this page';
$string['updatemymoodleoff'] = 'Normal mode';
$string['updatesevery'] = 'Updates every $a seconds';
$string['updatethis'] = 'Update this $a';
$string['updatethiscourse'] = 'Update this course';

9
lang/en/my.php Normal file
View File

@ -0,0 +1,9 @@
<?PHP // $Id$
// moodle.php - created with Moodle 1.5 UNSTABLE DEVELOPMENT (2005010100)
$string['mymoodle'] = 'My moodle';
$string['nocourses'] = 'No course information to show.';
$string['pinblocks'] = 'Configure pinned blocks for my moodle';
$string['pinblocksexplan'] = 'Any block settings you configure here will be visible (and non-editable) for any user of moodle on their \'my moodle\' screen.';
?>

View File

@ -180,7 +180,7 @@ function blocks_name_allowed_in_format($name, $pageformat) {
return $accept;
}
function blocks_delete_instance($instance) {
function blocks_delete_instance($instance,$pinned=false) {
global $CFG;
// Get the block object and call instance_delete() first
@ -193,13 +193,20 @@ function blocks_delete_instance($instance) {
// Return value ignored
$obj->instance_delete();
// Now kill the db record;
delete_records('block_instance', 'id', $instance->id);
// And now, decrement the weight of all blocks after this one
execute_sql('UPDATE '.$CFG->prefix.'block_instance SET weight = weight - 1 WHERE pagetype = \''.$instance->pagetype.
'\' AND pageid = '.$instance->pageid.' AND position = \''.$instance->position.
'\' AND weight > '.$instance->weight, false);
if (!empty($pinned)) {
delete_records('block_pinned', 'id', $instance->id);
// And now, decrement the weight of all blocks after this one
execute_sql('UPDATE '.$CFG->prefix.'block_pinned SET weight = weight - 1 WHERE pagetype = \''.$instance->pagetype.
'\' AND position = \''.$instance->position.
'\' AND weight > '.$instance->weight, false);
} else {
// Now kill the db record;
delete_records('block_instance', 'id', $instance->id);
// And now, decrement the weight of all blocks after this one
execute_sql('UPDATE '.$CFG->prefix.'block_instance SET weight = weight - 1 WHERE pagetype = \''.$instance->pagetype.
'\' AND pageid = '.$instance->pageid.' AND position = \''.$instance->position.
'\' AND weight > '.$instance->weight, false);
}
return true;
}
@ -207,6 +214,10 @@ function blocks_delete_instance($instance) {
// (causing them to calculate their content in the process). Returns true or false. Parameter passed
// by reference for speed; the array is actually not modified.
function blocks_have_content(&$pageblocks, $position) {
if (empty($pageblocks) || !is_array($pageblocks) || !array_key_exists($position,$pageblocks)) {
return false;
}
foreach($pageblocks[$position] as $instance) {
if(!$instance->visible) {
continue;
@ -251,7 +262,11 @@ function blocks_print_group(&$page, &$pageblocks, $position) {
continue;
}
if ($isediting) {
if (method_exists($page,'edit_always')) {
$editalways = $page->edit_always();
}
if (($isediting && empty($instance->pinned)) || !empty($editalways)) {
$options = 0;
// The block can be moved up if it's NOT the first one in its position. If it is, we look at the OR clause:
// the first block might still be able to move up if the page says so (i.e., it will change position)
@ -295,6 +310,12 @@ function blocks_preferred_width(&$instances) {
$blocks = blocks_get_record();
foreach ($instances as $instance) {
if (!empty($instance->pinned)) {
$maxweight--;
}
}
foreach($instances as $instance) {
if(!$instance->visible) {
continue;
@ -329,7 +350,13 @@ function blocks_get_record($blockid = NULL, $invalidate = false) {
}
function blocks_find_block($blockid, $blocksarray) {
if (empty($blocksarray)) {
return false;
}
foreach($blocksarray as $blockgroup) {
if (empty($blockgroup)) {
continue;
}
foreach($blockgroup as $instance) {
if($instance->blockid == $blockid) {
return $instance;
@ -357,7 +384,7 @@ function blocks_setup(&$PAGE) {
return $pageblocks;
}
function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) {
function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid, $pinned=false) {
global $CFG;
if (is_int($instanceorid)) {
@ -399,7 +426,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid)
foreach($remove as $item) {
unset($data->$item);
}
if(!$blockobject->instance_config_save($data)) {
if(!$blockobject->instance_config_save($data,$pinned)) {
error('Error saving block configuration');
}
// And nothing more, continue with displaying the page
@ -426,13 +453,17 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid)
error('Invalid block instance for '.$blockaction);
}
$instance->visible = ($instance->visible) ? 0 : 1;
update_record('block_instance', $instance);
if (!empty($pinned)) {
update_record('block_pinned', $instance);
} else {
update_record('block_instance', $instance);
}
break;
case 'delete':
if(empty($instance)) {
error('Invalid block instance for '. $blockaction);
}
blocks_delete_instance($instance);
blocks_delete_instance($instance, $pinned);
break;
case 'moveup':
if(empty($instance)) {
@ -445,7 +476,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid)
$newpos = $page->blocks_move_position($instance, BLOCK_MOVE_UP);
$newweight = (empty($pageblocks[$newpos]) ? 0 : max(array_keys($pageblocks[$newpos])) + 1);
blocks_execute_repositioning($instance, $newpos, $newweight);
blocks_execute_repositioning($instance, $newpos, $newweight, $pinned);
}
else {
// The block is just moving upwards in the same position.
@ -457,10 +488,18 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid)
}
if(!empty($other)) {
++$other->weight;
update_record('block_instance', $other);
if (!empty($pinned)) {
update_record('block_pinned', $other);
} else {
update_record('block_instance', $other);
}
}
--$instance->weight;
update_record('block_instance', $instance);
if (!empty($pinned)) {
update_record('block_pinned', $instance);
} else {
update_record('block_instance', $instance);
}
}
break;
case 'movedown':
@ -474,7 +513,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid)
$newpos = $page->blocks_move_position($instance, BLOCK_MOVE_DOWN);
$newweight = (empty($pageblocks[$newpos]) ? 0 : max(array_keys($pageblocks[$newpos])) + 1);
blocks_execute_repositioning($instance, $newpos, $newweight);
blocks_execute_repositioning($instance, $newpos, $newweight, $pinned);
}
else {
// The block is just moving downwards in the same position.
@ -486,10 +525,18 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid)
}
if(!empty($other)) {
--$other->weight;
update_record('block_instance', $other);
if (!empty($pinned)) {
update_record('block_pinned', $other);
} else {
update_record('block_instance', $other);
}
}
++$instance->weight;
update_record('block_instance', $instance);
if (!empty($pinned)) {
update_record('block_pinned', $instance);
} else {
update_record('block_instance', $instance);
}
}
break;
case 'moveleft':
@ -501,7 +548,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid)
$newpos = $page->blocks_move_position($instance, BLOCK_MOVE_LEFT);
$newweight = (empty($pageblocks[$newpos]) ? 0 : max(array_keys($pageblocks[$newpos])) + 1);
blocks_execute_repositioning($instance, $newpos, $newweight);
blocks_execute_repositioning($instance, $newpos, $newweight, $pinned);
break;
case 'moveright':
if(empty($instance)) {
@ -512,7 +559,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid)
$newpos = $page->blocks_move_position($instance, BLOCK_MOVE_RIGHT);
$newweight = (empty($pageblocks[$newpos]) ? 0 : max(array_keys($pageblocks[$newpos])) + 1);
blocks_execute_repositioning($instance, $newpos, $newweight);
blocks_execute_repositioning($instance, $newpos, $newweight, $pinned);
break;
case 'add':
// Add a new instance of this block, if allowed
@ -529,17 +576,30 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid)
}
$newpos = $page->blocks_default_position();
$weight = get_record_sql('SELECT 1, max(weight) + 1 AS nextfree FROM '. $CFG->prefix .'block_instance WHERE pageid = '. $page->get_id() .' AND pagetype = \''. $page->get_type() .'\' AND position = \''. $newpos .'\'');
if (!empty($pinned)) {
$sql = 'SELECT 1, max(weight) + 1 AS nextfree FROM '. $CFG->prefix .'block_pinned WHERE '
.' pagetype = \''. $page->get_type() .'\' AND position = \''. $newpos .'\'';
} else {
$sql = 'SELECT 1, max(weight) + 1 AS nextfree FROM '. $CFG->prefix .'block_instance WHERE pageid = '. $page->get_id()
.' AND pagetype = \''. $page->get_type() .'\' AND position = \''. $newpos .'\'';
}
$weight = get_record_sql($sql);
$newinstance = new stdClass;
$newinstance->blockid = $blockid;
$newinstance->pageid = $page->get_id();
if (empty($pinned)) {
$newinstance->pageid = $page->get_id();
}
$newinstance->pagetype = $page->get_type();
$newinstance->position = $newpos;
$newinstance->weight = empty($weight->nextfree) ? 0 : $weight->nextfree;
$newinstance->visible = 1;
$newinstance->configdata = '';
$newinstance->id = insert_record('block_instance', $newinstance);
if (!empty($pinned)) {
$newinstance->id = insert_record('block_pinned', $newinstance);
} else {
$newinstance->id = insert_record('block_instance', $newinstance);
}
// If the new instance was created, allow it to do additional setup
if($newinstance && ($obj = block_instance($block->name, $newinstance))) {
@ -555,7 +615,7 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid)
}
// You can use this to get the blocks to respond to URL actions without much hassle
function blocks_execute_url_action(&$PAGE, &$pageblocks) {
function blocks_execute_url_action(&$PAGE, &$pageblocks,$pinned=false) {
$blockaction = optional_param('blockaction');
if (empty($blockaction) || !$PAGE->user_allowed_editing() || !confirm_sesskey()) {
@ -566,18 +626,18 @@ function blocks_execute_url_action(&$PAGE, &$pageblocks) {
$blockid = optional_param('blockid', 0, PARAM_INT);
if (!empty($blockid)) {
blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $blockid);
blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $blockid, $pinned);
}
else if (!empty($instanceid)) {
$instance = blocks_find_instance($instanceid, $pageblocks);
blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance, $pinned);
}
}
// This shouldn't be used externally at all, it's here for use by blocks_execute_action()
// in order to reduce code repetition.
function blocks_execute_repositioning(&$instance, $newpos, $newweight) {
function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=false) {
global $CFG;
// If it's staying where it is, don't do anything
@ -586,15 +646,82 @@ function blocks_execute_repositioning(&$instance, $newpos, $newweight) {
}
// Close the weight gap we 'll leave behind
execute_sql('UPDATE '. $CFG->prefix .'block_instance SET weight = weight - 1 WHERE pagetype = \''. $instance->pagetype.
if (!empty($pinned)) {
$sql = 'UPDATE '. $CFG->prefix .'block_instance SET weight = weight - 1 WHERE pagetype = \''. $instance->pagetype.
'\' AND position = \'' .$instance->position.
'\' AND weight > '. $instance->weight;
} else {
$sql = 'UPDATE '. $CFG->prefix .'block_instance SET weight = weight - 1 WHERE pagetype = \''. $instance->pagetype.
'\' AND pageid = '. $instance->pageid .' AND position = \'' .$instance->position.
'\' AND weight > '. $instance->weight,
false);
'\' AND weight > '. $instance->weight;
}
execute_sql($sql,false);
$instance->position = $newpos;
$instance->weight = $newweight;
update_record('block_instance', $instance);
if (!empty($pinned)) {
update_record('block_pinned', $instance);
} else {
update_record('block_instance', $instance);
}
}
function blocks_get_pinned($page) {
$visible = true;
if (method_exists($page,'edit_always')) {
if ($page->edit_always()) {
$visible = false;
}
}
$blocks = get_records_select('block_pinned', 'pagetype = \''. $page->get_type() .'\''.(($visible) ? 'AND visible = 1' : ''), 'position, weight');
$positions = $page->blocks_get_positions();
$arr = array();
foreach($positions as $key => $position) {
$arr[$position] = array();
}
if(empty($blocks)) {
return $arr;
}
foreach($blocks as $block) {
$block->pinned = true; // so we know we can't move it.
$arr[$block->position][$block->weight] = $block;
}
return $arr;
}
function blocks_get_by_page_pinned($page) {
$pinned = blocks_get_pinned($page);
$user = blocks_get_by_page($page);
$weights = array();
foreach ($pinned as $pos => $arr) {
$weights[$pos] = count($arr);
}
foreach ($user as $pos => $blocks) {
if (!array_key_exists($pos,$pinned)) {
$pinned[$pos] = array();
}
if (!array_key_exists($pos,$weights)) {
$weights[$pos] = 0;
}
foreach ($blocks as $block) {
$pinned[$pos][$weights[$pos]] = $block;
$weights[$pos]++;
}
}
return $pinned;
}
function blocks_get_by_page($page) {

View File

@ -2246,14 +2246,15 @@ function user_login_string($course=NULL, $user=NULL) {
* @param string $navigation The breadcrumbs string to be printed
*/
function print_navigation ($navigation) {
global $CFG;
global $CFG, $USER;
if ($navigation) {
if (! $site = get_site()) {
$site->shortname = get_string('home');
}
$navigation = str_replace('->', '&raquo;', $navigation);
echo '<a target="'. $CFG->framename .'" href="'. $CFG->wwwroot .'/">'. $site->shortname .'</a> &raquo; '. $navigation;
echo '<a target="'. $CFG->framename .'" href="'. $CFG->wwwroot.((!isadmin() && !empty($USER->id)) ? '/my' : '') .'/">'. $site->shortname .'</a> &raquo; '. $navigation;
}
}
@ -3100,6 +3101,31 @@ function update_studentview_button($courseid) {
}
}
/**
* Returns a turn edit on/off button for course in a self contained form.
* Used to be an icon, but it's now a simple form button
*
* @uses $CFG
* @uses $USER
* @param int $courseid The course to update by id as found in 'course' table
* @return string
*/
function update_mymoodle_icon() {
global $CFG, $USER;
if (!empty($USER->editing)) {
$string = get_string('updatemymoodleoff');
$edit = 'off';
} else {
$string = get_string('updatemymoodleon');
$edit = 'on';
}
return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/my/index.php\">".
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
"<input type=\"submit\" value=\"$string\" /></form>";
}
/**
* Prints the editing button on a module "view" page
*

View File

@ -148,7 +148,10 @@
unset($SESSION->wantsurl);
} else {
$urltogo = $CFG->wwwroot.'/'; /// Go to the standard home page
$urltogo = $CFG->wwwroot.'/my'; /// Go to the standard home page
if (isadmin()) {
$urltogo = $CFG->wwwroot; /// not needed by admins.
}
unset($SESSION->wantsurl); /// Just in case
}
@ -188,7 +191,10 @@
/// First, let's remember where the user was trying to get to before they got here
if (empty($SESSION->wantsurl)) {
$SESSION->wantsurl = array_key_exists('HTTP_REFERER',$_SERVER) ? $_SERVER["HTTP_REFERER"] : $CFG->wwwroot;
$SESSION->wantsurl = (array_key_exists('HTTP_REFERER',$_SERVER) &&
$_SERVER["HTTP_REFERER"] != $CFG->wwwroot &&
$_SERVER["HTTP_REFERER"] != $CFG->wwwroot.'/')
? $_SERVER["HTTP_REFERER"] : NULL;
}
if (!empty($loginurl)) { // We don't want the standard forms, go elsewhere

View File

@ -734,6 +734,33 @@ function forum_user_complete($course, $user, $mod, $forum) {
}
}
function forum_print_overview($course, $cm,$lastaccess) {
global $USER, $CFG;
$forum = get_record("forum","id","$cm->instance");
$str = '<a title="'.get_string('forums').'" href="mod/forum/view.php?id='.$cm->id.'">'
.get_string('forum','forum').': '.$forum->name.'</a><br />';
if ($numnew = count_records_select("log","time > $lastaccess AND "
." course = $course->id AND "
." module = 'forum' AND cmid = $cm->id "
." AND action LIKE 'add %' AND userid != $USER->id")) {
$str .= get_string('overviewnumpostssince','forum',$numnew)."<br />";
$p = 1;
}
if ($CFG->forum_trackreadposts) {
$groupid = ($groupmode==SEPARATEGROUPS && !isteacheredit($course->id)) ? $currentgroup : false;
$unread = forum_tp_count_forum_posts($forum->id, $groupid) -
forum_tp_count_forum_read_records($USER->id, $forum->id, $groupid);
if ($unread > 0) {
$a->unread = $unread;
$str .= get_string('overviewnumunread','forum',$unread).'<br />';
$p = 1;
}
}
if (!empty($p)) {
echo $str;
}
}
function forum_print_recent_activity($course, $isteacher, $timestart) {
/// Given a course and a date, prints a summary of all the new
/// messages posted in the course since that date

67
my/index.php Normal file
View File

@ -0,0 +1,67 @@
<?php
// this is the 'my moodle' page
require_once('../config.php');
require_once($CFG->libdir.'/blocklib.php');
require_once('pagelib.php');
require_login();
$edit = optional_param('edit', '');
$blockaction = optional_param('blockaction');
$PAGE = page_create_instance($USER->id);
$pageblocks = blocks_get_by_page_pinned($PAGE);
if (!empty($blockaction)) {
blocks_execute_url_action($PAGE, $pageblocks);
// This re-query could be eliminated by judicious programming in blocks_execute_action(),
// but I 'm not sure if it's worth the complexity increase...
$pageblocks = blocks_get_by_page_pinned($PAGE);
}
if (!empty($edit) && $PAGE->user_allowed_editing()) {
if ($edit == 'on') {
$USER->editing = true;
} else if ($edit == 'off') {
$USER->editing = false;
}
}
$PAGE->print_header(get_string('mymoodle','my'));
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($pageblocks[BLOCK_POS_LEFT]), 210);
if(blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $PAGE->user_is_editing()) {
echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="left-column">';
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
echo '</td>';
}
echo '<td valign="top" width="*" id="middle-column">';
include('overview.php');
echo '</td>';
$blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), 210);
if(blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $PAGE->user_is_editing()) {
echo '<td style="vertical-align: top; width: '.$blocks_preferred_width.'px;" id="right-column">';
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
echo '</td>';
}
/// Finish the page
echo '</tr></table>';
print_footer();
?>

23
my/overview.php Normal file
View File

@ -0,0 +1,23 @@
<?php
require_once(dirname(dirname(__FILE__)).'/config.php');
require_once(dirname(dirname(__FILE__)).'/course/lib.php');
require_login();
$courses = get_my_courses($USER->id);
$site = get_site();
if (array_key_exists($site->id,$courses)) {
unset($courses[$site->id]);
}
if (empty($courses)) {
print_simple_box(get_string('nocourses','my'),'center');
}
else {
foreach ($courses as $course) {
print_overview($course);
}
}
?>

89
my/pagelib.php Normal file
View File

@ -0,0 +1,89 @@
<?php
global $CFG;
require_once($CFG->libdir.'/pagelib.php');
class page_my_moodle extends page_base {
function get_type() {
return PAGE_MY_MOODLE;
}
function user_allowed_editing() {
page_id_and_class($id,$class);
if (isadmin() && $id == PAGE_ADMIN_MY_MOODLE) {
return true;
} elseif ($id == PAGE_MY_MOODLE) {
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) {
return true;
}
return (!empty($USER->editing));
}
function print_header($title) {
global $USER;
$site = get_site();
$button = update_mymoodle_icon($USER->id);
$header = get_string('mymoodle','my');
$nav = $header;
$loggedinas = '<p class="logininfo">'. user_login_string($site) .'</p>';
print_header($title, $header,$nav,'','',true, $button, $loggedinas);
}
function url_get_path() {
page_id_and_class($id,$class);
if ($id == PAGE_ADMIN_MY_MOODLE) {
return $GLOBALS['CFG']->wwwroot.'/admin/mymoodle.php';
}
return $GLOBALS['CFG']->wwwroot.'/my/index.php';
}
function blocks_default_position() {
return BLOCK_POS_LEFT;
}
function blocks_move_position(&$instance, $move) {
if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
return BLOCK_POS_RIGHT;
} else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
return BLOCK_POS_LEFT;
}
return $instance->position;
}
function get_format_name() {
return MY_MOODLE_FORMAT;
}
}
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');
?>