Permalink
Browse files

MDL-25886 allow user_picture::fields() to be used multiple times with…

…in a single query

When user table is joined twice or more within a single query, it is
important to be able to provide aliases to all returned files. This
patch adds optional parameter that, if provided, is used as a prefix
for columns aliases. Does not apply to the 'id' column, use $idalias for
that.
  • Loading branch information...
1 parent 46f4c39 commit 9958e561d81c462667f521b915cc0482f51d097b @mudrd8mz mudrd8mz committed Jan 7, 2011
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/outputcomponents.php
View
@@ -177,9 +177,10 @@ public function __construct(stdClass $user) {
* @param string $tableprefix name of database table prefix in query
* @param array $extrafields extra fields to be included in result (do not include TEXT columns because it would break SELECT DISTINCT in MSSQL and ORACLE)
* @param string $idalias alias of id field
+ * @param string $fieldprefix prefix to add to all columns in their aliases, does not apply to 'id'
* @return string
*/
- public static function fields($tableprefix = '', array $extrafields = NULL, $idalias = 'id') {
+ public static function fields($tableprefix = '', array $extrafields = NULL, $idalias = 'id', $fieldprefix = '') {
if (!$tableprefix and !$extrafields and !$idalias) {
return implode(',', self::$fields);
}
@@ -191,7 +192,11 @@ public static function fields($tableprefix = '', array $extrafields = NULL, $ida
if ($field === 'id' and $idalias and $idalias !== 'id') {
$fields[$field] = "$tableprefix$field AS $idalias";
} else {
- $fields[$field] = $tableprefix.$field;
+ if ($fieldprefix and $field !== 'id') {
+ $fields[$field] = "$tableprefix$field AS $fieldprefix$field";
+ } else {
+ $fields[$field] = "$tableprefix$field";
+ }
}
}
// add extra fields if not already there

0 comments on commit 9958e56

Please sign in to comment.