Jump to:

10851 Posts in 2517 Topics by 1793 members

All other Modules

SilverStripe Forums » All other Modules » Member Profiles - list only members that have logged in

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 709 Views
  • Acidtripchimp
    Avatar
    Community Member
    6 Posts

    Member Profiles - list only members that have logged in Link to this post

    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;

    }
    }

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Member Profiles - list only members that have logged in Link to this post

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

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

  • Acidtripchimp
    Avatar
    Community Member
    6 Posts

    Re: Member Profiles - list only members that have logged in Link to this post

    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!

  • Acidtripchimp
    Avatar
    Community Member
    6 Posts

    Re: Member Profiles - list only members that have logged in Link to this post

    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!

    709 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.