mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-21851 adding idalias to user_picture::fields()
This commit is contained in:
parent
e116a81833
commit
f3afba4e19
1 changed files with 16 additions and 4 deletions
|
@ -119,15 +119,27 @@ class user_picture implements renderable {
|
|||
|
||||
/**
|
||||
* Returns a list of required user fields, usefull when fetching required user info from db.
|
||||
*
|
||||
* In some cases we have to fetch the user data together with some other information,
|
||||
* the idalias is useful there because the id would otherwise override the main
|
||||
* id of the result record. Please note it has to be converted back to id before rendering.
|
||||
*
|
||||
* @param string $tableprefix name of database table prefix in query
|
||||
* @param string $idalias alias of id field
|
||||
* @return string
|
||||
*/
|
||||
public static function fields($tableprefix = '') {
|
||||
if ($tableprefix === '') {
|
||||
public static function fields($tableprefix = '', $idalias = '') {
|
||||
if ($tableprefix === '' and $idalias === '') {
|
||||
return self::FIELDS;
|
||||
} else {
|
||||
return "$tableprefix." . str_replace(',', ",$tableprefix.", self::FIELDS);
|
||||
}
|
||||
$fields = explode(',', self::FIELDS);
|
||||
foreach ($fields as $key=>$field) {
|
||||
if ($field === 'id' and $idalias !== '') {
|
||||
$field = "$field AS $idalias";
|
||||
}
|
||||
$fields[$key] = "$tableprefix.$field";
|
||||
}
|
||||
return implode(',', $fields);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue