mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-50851 user: use new tag API for interests
This commit is contained in:
parent
b355a1c97c
commit
c4e868d5f0
@ -1209,16 +1209,14 @@ abstract class restore_dbops {
|
||||
}
|
||||
|
||||
// Process tags
|
||||
if (!empty($CFG->usetags) && isset($user->tags)) { // if enabled in server and present in backup
|
||||
if (core_tag_tag::is_enabled('core', 'user') && isset($user->tags)) { // If enabled in server and present in backup.
|
||||
$tags = array();
|
||||
foreach($user->tags['tag'] as $usertag) {
|
||||
$usertag = (object)$usertag;
|
||||
$tags[] = $usertag->rawname;
|
||||
}
|
||||
if (empty($newuserctxid)) {
|
||||
$newuserctxid = null; // Tag apis expect a null contextid not 0.
|
||||
}
|
||||
tag_set('user', $newuserid, $tags, 'core', $newuserctxid);
|
||||
core_tag_tag::set_item_tags('core', 'user', $newuserid,
|
||||
context_user::instance($newuserid), $tags);
|
||||
}
|
||||
|
||||
// Process preferences
|
||||
|
@ -3901,7 +3901,6 @@ function delete_user(stdClass $user) {
|
||||
require_once($CFG->libdir.'/grouplib.php');
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
require_once($CFG->dirroot.'/message/lib.php');
|
||||
require_once($CFG->dirroot.'/tag/lib.php');
|
||||
require_once($CFG->dirroot.'/user/lib.php');
|
||||
|
||||
// Make sure nobody sends bogus record type as parameter.
|
||||
@ -3944,7 +3943,7 @@ function delete_user(stdClass $user) {
|
||||
// TODO: remove from cohorts using standard API here.
|
||||
|
||||
// Remove user tags.
|
||||
tag_set('user', $user->id, array(), 'core', $usercontext->id);
|
||||
core_tag_tag::remove_all_item_tags('core', 'user', $user->id);
|
||||
|
||||
// Unconditionally unenrol from all courses.
|
||||
enrol_user_delete($user);
|
||||
|
@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->dirroot . '/tag/lib.php');
|
||||
|
||||
/**
|
||||
* Defines core nodes for my profile navigation tree.
|
||||
@ -36,7 +35,7 @@ require_once($CFG->dirroot . '/tag/lib.php');
|
||||
* @return bool
|
||||
*/
|
||||
function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
|
||||
global $CFG, $USER, $DB, $PAGE;
|
||||
global $CFG, $USER, $DB, $PAGE, $OUTPUT;
|
||||
|
||||
$usercontext = context_user::instance($user->id, MUST_EXIST);
|
||||
$systemcontext = context_system::instance();
|
||||
@ -218,11 +217,10 @@ function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user,
|
||||
}
|
||||
|
||||
// Printing tagged interests. We want this only for full profile.
|
||||
if (!empty($CFG->usetags) && empty($course)) {
|
||||
if ($interests = tag_get_tags_csv('user', $user->id) ) {
|
||||
$node = new core_user\output\myprofile\node('contact', 'interests', get_string('interests'), null, null, $interests);
|
||||
$tree->add_node($node);
|
||||
}
|
||||
if (empty($course) && ($interests = core_tag_tag::get_item_tags('core', 'user', $user->id))) {
|
||||
$node = new core_user\output\myprofile\node('contact', 'interests', get_string('interests'), null, null,
|
||||
$OUTPUT->tag_list($interests, ''));
|
||||
$tree->add_node($node);
|
||||
}
|
||||
|
||||
if (!isset($hiddenfields['mycourses'])) {
|
||||
|
35
tag/user.php
35
tag/user.php
@ -4,8 +4,6 @@ require_once('../config.php');
|
||||
require_once('lib.php');
|
||||
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
$tag = optional_param('tag', '', PARAM_TAG);
|
||||
|
||||
require_login();
|
||||
|
||||
@ -25,32 +23,31 @@ $usercontext = context_user::instance($USER->id);
|
||||
|
||||
switch ($action) {
|
||||
case 'addinterest':
|
||||
if (empty($tag) && $id) { // for backward-compatibility (people saving bookmarks, mostly..)
|
||||
$tag = tag_get_name($id);
|
||||
if (!core_tag_tag::is_enabled('core', 'user')) {
|
||||
print_error('tagdisabled');
|
||||
}
|
||||
|
||||
tag_set_add('user', $USER->id, $tag, 'core', $usercontext->id);
|
||||
|
||||
redirect($CFG->wwwroot.'/tag/index.php?tag='. rawurlencode($tag));
|
||||
$tag = required_param('tag', PARAM_TAG);
|
||||
core_tag_tag::add_item_tag('core', 'user', $USER->id, $usercontext, $tag);
|
||||
$tc = core_tag_area::get_collection('core', 'user');
|
||||
redirect(core_tag_tag::make_url($tc, $tag));
|
||||
break;
|
||||
|
||||
case 'removeinterest':
|
||||
if (empty($tag) && $id) { // for backward-compatibility (people saving bookmarks, mostly..)
|
||||
$tag = tag_get_name($id);
|
||||
if (!core_tag_tag::is_enabled('core', 'user')) {
|
||||
print_error('tagdisabled');
|
||||
}
|
||||
|
||||
tag_set_delete('user', $USER->id, $tag, 'core', $usercontext->id);
|
||||
|
||||
redirect($CFG->wwwroot.'/tag/index.php?tag='. rawurlencode($tag));
|
||||
$tag = required_param('tag', PARAM_TAG);
|
||||
core_tag_tag::remove_item_tag('core', 'user', $USER->id, $tag);
|
||||
$tc = core_tag_area::get_collection('core', 'user');
|
||||
redirect(core_tag_tag::make_url($tc, $tag));
|
||||
break;
|
||||
|
||||
case 'flaginappropriate':
|
||||
require_capability('moodle/tag:flag', context_system::instance());
|
||||
$tagid = tag_get_id($tag);
|
||||
|
||||
tag_set_flag($tagid);
|
||||
|
||||
redirect($CFG->wwwroot.'/tag/index.php?tag='. rawurlencode($tag), get_string('responsiblewillbenotified', 'tag'));
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$tagobject = core_tag_tag::get($id, '*', MUST_EXIST);
|
||||
$tagobject->flag();
|
||||
redirect($tagobject->get_view_url(), get_string('responsiblewillbenotified', 'tag'));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -70,10 +70,7 @@ if (isguestuser($user)) {
|
||||
}
|
||||
|
||||
// User interests separated by commas.
|
||||
if (!empty($CFG->usetags)) {
|
||||
require_once($CFG->dirroot.'/tag/lib.php');
|
||||
$user->interests = tag_get_tags_array('user', $user->id);
|
||||
}
|
||||
$user->interests = core_tag_tag::get_item_tags_array('core', 'user', $user->id);
|
||||
|
||||
// Remote users cannot be edited.
|
||||
if (is_mnet_remote_user($user)) {
|
||||
@ -233,7 +230,7 @@ if ($usernew = $userform->get_data()) {
|
||||
useredit_update_user_preference($usernew);
|
||||
|
||||
// Update interests.
|
||||
if (!empty($CFG->usetags)) {
|
||||
if (isset($usernew->interests)) {
|
||||
useredit_update_interests($usernew, $usernew->interests);
|
||||
}
|
||||
|
||||
|
@ -116,10 +116,7 @@ useredit_load_preferences($user);
|
||||
profile_load_data($user);
|
||||
|
||||
// User interests.
|
||||
if (!empty($CFG->usetags)) {
|
||||
require_once($CFG->dirroot.'/tag/lib.php');
|
||||
$user->interests = tag_get_tags_array('user', $id);
|
||||
}
|
||||
$user->interests = core_tag_tag::get_item_tags_array('core', 'user', $id);
|
||||
|
||||
if ($user->id !== -1) {
|
||||
$usercontext = context_user::instance($user->id);
|
||||
@ -236,7 +233,7 @@ if ($usernew = $userform->get_data()) {
|
||||
useredit_update_user_preference($usernew);
|
||||
|
||||
// Update tags.
|
||||
if (!empty($CFG->usetags) and empty($USER->newadminuser)) {
|
||||
if (empty($USER->newadminuser) && isset($usernew->interests)) {
|
||||
useredit_update_interests($usernew, $usernew->interests);
|
||||
}
|
||||
|
||||
|
@ -264,9 +264,8 @@ function useredit_update_trackforums($user, $usernew) {
|
||||
* @param array $interests
|
||||
*/
|
||||
function useredit_update_interests($user, $interests) {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/tag/lib.php');
|
||||
tag_set('user', $user->id, $interests, 'core', context_user::instance($user->id)->id);
|
||||
core_tag_tag::set_item_tags('core', 'user', $user->id,
|
||||
context_user::instance($user->id), $interests);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -397,9 +396,10 @@ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($CFG->usetags) and empty($USER->newadminuser)) {
|
||||
if (core_tag_tag::is_enabled('core', 'user') and empty($USER->newadminuser)) {
|
||||
$mform->addElement('header', 'moodle_interests', get_string('interests'));
|
||||
$mform->addElement('tags', 'interests', get_string('interestslist'), array('display' => 'noofficial'));
|
||||
$mform->addElement('tags', 'interests', get_string('interestslist'),
|
||||
array('display' => 'noofficial', 'itemtype' => 'user', 'component' => 'core'));
|
||||
$mform->addHelpButton('interests', 'interestslist');
|
||||
}
|
||||
|
||||
|
46
user/lib.php
46
user/lib.php
@ -463,10 +463,10 @@ function user_get_user_details($user, $course = null, array $userfields = array(
|
||||
$userdetails['email'] = $user->email;
|
||||
}
|
||||
|
||||
if (in_array('interests', $userfields) && !empty($CFG->usetags)) {
|
||||
require_once($CFG->dirroot . '/tag/lib.php');
|
||||
if ($interests = tag_get_tags_csv('user', $user->id, TAG_RETURN_TEXT) ) {
|
||||
$userdetails['interests'] = $interests;
|
||||
if (in_array('interests', $userfields)) {
|
||||
$interests = core_tag_tag::get_item_tags_array('core', 'user', $user->id, null, 0, false);
|
||||
if ($interests) {
|
||||
$userdetails['interests'] = join(', ', $interests);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1134,3 +1134,41 @@ function user_can_view_profile($user, $course = null, $usercontext = null) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns users tagged with a specified tag.
|
||||
*
|
||||
* @param core_tag_tag $tag
|
||||
* @param bool $exclusivemode if set to true it means that no other entities tagged with this tag
|
||||
* are displayed on the page and the per-page limit may be bigger
|
||||
* @param int $fromctx context id where the link was displayed, may be used by callbacks
|
||||
* to display items in the same context first
|
||||
* @param int $ctx context id where to search for records
|
||||
* @param bool $rec search in subcontexts as well
|
||||
* @param int $page 0-based number of page being displayed
|
||||
* @return \core_tag\output\tagindex
|
||||
*/
|
||||
function user_get_tagged_users($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) {
|
||||
global $PAGE;
|
||||
|
||||
if ($ctx && $ctx != context_system::instance()->id) {
|
||||
$usercount = 0;
|
||||
} else {
|
||||
// Users can only be displayed in system context.
|
||||
$usercount = $tag->count_tagged_items('core', 'user',
|
||||
'it.deleted=:notdeleted', array('notdeleted' => 0));
|
||||
}
|
||||
$perpage = $exclusivemode ? 24 : 5;
|
||||
$content = '';
|
||||
$totalpages = ceil($usercount / $perpage);
|
||||
|
||||
if ($usercount) {
|
||||
$userlist = $tag->get_tagged_items('core', 'user', $page * $perpage, $perpage,
|
||||
'it.deleted=:notdeleted', array('notdeleted' => 0));
|
||||
$renderer = $PAGE->get_renderer('core', 'user');
|
||||
$content .= $renderer->user_list($userlist, $exclusivemode);
|
||||
}
|
||||
|
||||
return new core_tag\output\tagindex($tag, 'core', 'user', $content,
|
||||
$exclusivemode, $fromctx, $ctx, $rec, $page, $totalpages);
|
||||
}
|
||||
|
@ -34,7 +34,6 @@
|
||||
|
||||
require_once(dirname(__FILE__) . '/../config.php');
|
||||
require_once($CFG->dirroot . '/my/lib.php');
|
||||
require_once($CFG->dirroot . '/tag/lib.php');
|
||||
require_once($CFG->dirroot . '/user/profile/lib.php');
|
||||
require_once($CFG->dirroot . '/user/lib.php');
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
|
@ -164,6 +164,40 @@ class core_user_renderer extends plugin_renderer_base {
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the list of tagged users
|
||||
*
|
||||
* @param array $userlist
|
||||
* @param bool $exclusivemode if set to true it means that no other entities tagged with this tag
|
||||
* are displayed on the page and the per-page limit may be bigger
|
||||
* @return string
|
||||
*/
|
||||
public function user_list($userlist, $exclusivemode) {
|
||||
$tagfeed = new core_tag\output\tagfeed();
|
||||
foreach ($userlist as $user) {
|
||||
$userpicture = $this->output->user_picture($user, array('size' => $exclusivemode ? 100 : 35));
|
||||
$fullname = fullname($user);
|
||||
if (user_can_view_profile($user)) {
|
||||
$profilelink = new moodle_url('/user/view.php', array('id' => $user->id));
|
||||
$fullname = html_writer::link($profilelink, $fullname);
|
||||
}
|
||||
$tagfeed->add($userpicture, $fullname);
|
||||
}
|
||||
|
||||
$items = $tagfeed->export_for_template($this->output);
|
||||
|
||||
if ($exclusivemode) {
|
||||
$output = '<div><ul class="inline-list">';
|
||||
foreach ($items['items'] as $item) {
|
||||
$output .= '<li><div class="user-box">'. $item['img'] . $item['heading'] ."</div></li>\n";
|
||||
}
|
||||
$output .= "</ul></div>\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
return $this->output->render_from_template('core_tag/tagfeed', $items);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,6 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
|
||||
$user1 = self::getDataGenerator()->create_user($user1);
|
||||
set_config('usetags', 1);
|
||||
require_once($CFG->dirroot . '/user/editlib.php');
|
||||
require_once($CFG->dirroot . '/tag/lib.php');
|
||||
$user1->interests = array('Cinema', 'Tennis', 'Dance', 'Guitar', 'Cooking');
|
||||
useredit_update_interests($user1, $user1->interests);
|
||||
|
||||
@ -228,7 +227,6 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
|
||||
$user1 = self::getDataGenerator()->create_user($user1);
|
||||
if (!empty($CFG->usetags)) {
|
||||
require_once($CFG->dirroot . '/user/editlib.php');
|
||||
require_once($CFG->dirroot . '/tag/lib.php');
|
||||
$user1->interests = array('Cinema', 'Tennis', 'Dance', 'Guitar', 'Cooking');
|
||||
useredit_update_interests($user1, $user1->interests);
|
||||
}
|
||||
@ -390,7 +388,6 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
|
||||
$return->user1 = self::getDataGenerator()->create_user($return->user1);
|
||||
if (!empty($CFG->usetags)) {
|
||||
require_once($CFG->dirroot . '/user/editlib.php');
|
||||
require_once($CFG->dirroot . '/tag/lib.php');
|
||||
$return->user1->interests = array('Cinema', 'Tennis', 'Dance', 'Guitar', 'Cooking');
|
||||
useredit_update_interests($return->user1, $return->user1->interests);
|
||||
}
|
||||
@ -594,7 +591,6 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
|
||||
$user1 = self::getDataGenerator()->create_user($user1);
|
||||
if (!empty($CFG->usetags)) {
|
||||
require_once($CFG->dirroot . '/user/editlib.php');
|
||||
require_once($CFG->dirroot . '/tag/lib.php');
|
||||
$user1->interests = array('Cinema', 'Tennis', 'Dance', 'Guitar', 'Cooking');
|
||||
useredit_update_interests($user1, $user1->interests);
|
||||
}
|
||||
|
@ -25,7 +25,6 @@
|
||||
require_once("../config.php");
|
||||
require_once($CFG->dirroot.'/user/profile/lib.php');
|
||||
require_once($CFG->dirroot.'/user/lib.php');
|
||||
require_once($CFG->dirroot.'/tag/lib.php');
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
require_once($CFG->libdir . '/badgeslib.php');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user