Skip to content

Commit

Permalink
My Moodle MDL-19124 New version of My Moodle, User profiles and Cours…
Browse files Browse the repository at this point in the history
…e profiles, all with block support

Thanks very much to Remote Learner Canada, especially Hubert Chathi and Olav Jordan, for their work on the bulk of this code, and also Mike Churchward for supporting them.  I worked on it after that (actually simplified it by removing a feature temporarily: multiple pages) to bring it more to what I was imagining, and to provide a base to build on and get all the navigation perfect.

There's still work to do.  Some blocks don't quite work as expected, and some of the code still needs upgrading to bring it fully into line with 2.0.  We also could use a much better course overview block and better CSS styling of the profile pages.  But it's definitely more usable this it was, I think.
  • Loading branch information
moodler committed May 4, 2010
1 parent 1b80c91 commit 03d9401
Show file tree
Hide file tree
Showing 36 changed files with 1,820 additions and 395 deletions.
2 changes: 1 addition & 1 deletion admin/registration/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('registeron', 'hub'), 3, 'main');
echo $renderer->registrationselector();
echo $OUTPUT->footer();
echo $OUTPUT->footer();
8 changes: 5 additions & 3 deletions admin/settings/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
}
}


// calendar
$temp = new admin_settingpage('calendar', get_string('calendarsettings','admin'));
$temp->add(new admin_setting_special_adminseesall());
Expand Down Expand Up @@ -123,9 +124,10 @@
$temp->add(new admin_setting_configcheckbox('doctonewwindow', get_string('doctonewwindow', 'admin'), get_string('configdoctonewwindow', 'admin'), 0));
$ADMIN->add('appearance', $temp);

$temp = new admin_settingpage('mymoodle', get_string('mymoodle', 'admin'));
$temp->add(new admin_setting_configcheckbox('mymoodleredirect', get_string('mymoodleredirect', 'admin'), get_string('configmymoodleredirect', 'admin'), 0));
$temp->add(new admin_setting_configtext('mycoursesperpage', get_string('mycoursesperpage', 'admin'), get_string('configmycoursesperpage', 'admin'), 21, PARAM_INT));
$temp = new admin_externalpage('mypage', get_string('mypage', 'admin'), $CFG->wwwroot . '/my/indexsys.php');
$ADMIN->add('appearance', $temp);

$temp = new admin_externalpage('profilepage', get_string('myprofile', 'admin'), $CFG->wwwroot . '/user/profilesys.php');
$ADMIN->add('appearance', $temp);

// coursemanager is the person responsible for course - usually manages enrolments, receives notification, etc.
Expand Down
128 changes: 128 additions & 0 deletions blocks/course_overview/block_course_overview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Course overview block
*
* Currently, just a copy-and-paste from the old My Moodle.
*
* @package blocks
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once($CFG->dirroot.'/lib/weblib.php');
require_once($CFG->dirroot . '/lib/formslib.php');

class block_course_overview extends block_base {
/**
* block initializations
*/
public function init() {
$this->title = get_string('pluginname', 'block_course_overview');
$this->version = 2010021100;
}

/**
* block contents
*
* @return object
*/
public function get_content() {
global $USER;
if($this->content !== NULL) {
return $this->content;
}

$this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';

$content = array();

// limits the number of courses showing up
$courses_limit = 21;
// FIXME: this should be a block setting, rather than a global setting
if (isset($CFG->mycoursesperpage)) {
$courses_limit = $CFG->mycoursesperpage;
}

$morecourses = false;
if ($courses_limit > 0) {
$courses_limit = $courses_limit + 1;
}

$courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', '*', false, $courses_limit);
$site = get_site();
$course = $site; //just in case we need the old global $course hack

if (($courses_limit > 0) && (count($courses) >= $courses_limit)) {
//remove the 'marker' course that we retrieve just to see if we have more than $courses_limit
array_pop($courses);
$morecourses = true;
}


if (array_key_exists($site->id,$courses)) {
unset($courses[$site->id]);
}

foreach ($courses as $c) {
if (isset($USER->lastcourseaccess[$c->id])) {
$courses[$c->id]->lastaccess = $USER->lastcourseaccess[$c->id];
} else {
$courses[$c->id]->lastaccess = 0;
}
}

if (empty($courses)) {
$content[] = get_string('nocourses','my');
} else {
ob_start();
print_overview($courses);
$content[] = ob_get_contents();
ob_end_clean();
}

// if more than 20 courses
if ($morecourses) {
$content[] = '<br />...';
}

$this->content->text = implode($content);

return $this->content;
}

/**
* allow the block to have a configuration page
*
* @return boolean
*/
public function has_config() {
return false;
}

/**
* locations where block can be displayed
*
* @return array
*/
public function applicable_formats() {
return array('my-index'=>true);
}
}
?>
2 changes: 2 additions & 0 deletions blocks/course_overview/lang/en/block_course_overview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
$string['pluginname'] = 'Course overview';
31 changes: 29 additions & 2 deletions blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,21 @@ function instance_delete() {
* @return boolean
*/
function user_can_edit() {
return has_capability('moodle/block:edit', $this->context);
global $USER;

if (has_capability('moodle/block:edit', $this->context)) {
return true;
}

// The blocks in My Moodle are a special case. We want them to inherit from the user context.
if (!empty($USER->id)
&& $this->instance->parentcontextid == $this->page->context->id // Block belongs to this page
&& $this->page->context->contextlevel == CONTEXT_USER // Page belongs to a user
&& $this->page->context->instanceid == $USER->id) { // Page belongs to this user
return has_capability('moodle/my:manageblocks', $this->page->context);
}

return false;
}

/**
Expand All @@ -676,7 +690,20 @@ function user_can_edit() {
* @return boolean
*/
function user_can_addto($page) {
return has_capability('moodle/block:edit', $page->context);
global $USER;

if (has_capability('moodle/block:edit', $page->context)) {
return true;
}

// The blocks in My Moodle are a special case and use a different capability.
if (!empty($USER->id)
&& $page->context->contextlevel == CONTEXT_USER // Page belongs to a user
&& $page->context->instanceid == $USER->id) { // Page belongs to this user
return has_capability('moodle/my:manageblocks', $page->context);
}

return false;
}

function get_extra_capabilities() {
Expand Down
Loading

0 comments on commit 03d9401

Please sign in to comment.