Skip to content

Commit

Permalink
Merge branch 'wip-MDL-60029-master' of git://github.com/marinaglancy/…
Browse files Browse the repository at this point in the history
…moodle
  • Loading branch information
junpataleta committed Oct 12, 2017
2 parents 42c7270 + b47fda7 commit dab702d
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 171 deletions.
20 changes: 7 additions & 13 deletions lib/myprofilelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,13 @@ function core_myprofile_navigation(core_user\output\myprofile\tree $tree, $user,
$tree->add_node($node);
}

if ($categories = $DB->get_records('user_info_category', null, 'sortorder ASC')) {
foreach ($categories as $category) {
if ($fields = $DB->get_records('user_info_field', array('categoryid' => $category->id), 'sortorder ASC')) {
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);
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());
$tree->add_node($node);
}
}
$categories = profile_get_user_fields_with_data_by_category($user->id);
foreach ($categories as $categoryid => $fields) {
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());
$tree->add_node($node);
}
}
}
Expand Down
42 changes: 18 additions & 24 deletions user/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,34 +331,28 @@ function user_get_user_details($user, $course = null, array $userfields = array(
$userdetails['fullname'] = fullname($user);

if (in_array('customfields', $userfields)) {
$fields = $DB->get_recordset_sql("SELECT f.*
FROM {user_info_field} f
JOIN {user_info_category} c
ON f.categoryid=c.id
ORDER BY c.sortorder ASC, f.sortorder ASC");
$categories = profile_get_user_fields_with_data_by_category($user->id);
$userdetails['customfields'] = array();
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);
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') {
$fieldvalue = $formfield->display_data();
} else {
// Cases: datetime, checkbox and menu.
$fieldvalue = $formfield->data;
foreach ($categories as $categoryid => $fields) {
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 ($formfield->field->datatype == 'text' or $formfield->field->datatype == 'textarea') {
$fieldvalue = $formfield->display_data();
} else {
// Cases: datetime, checkbox and menu.
$fieldvalue = $formfield->data;
}

$userdetails['customfields'][] =
array('name' => $formfield->field->name, 'value' => $fieldvalue,
'type' => $formfield->field->datatype, 'shortname' => $formfield->field->shortname);
}

$userdetails['customfields'][] =
array('name' => $formfield->field->name, 'value' => $fieldvalue,
'type' => $field->datatype, 'shortname' => $formfield->field->shortname);
}
}
$fields->close();
// Unset customfields if it's empty.
if (empty($userdetails['customfields'])) {
unset($userdetails['customfields']);
Expand Down
33 changes: 0 additions & 33 deletions user/profile/field/checkbox/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,6 @@
*/
class profile_field_checkbox extends profile_field_base {

/**
* Constructor method.
* Pulls out the options for the checkbox from the database and sets the
* the corresponding key for the data if it exists
*
* @param int $fieldid
* @param int $userid
*/
public function __construct($fieldid=0, $userid=0) {
global $DB;
// First call parent constructor.
parent::__construct($fieldid, $userid);

if (!empty($this->field)) {
$datafield = $DB->get_field('user_info_data', 'data', array('userid' => $this->userid, 'fieldid' => $this->fieldid));
if ($datafield !== false) {
$this->data = $datafield;
} else {
$this->data = $this->field->defaultdata;
}
}
}

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

/**
* Add elements for editing the profile field value.
* @param moodleform $mform
Expand Down
15 changes: 3 additions & 12 deletions user/profile/field/menu/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class profile_field_menu extends profile_field_base {
*
* @param int $fieldid
* @param int $userid
* @param object $fielddata
*/
public function __construct($fieldid = 0, $userid = 0) {
public function __construct($fieldid = 0, $userid = 0, $fielddata = null) {
// First call parent constructor.
parent::__construct($fieldid, $userid);
parent::__construct($fieldid, $userid, $fielddata);

// Param 1 for menu type is the options.
if (isset($this->field->param1)) {
Expand All @@ -73,16 +74,6 @@ public function __construct($fieldid = 0, $userid = 0) {
}
}

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

/**
* 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 dab702d

Please sign in to comment.