mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR ability to customize the text that comes out of Member->Title
MINOR updated workflow reports (from r96352) (from r99099) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102846 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
3dc4486f3b
commit
ae7439a4c3
@ -72,7 +72,12 @@ class Member extends DataObject {
|
||||
'FirstName' => 'First Name',
|
||||
'Surname' => 'Last Name',
|
||||
'Email' => 'Email',
|
||||
);
|
||||
);
|
||||
|
||||
/**
|
||||
* @var Array See {@link set_title_columns()}
|
||||
*/
|
||||
static $title_format = null;
|
||||
|
||||
/**
|
||||
* The unique field used to identify this member.
|
||||
@ -688,16 +693,36 @@ class Member extends DataObject {
|
||||
function isAdmin() {
|
||||
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{
|
||||
@ -712,6 +737,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)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user