Skip to content
Permalink
Browse files

MDL-45898 myprofile: Redesign my profile page

Part of MDL-45774.

Contributions by John Okely, Jetha Chan and Damyon Wiese (squashed branch).

AMOS BEGIN
CPY [coursebadges,core_badges], [badges,core_badges]
AMOS END
  • Loading branch information...
ankitagarwal authored and abgreeve committed Apr 7, 2015
1 parent 479fa47 commit b19cc4ef25740cc7aae543f9ca85b7263274a47a
@@ -0,0 +1,82 @@
<?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/>.
/**
* Defines various library functions.
*
* @package core_badges
* @copyright 2015 onwards Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Add nodes to myprofile page.
*
* @param \core_user\output\myprofile\tree $tree Tree object
* @param stdClass $user user object
* @param bool $iscurrentuser
* @param stdClass $course Course object
*
* @return bool
*/
function core_badges_myprofile_navigation(\core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
global $CFG, $PAGE, $USER, $SITE;
require_once($CFG->dirroot . '/badges/renderer.php');
if (empty($CFG->enablebadges) || (!empty($course) || empty($CFG->badges_allowcoursebadges))) {
// Y U NO LIKE BADGES ?
return true;
}
$category = new core_user\output\myprofile\category('badges', get_string('badges', 'badges'), null);
$url = new moodle_url("/badges/mybadges.php");
// Add category.
$tree->add_category($category);
// Determine context.
if (isloggedin()) {
$context = context_user::instance($USER->id);
} else {
$context = context_system::instance();
}
$courseid = empty($course) ? 0 : $course->id;
if ($USER->id == $user->id || has_capability('moodle/badges:viewotherbadges', $context)) {
$records = badges_get_user_badges($user->id, $courseid, null, null, null, true);
$renderer = new core_badges_renderer($PAGE, '');
// Local badges.
if ($records) {
$title = get_string('localbadgesp', 'badges', format_string($SITE->fullname));
$content = $renderer->print_badges_list($records, $user->id, true);
$localnode = $mybadges = new core_user\output\myprofile\node('badges', 'localbadges', $title, null, null, $content);
$tree->add_node($localnode);
}
// External badges.
if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack)) {
$backpack = get_backpack_settings($user->id);
if (isset($backpack->totalbadges) && $backpack->totalbadges !== 0) {
$title = get_string('externalbadgesp', 'badges');
$content = $renderer->print_badges_list($backpack->badges, $user->id, true, true);
$externalnode = $mybadges = new core_user\output\myprofile\node('badges', 'externalbadges', $title, null, null,
$content);
$tree->add_node($externalnode);
}
}
}
}
@@ -1013,3 +1013,31 @@ function blog_page_type_list($pagetype, $parentcontext, $currentcontext) {
'blog-edit'=>get_string('page-blog-edit', 'blog')
);
}
/**
* Add nodes to myprofile page.
*
* @param \core_user\output\myprofile\tree $tree Tree object
* @param stdClass $user user object
* @param bool $iscurrentuser
* @param stdClass $course Course object
*
* @return bool
*/
function core_blog_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
if (!blog_is_enabled_for_user() || isguestuser($user)) {
// The guest user cannot post, so it is not possible to view any posts.
// Also blogs might be disabled.
// May as well just bail aggressively here.
return true;
}
$url = new moodle_url("/blog/index.php", array('userid' => $user->id));
if ($iscurrentuser) {
$title = get_string('myprofilemyblogs', 'core_blog');
} else {
$title = get_string('myprofileuserblogs', 'core_blog', fullname($user));
}
$blognode = new core_user\output\myprofile\node('miscellaneous', 'blogs', $title, null, $url);
$tree->add_node($blognode);
return true;
}
@@ -94,6 +94,7 @@
$string['backpackimport_help'] = 'After backpack connection is successfully established, badges from your backpack can be displayed on your "My Badges" page and your profile page.
In this area, you can select collections of badges from your backpack that you would like to display in your profile.';
$string['badges'] = 'Badges';
$string['badgedetails'] = 'Badge details';
$string['badgeimage'] = 'Image';
$string['badgeimage_help'] = 'This is an image that will be used when this badge is issued.
@@ -108,6 +108,8 @@
$string['invalidurl'] = 'This URL is unreachable';
$string['linktooriginalentry'] = 'Link to original blog entry';
$string['maxexternalblogsperuser'] = 'Maximum number of external blogs per user';
$string['myprofilemyblogs'] = 'My blog entries';
$string['myprofileuserblogs'] = 'View all blog entries by {$a}';
$string['name'] = 'Name';
$string['name_help'] = 'Enter a descriptive name for your external blog. (If no name is supplied, the title of your external blog will be used).';
$string['noentriesyet'] = 'No visible entries here';
@@ -192,7 +192,8 @@
$string['remotecourses'] = 'Remote courses';
$string['remotehost'] = 'Remote host';
$string['remotehosts'] = 'Remote hosts';
$string['remoteuserinfo'] = 'Remote {$a->remotetype} user - profile fetched from <a href="{$a->remoteurl}">{$a->remotename}</a>';
$string['remoteuser'] = 'Remote {$a->remotetype} user';
$string['remoteuserinfo'] = 'Profile fetched from <a href="{$a->remoteurl}">{$a->remotename}</a>';
$string['requiresopenssl'] = 'Networking requires the OpenSSL extension';
$string['restore'] = 'Restore';
$string['returnvalue'] = 'Return value';
@@ -317,6 +317,7 @@
$string['coursecompletions'] = 'Course completions';
$string['coursecreators'] = 'Course creator';
$string['coursecreatorsdescription'] = 'Course creators can create new courses.';
$string['coursedetails'] = 'Course details';
$string['coursedisplay'] = 'Course layout';
$string['coursedisplay_help'] = 'This setting determines whether the whole course is displayed on one page or split over several pages.';
$string['coursedisplay_single'] = 'Show all sections on one page';
@@ -331,6 +332,7 @@
$string['courseformats'] = 'Course formats';
$string['courseformatoptions'] = 'Formatting options for {$a}';
$string['courseformatudpate'] = 'Update format';
$string['courseprofiles'] = 'Course profiles';
$string['coursegrades'] = 'Course grades';
$string['coursehelpcategory'] = 'Position the course on the course listing and may make it easier for students to find it.';
$string['coursehelpforce'] = 'Force the course group mode to every activity in the course.';
@@ -356,7 +358,6 @@
$string['courselegacyfilesofcourse'] = 'Legacy course files: {$a}';
$string['courseoverview'] = 'Course overview';
$string['courseoverviewgraph'] = 'Course overview graph';
$string['courseprofiles'] = 'Course profiles';
$string['coursereasonforrejecting'] = 'Your reasons for rejecting this request';
$string['coursereasonforrejectingemail'] = 'This will be emailed to the requester';
$string['coursereject'] = 'Reject a course request';
@@ -1905,6 +1906,7 @@
$string['uploadthisfile'] = 'Upload this file';
$string['url'] = 'URL';
$string['used'] = 'Used';
$string['userdetails'] = 'User details';
$string['usedinnplaces'] = 'Used in {$a} places';
$string['usemessageform'] = 'or use the form below to send a message to the selected students';
$string['user'] = 'User';
@@ -1929,6 +1931,7 @@
$string['usernotconfirmed'] = 'Could not confirm {$a}';
$string['userpic'] = 'User picture';
$string['users'] = 'Users';
$string['userspreferences'] = 'User {$a}\'s preferences';
$string['userselectorautoselectunique'] = 'If only one user matches the search, select them automatically';
$string['userselectorpreserveselected'] = 'Keep selected users, even if they no longer match the search';
$string['userselectorsearchanywhere'] = 'Match the search text anywhere in the displayed fields';
@@ -43,6 +43,8 @@
$string['groupaddnewnote'] = 'Add a common note';
$string['invalidid'] = 'Invalid note ID specified';
$string['invaliduserid'] = 'Invalid user id: {$a}';
$string['myprofileownnotes'] = 'My notes';
$string['myprofileothernotes'] = 'Notes by {$a}';
$string['nocontent'] = 'Note content can not be empty';
$string['nonotes'] = 'There are no notes of this type yet';
$string['nopermissiontodelete'] = 'You may not delete this note';
@@ -1140,48 +1140,6 @@ function badges_download($userid) {
}
}
/**
* Print badges on user profile page.
*
* @param int $userid User ID.
* @param int $courseid Course if we need to filter badges (optional).
*/
function profile_display_badges($userid, $courseid = 0) {
global $CFG, $PAGE, $USER, $SITE;
require_once($CFG->dirroot . '/badges/renderer.php');
// Determine context.
if (isloggedin()) {
$context = context_user::instance($USER->id);
} else {
$context = context_system::instance();
}
if ($USER->id == $userid || has_capability('moodle/badges:viewotherbadges', $context)) {
$records = badges_get_user_badges($userid, $courseid, null, null, null, true);
$renderer = new core_badges_renderer($PAGE, '');
// Print local badges.
if ($records) {
$left = get_string('localbadgesp', 'badges', format_string($SITE->fullname));
$right = $renderer->print_badges_list($records, $userid, true);
echo html_writer::tag('dt', $left);
echo html_writer::tag('dd', $right);
}
// Print external badges.
if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack)) {
$backpack = get_backpack_settings($userid);
if (isset($backpack->totalbadges) && $backpack->totalbadges !== 0) {
$left = get_string('externalbadgesp', 'badges');
$right = $renderer->print_badges_list($backpack->badges, $userid, true, true);
echo html_writer::tag('dt', $left);
echo html_writer::tag('dd', $right);
}
}
}
}
/**
* Checks if badges can be pushed to external backpack.
*
@@ -4220,3 +4220,48 @@ function message_current_user_is_involved($user1, $user2) {
}
return true;
}
/**
* Print badges on user profile page.
*
* @deprecated since Moodle 2.9 MDL-45898 - please do not use this function any more.
* @param int $userid User ID.
* @param int $courseid Course if we need to filter badges (optional).
*/
function profile_display_badges($userid, $courseid = 0) {
global $CFG, $PAGE, $USER, $SITE;
require_once($CFG->dirroot . '/badges/renderer.php');
debugging('profile_display_badges() is deprecated.', DEBUG_DEVELOPER);
// Determine context.
if (isloggedin()) {
$context = context_user::instance($USER->id);
} else {
$context = context_system::instance();
}
if ($USER->id == $userid || has_capability('moodle/badges:viewotherbadges', $context)) {
$records = badges_get_user_badges($userid, $courseid, null, null, null, true);
$renderer = new core_badges_renderer($PAGE, '');
// Print local badges.
if ($records) {
$left = get_string('localbadgesp', 'badges', format_string($SITE->fullname));
$right = $renderer->print_badges_list($records, $userid, true);
echo html_writer::tag('dt', $left);
echo html_writer::tag('dd', $right);
}
// Print external badges.
if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack)) {
$backpack = get_backpack_settings($userid);
if (isset($backpack->totalbadges) && $backpack->totalbadges !== 0) {
$left = get_string('externalbadgesp', 'badges');
$right = $renderer->print_badges_list($backpack->badges, $userid, true, true);
echo html_writer::tag('dt', $left);
echo html_writer::tag('dd', $right);
}
}
}
}

0 comments on commit b19cc4e

Please sign in to comment.
You can’t perform that action at this time.