Displaying newly created users from last login

152 views Asked by At

I have installed the Members for Elgg 1.8 plugin in my Elgg application, now I'm editing this plugin to display all the user that are created from last admin login to current login.

but I'm not getting the expected results from the query that I have written.

Here is my index.php code

 case 'lasttonow':
     $db_prefix = elgg_get_config('dbprefix');
     $joins = array("JOIN {$db_prefix}users_entity u on e.guid = u.guid");
     $time = time();
     $options['joins'] = $joins;
     options['wheres'] = "e.time_created >= u.prev_last_login";
     $options['order_by'] = "e.time_created DESC";

     $content = elgg_list_entities_from_metadata($options);
 break;

I'm not understanding where I'm doing mistake.

Thank You

2

There are 2 answers

0
Kishan_KP On BEST ANSWER

I have edited your code to fit in your requirement. Please try following code and you will get what you are expecting. What you were trying to do was wrong, the query you are trying will not display correct result as you are trying to add Prev Last Login of particular user like you mentioned in your code above, actually you were suppose to use Prev Last Login of any users you have logged in to the site.

case 'lasttonow':
                  $db_prefix = elgg_get_config('dbprefix');
                  $joins = array("JOIN {$db_prefix}users_entity u on e.guid = u.guid");
                  $admin = elgg_get_logged_in_user_entity();                            
                  $times =$admin->prev_last_login;                        
                  $options['joins'] = $joins;        
                  $options['wheres'] = "e.time_created >= {$times}";
                  $options['order_by'] = "e.time_created DESC";    
                  $content = elgg_list_entities_from_metadata($options);
                  break;
0
Evan On

The query as constructed is saying, "List all the users created after they last logged in." That will not get you any results.

What you want to do instead is get prev_last_login of the admin (I'll assume currently logged in user) and use that in your query options:

$admin = elgg_get_logged_in_user_entity();
$options['time_created_lower'] = $admin->prev_last_login;
$options['order_by'] = "e.time_created DESC";
$content = elgg_list_entities_from_metadata($options);