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) (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
@ -74,6 +74,11 @@ class Member extends DataObject {
|
|||||||
'Email' => 'Email',
|
'Email' => 'Email',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Array See {@link set_title_columns()}
|
||||||
|
*/
|
||||||
|
static $title_format = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The unique field used to identify this member.
|
* The unique field used to identify this member.
|
||||||
* By default, it's "Email", but another common
|
* By default, it's "Email", but another common
|
||||||
@ -689,15 +694,35 @@ class Member extends DataObject {
|
|||||||
return Permission::checkMember($this, 'ADMIN');
|
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 -----------------------------------//
|
//------------------- 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
|
* @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() {
|
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)
|
if($this->getField('ID') === 0)
|
||||||
return $this->getField('Surname');
|
return $this->getField('Surname');
|
||||||
else{
|
else{
|
||||||
@ -713,6 +738,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
|
* Get the complete name of the member
|
||||||
|
Loading…
x
Reference in New Issue
Block a user