Permalink
Browse files

Added ability to query users by group id(s) - Resolves Issue #113

  • Loading branch information...
benedmunds committed Apr 11, 2012
1 parent 0d5945a commit bcea692deb627df9bb331697aa843f5aa6a569c2
Showing with 24 additions and 1 deletion.
  1. +24 −1 models/ion_auth_model.php
View
@@ -806,7 +806,7 @@ public function result_array()
* @return object Users
* @author Ben Edmunds
**/
- public function users()
+ public function users($groups = NULL)
{
$this->trigger_events('users');
@@ -820,6 +820,29 @@ public function users()
$this->_ion_select = array();
}
+ //filter by group id(s) if passed
+ if (isset($groups))
+ {
+ //build an array if only one group was passed
+ if (is_numeric($groups))
+ {
+ $group = $groups;
+ $groups = Array($group);
+ }
+
+ //join and then run a where_in against the group ids
+ if (isset($groups) && !empty($groups))
+ {
+ $this->db->join(
+ $this->tables['users_groups'],
+ $this->tables['users_groups'].'.user_id = ' . $this->tables['users'].'.id',
+ 'inner'
+ );
+
+ $this->db->where_in($this->tables['users_groups'].'.group_id', $groups);
+ }
+ }
+
$this->trigger_events('extra_where');
//run each where that was passed

0 comments on commit bcea692

Please sign in to comment.