3 class MemberList
extends FormField
{
5 protected $hidePassword;
8 function __construct($name, $group, $members = null, $hidePassword = null, $pageLimit = 10) {
10 if(is_object($group)) $this->group
= $group;
11 else $this->group
= DataObject
::get_by_id('Group',$group);
14 $this->pageSize
= $pageLimit;
16 if($members) $this->members
= $this->memberListWithGroupID($members, $group);
18 $this->hidePassword
= $hidePassword;
20 parent
::__construct(null);
23 function memberListWithGroupID($members, $group) {
24 $newMembers = new DataObjectSet();
25 foreach($members as $member) {
26 $newMembers->push($member->customise(array("GroupID" => $group->ID
)));
31 function FieldHolder() {
32 return $this->renderWith("MemberList");
34 function setGroup($group) {
35 $this->group
= $group;
37 function setController($controller) {
38 $this->controller
= $controller;
43 return $this->group
->ID
;
48 function GetControllerName() {
49 return $this->controller
->class;
53 $members = $this->members;
54 else if($this->group) {
55 $members = $this->group->Members( $this->pageSize, 0 );
56 $allMembers = $this->group->Members();
59 $total = $allMembers->Count();
64 return $this->members
;
67 $baseGroup = $this->group
->ID
;
69 // Debug::message( $_REQUEST['MemberListOrderByField'] );
71 // construct the filter and sort
73 if( $_REQUEST['MemberListOrderByField'] )
74 $sort = "`" . $_REQUEST['MemberListOrderByField'] . "`" . addslashes( $_REQUEST['MemberListOrderByOrder'] );
76 $whereClauses = array();
78 $search = addslashes( $_REQUEST['MemberListSearch'] );
80 if( is_numeric( $_REQUEST['MemberListStart'] ) )
81 $limitClause = ( $_REQUEST['MemberListStart'] ) . ", {$this->pageSize}";
83 $limitClause = "0, {$this->pageSize}";
86 if( !empty($_REQUEST['MemberListSearch']) )
87 $whereClauses[] = "( `Email`='$search' OR `FirstName`='$search' OR `Surname`='$search' )";
89 if( is_numeric( $_REQUEST['MemberListBaseGroup'] ) )
90 $baseGroup = $_REQUEST['MemberListBaseGroup'];
92 $whereClauses[] = "`GroupID`='".$baseGroup."'";
93 $join = "INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`";
95 // $_REQUEST['showqueries'] = 1;
97 $members = DataObject
::get('Member', implode( ' AND ', $whereClauses ), $sort, $join, $limitClause );
99 // $_REQUEST['showqueries'] = 0;
101 if( is_numeric( $_REQUEST['MemberListGroup'] ) ) {
102 $baseMembers = new DataObjectSet();
105 foreach( $members as $member )
106 if( $member->inGroup( $_REQUEST['MemberListGroup'] ) )
107 $baseMembers->push( $member );
109 $baseMembers = $members;
112 $members->setPageLimits( $_REQUEST['MemberListStart'], $this->pageSize
, $total );
114 $this->members
= $this->memberListWithGroupID($members, $this->group
);
116 return $this->members
;
119 function FirstLink() {
120 if( !$_REQUEST['MemberListStart'] )
123 return "admin/security/listmembers?MemberListStart=0{$this->filterString()}";
126 function filterString() {
128 foreach( $_REQUEST as $key => $value ) {
129 if( strpos( $key, 'MemberList' ) === 0 && $key != 'MemberListStart' )
130 $filterString .= "&$key=$value";
133 if( !$_REQUEST['MemberListBaseGroup'] )
134 $filterString .= '&MemberListBaseGroup=' . $this->group
->ID
;
136 return $filterString;
139 function MemberListStart() {
140 return $_REQUEST['MemberListStart'];
143 function PrevLink() {
144 if( !$_REQUEST['MemberListStart'] )
147 $prevStart = $_REQUEST['MemberListStart'] - $this->pageSize
;
152 return "admin/security/listmembers?MemberListStart=$prevStart{$this->filterString()}";
155 function NextLink() {
156 $total = $this->TotalMembers();
158 $lastStart = $total - ( $total %
$this->pageSize
);
160 if( $_REQUEST['MemberListStart'] >= $lastStart )
163 return "admin/security/listmembers?MemberListStart={$this->pageSize}{$this->filterString()}";
166 function LastLink() {
168 $total = $this->TotalMembers();
170 $lastStart = $total - ( $total %
$this->pageSize
);
172 if( $_REQUEST['MemberListStart'] >= $lastStart )
175 return "admin/security/listmembers?MemberListStart=$lastStart{$this->filterString()}";
178 function PageSize() {
179 return $this->pageSize
;
182 function FirstMember() {
183 return $_REQUEST['MemberListStart'] +
1;
186 function LastMember() {
187 return $_REQUEST['MemberListStart'] +
min( $_REQUEST['MemberListStart'] +
$this->pageSize
, $this->TotalMembers() - $_REQUEST['MemberListStart'] );
190 function TotalMembers() {
191 if($this->group
) $members = $this->group
->Members();
196 return $members->TotalItems();
199 function DontShowPassword(){
200 if( $this->hidePassword
)
203 return $this->controller
->class=='CMSMain'||
$this->controller
->class=='NewsletterAdmin';
206 function AddRecordForm() {
207 if($this->DontShowPassword())
209 return new TabularStyle(new Form($this->controller
,'AddRecordForm',
211 new TextField("FirstName", "First Name"),
212 new TextField("Surname", "Surname"),
213 new TextField("Email", "Email"),
214 new HiddenField("GroupID", null, $this->group
->ID
)
217 new FormAction("addmember", "Add")
222 return new TabularStyle(new Form($this->controller
,'AddRecordForm',
224 new TextField("FirstName", "First Name"),
225 new TextField("Surname", "Surname"),
226 new TextField("Email", "Email"),
227 new TextField("Password", "Password"),
228 new HiddenField("GroupID", null, $this->group
->ID
)
231 new FormAction("addmember", "Add")
237 function SearchField() {
238 $field = new TextField( 'MemberListSearch', 'Search' );
239 return $field->FieldHolder();
242 function OrderByField() {
243 $fields = new FieldGroup( new DropdownField('MemberListOrderByField','', array(
244 'FirstName' => 'FirstName',
245 'Surname' => 'Surname',
248 new DropdownField('MemberListOrderByOrder','',array(
249 'ASC' => 'Ascending',
250 'DESC' => 'Descending'
253 $field = new FieldGroup( new LabelField( 'Order by' ), $fields );
254 return $field->FieldHolder();
257 function GroupFilter() {
259 $groups = DataObject
::get('Group');
261 $groupArray = array( '' => 'Any group' );
263 foreach( $groups as $group )
264 $groupArray[$group->ID
] = $group->Title
;
266 $field = new DropdownField('MemberListGroup','Filter by group',$groupArray );
267 return $field->FieldHolder();