Skip to content

Commit

Permalink
MDL-60029 core_user: new api functions rearranged
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Oct 10, 2017
1 parent 860f59b commit b47fda7
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 127 deletions.
5 changes: 1 addition & 4 deletions lib/myprofilelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,7 @@ function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user,

$categories = profile_get_user_fields_with_data_by_category($user->id);
foreach ($categories as $categoryid => $fields) {
foreach ($fields as $field) {
require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
$newfield = 'profile_field_'.$field->datatype;
$formfield = new $newfield($field->id, $user->id, $field);
foreach ($fields as $formfield) {
if ($formfield->is_visible() and !$formfield->is_empty()) {
$node = new core_user\output\myprofile\node('contact', 'custom_field_' . $formfield->field->shortname,
format_string($formfield->field->name), null, null, $formfield->display_data());
Expand Down
9 changes: 3 additions & 6 deletions user/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,13 @@ function user_get_user_details($user, $course = null, array $userfields = array(
$categories = profile_get_user_fields_with_data_by_category($user->id);
$userdetails['customfields'] = array();
foreach ($categories as $categoryid => $fields) {
foreach ($fields as $field) {
require_once($CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php');
$newfield = 'profile_field_' . $field->datatype;
$formfield = new $newfield($field->id, $user->id, $field);
foreach ($fields as $formfield) {
if ($formfield->is_visible() and !$formfield->is_empty()) {

// TODO: Part of MDL-50728, this conditional coding must be moved to
// proper profile fields API so they are self-contained.
// We only use display_data in fields that require text formatting.
if ($field->datatype == 'text' or $field->datatype == 'textarea') {
if ($formfield->field->datatype == 'text' or $formfield->field->datatype == 'textarea') {
$fieldvalue = $formfield->display_data();
} else {
// Cases: datetime, checkbox and menu.
Expand All @@ -352,7 +349,7 @@ function user_get_user_details($user, $course = null, array $userfields = array(

$userdetails['customfields'][] =
array('name' => $formfield->field->name, 'value' => $fieldvalue,
'type' => $field->datatype, 'shortname' => $formfield->field->shortname);
'type' => $formfield->field->datatype, 'shortname' => $formfield->field->shortname);
}
}
}
Expand Down
10 changes: 0 additions & 10 deletions user/profile/field/menu/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ public function __construct($fieldid = 0, $userid = 0, $fielddata = null) {
}
}

/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function profile_field_menu($fieldid=0, $userid=0, $fielddata=null) {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct($fieldid, $userid, $fielddata);
}

/**
* Create the code snippet for this field instance
* Overwrites the base class method
Expand Down
6 changes: 6 additions & 0 deletions user/profile/field/upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This files describes API changes in /user/profile/field/* - user profile fields,
information provided here is intended especially for developers.

=== 3.4 ===

* profile_field_base::__construct() now takes three arguments instead of two. Update your plugins if required.
Loading

0 comments on commit b47fda7

Please sign in to comment.