mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR ability to customize the text that comes out of Member->Title
MINOR updated workflow reports (from r96352) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@99099 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
61d880ce68
commit
7a63868fd6
@ -74,6 +74,11 @@ class Member extends DataObject {
|
||||
'Email' => 'Email',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var Array See {@link set_title_columns()}
|
||||
*/
|
||||
static $title_format = null;
|
||||
|
||||
/**
|
||||
* The unique field used to identify this member.
|
||||
* By default, it's "Email", but another common
|
||||
@ -683,15 +688,35 @@ class Member extends DataObject {
|
||||
return Permission::checkMember($this, 'ADMIN');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Array $columns Column names on the Member record to show in {@link getTitle()}.
|
||||
* @param String $sep Separator
|
||||
*/
|
||||
static function set_title_columns($columns, $sep = ' ') {
|
||||
if (!is_array($columns)) $columns = array($columns);
|
||||
self::$title_format = array('columns' => $columns, 'sep' => $sep);
|
||||
}
|
||||
|
||||
//------------------- HELPER METHODS -----------------------------------//
|
||||
|
||||
/**
|
||||
* Get the complete name of the member
|
||||
* Get the complete name of the member, by default in the format "<Surname>, <FirstName>".
|
||||
* Falls back to showing either field on its own.
|
||||
*
|
||||
* You can overload this getter with {@link set_title_format()}
|
||||
* and {@link set_title_sql()}.
|
||||
*
|
||||
* @return string Returns the first- and surname of the member. If the ID
|
||||
* of the member is equal 0, only the surname is returned.
|
||||
* of the member is equal 0, only the surname is returned.
|
||||
*/
|
||||
public function getTitle() {
|
||||
if (self::$title_format) {
|
||||
$values = array();
|
||||
foreach(self::$title_format['columns'] as $col) {
|
||||
$values[] = $this->getField($col);
|
||||
}
|
||||
return join(self::$title_format['sep'], $values);
|
||||
}
|
||||
if($this->getField('ID') === 0)
|
||||
return $this->getField('Surname');
|
||||
else{
|
||||
@ -707,6 +732,21 @@ class Member extends DataObject {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a SQL CONCAT() fragment suitable for a SELECT statement.
|
||||
* Useful for custom queries which assume a certain member title format.
|
||||
*
|
||||
* @param String $tableName
|
||||
* @return String SQL
|
||||
*/
|
||||
static function get_title_sql($tableName = 'Member') {
|
||||
if (self::$title_format) {
|
||||
return "CONCAT(".join('"'.self::$title_format['sep'].'"', self::$title_format['columns']).")";
|
||||
} else {
|
||||
return "CONCAT($tableName.Surname, \" \", $tableName.FirstName)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the complete name of the member
|
||||
|
Loading…
x
Reference in New Issue
Block a user