Query usr_data.
{
global $ilDB;
$ut_join = "";
if (is_array($this->additional_fields))
{
foreach ($this->additional_fields as $f)
{
if (!in_array($f, $this->default_fields))
{
if($f == "online_time")
{
$this->default_fields[] = "ut_online.online_time";
$ut_join = " LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id";
}
else
{
$this->default_fields[] = $f;
}
}
}
}
$count_query = "SELECT count(usr_id) cnt".
" FROM usr_data";
$sql_fields = array();
foreach($this->default_fields as $idx => $field)
{
if(!$field)
{
continue;
}
if(!stristr($field, "."))
{
$sql_fields[] = "usr_data.".$field;
}
else
{
$sql_fields[] = $field;
}
}
$query =
"SELECT ".implode($sql_fields,
",").
" FROM usr_data".
$ut_join;
$query.=
" WHERE usr_data.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID,
"integer");
if($this->users and is_array(($this->users)))
{
$query .=
' AND '.$ilDB->in(
'usr_data.usr_id',$this->users,
false,
'integer');
}
$count_query.= " WHERE usr_data.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
$where = " AND";
if ($this->first_letter != "")
{
$add = $where." (".$ilDB->upper($ilDB->substr("usr_data.lastname", 1, 1))." = ".$ilDB->upper($ilDB->quote($this->first_letter, "text")).") ";
$count_query.= $add;
$where = " AND";
}
if ($this->text_filter != "")
{
$add = $where." (".$ilDB->like("usr_data.login", "text", "%".$this->text_filter."%")." ".
"OR ".$ilDB->like("usr_data.firstname", "text", "%".$this->text_filter."%")." ".
"OR ".$ilDB->like("usr_data.lastname", "text", "%".$this->text_filter."%")." ".
"OR ".$ilDB->like("usr_data.email", "text", "%".$this->text_filter."%").") ";
$count_query.= $add;
$where = " AND";
}
if ($this->activation != "")
{
if ($this->activation == "inactive")
{
$add = $where." usr_data.active = ".$ilDB->quote(0, "integer")." ";
}
else
{
$add = $where." usr_data.active = ".$ilDB->quote(1, "integer")." ";
}
$count_query.= $add;
$where = " AND";
}
{
{
$add = $where." usr_data.last_login < ".
$count_query.= $add;
$where = " AND";
}
}
if ($this->limited_access)
{
$add = $where." usr_data.time_limit_unlimited= ".$ilDB->quote(0, "integer");
$count_query.= $add;
$where = " AND";
}
if ($this->no_courses)
{
$add = $where." usr_data.usr_id NOT IN (".
"SELECT DISTINCT ud.usr_id ".
"FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
"JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) ".
"WHERE od.title LIKE 'il_crs_%')";
$count_query.= $add;
$where = " AND";
}
if ($this->no_groups)
{
$add = $where." usr_data.usr_id NOT IN (".
"SELECT DISTINCT ud.usr_id ".
"FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
"JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) ".
"WHERE od.title LIKE 'il_grp_%')";
$count_query.= $add;
$where = " AND";
}
if ($this->crs_grp > 0)
{
$add = $where." usr_data.usr_id IN (".
"SELECT DISTINCT ud.usr_id ".
"FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
"JOIN object_data od ON (rbac_ua.rol_id = od.obj_id) ".
"WHERE od.title = ".$ilDB->quote("il_".$cgtype."_member_".$this->crs_grp, "text").")";
$count_query.= $add;
$where = " AND";
}
if ($this->role > 0)
{
$add = $where." usr_data.usr_id IN (".
"SELECT DISTINCT ud.usr_id ".
"FROM usr_data ud join rbac_ua ON (ud.usr_id = rbac_ua.usr_id) ".
"WHERE rbac_ua.rol_id = ".$ilDB->quote($this->role, "integer").")";
$count_query.= $add;
$where = " AND";
}
if($this->user_folder)
{
$add = $where." ".$ilDB->in('usr_data.time_limit_owner',$this->user_folder,false,'integer');
$count_query.= $add;
$where = " AND";
}
switch($this->order_field)
{
case "access_until":
if ($this->order_dir == "desc")
{
$query.=
" ORDER BY usr_data.active DESC, usr_data.time_limit_unlimited DESC, usr_data.time_limit_until DESC";
}
else
{
$query.=
" ORDER BY usr_data.active ASC, usr_data.time_limit_unlimited ASC, usr_data.time_limit_until ASC";
}
break;
case "online_time":
if ($this->order_dir == "desc")
{
$query.=
" ORDER BY ut_online.online_time DESC";
}
else
{
$query.=
" ORDER BY ut_online.online_time ASC";
}
break;
default:
if (!in_array($this->order_field, $this->default_fields))
{
$this->order_field = "login";
}
if ($this->order_dir != "asc" && $this->order_dir != "desc")
{
$this->order_dir = "asc";
}
$query .=
" ORDER BY usr_data.".$this->order_field.
" ".strtoupper($this->order_dir);
break;
}
$set = $ilDB->query($count_query);
$cnt = 0;
if ($rec = $ilDB->fetchAssoc($set))
{
$cnt = $rec["cnt"];
}
{
}
while($rec = $ilDB->fetchAssoc($set))
{
}
return array(
"cnt" => $cnt,
"set" =>
$result);
}