Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Member Profiles - list only members that have logged in


Reply


4 Posts   813 Views

Avatar
Acidtripchimp

Community Member, 6 Posts

24 June 2011 at 1:39am

I've put together a membership site for a small society and extended the member profile module to add in addtional fields and functionality to facilitate this. Members want to be able to contact other members of the site so I have a member list page only accessible to members. All members have been loaded into the database and to protect the details only those that have logged into their member profile should be shown on this listing. I figure the easiest way of doing this is to check 'NumVisit' in the database for a value of '0', if the condition is true then remove these members from the loop to only show members that have signed in.

However I've tried a number of different ways that I can think of to check for these conditions but it still continues to pull all the members from the database apart from admin - weird.

I only picked up SS a month ago so any help greatly appreciated!

This is the current attempt

class MemberList extends Page {
function pullMembers(){

$members = DataObject::get('Member');

foreach($members as $member){

$sqlQuery = new SQLQuery(
         "SUM(NumVisit)",
          "Member");

if('NumVisit' == '0'){

$members->remove($member);

break;
}

}
return $members;

}
}

Avatar
Willr

Forum Moderator, 5513 Posts

25 June 2011 at 4:39pm

The easiest way is just to pass the filter (NumVisit > 0) to the DataObject get call.

function pullMembers() {
return DataObject::get('Member', "NumVisit > 0");
}

Avatar
Acidtripchimp

Community Member, 6 Posts

25 June 2011 at 9:09pm

Hi Willr, thanks for the reply. I figured out a slightly different method in the end, but it's good to know there's a shorter route!

Avatar
Acidtripchimp

Community Member, 6 Posts

22 March 2012 at 12:19pm

The Society membership database mentioned below has now grown considerably and the requirement to segregate members into the groups has arisen. I have security groups to manage the different lists and can pull in a list of members in a group no problem. However what I need to make sure is that the members in a particular group have logged into the system before (a mechanism for them agreeing to their details being displayed). Currently the code below pulls in all group members whether they've logged in or not?

function pullMembers(){

$members = DataObject::get('Member', "NumVisit > 0");
foreach($members as $member){

if ($group = DataObject::get_one("Group", "Title = 'HKmembers'")){

$members->remove($member);

break;

}
}

return $members = $group->Members();
}

Any help much appreciated!