Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c1bdc1c4

Přidáno uživatelem Michal Kliment před více než 9 roky(ů)

Release 1.1.0

Zobrazit rozdíly:

application/models/login_log.php
* Returns last login of all user
*
* @author Michal Kliment
* @param int $sql_offset
* @param int $limit_results
* @param string $order_by
* @param string $order_by_direction
* @param string $filter_sql
* @return Mysql_Result
*/
public function get_all_login_logs($sql_offset = 0, $limit_results = 500)
public function get_all_login_logs($sql_offset = 0, $limit_results = 500,
$order_by = 'last_time', $order_by_direction = 'DESC', $filter_sql = '')
{
return $this->db->query('
$where = '';
if (!empty($filter_sql))
{
$where = 'WHERE ' . $filter_sql;
}
if (strtolower($order_by_direction) != 'asc')
{
$order_by_direction = 'desc';
}
if (!in_array($order_by, array('id', 'name', 'last_time')))
{
$order_by = 'last_time';
}
if ($order_by == 'last_time')
{
$order_by = "IF(last_time IS NULL, 0, 1) $order_by_direction, last_time";
}
return $this->db->query("
SELECT id, name, IFNULL(last_time,?) as last_time
FROM (
SELECT *
FROM (
SELECT u.id, CONCAT(u.name,\' \',u.surname) AS name,
SELECT u.id, CONCAT(u.name, ' ', u.surname) AS name,
l.time AS last_time
FROM users u
LEFT JOIN login_logs l ON u.id = l.user_id
ORDER BY time DESC
) AS q1
$where
GROUP BY q1.id
) AS q3
ORDER BY q3.last_time DESC
LIMIT ' . intval($sql_offset) . ', ' . intval($limit_results) . '
', url_lang::lang('texts.Never'));
ORDER BY $order_by $order_by_direction
LIMIT " . intval($sql_offset) . ", " . intval($limit_results) . "
", __('Never'));
}
/**
* Returns last login of all user
* Returns count of last login of all user
*
* @param string $filter_sql
* @author Michal Kliment
* @return integer
*/
public function count_all_login_logs()
public function count_all_login_logs($filter_sql)
{
$user = new User_Model();
return $user->count_all();
$where = '';
if (!empty($filter_sql))
{
$where = 'WHERE ' . $filter_sql;
}
else
{
return ORM::factory('user')->count_all();
}
return $this->db->query("
SELECT COUNT(*) AS total
FROM (
SELECT *
FROM (
SELECT u.id, CONCAT(u.name, ' ', u.surname) AS name,
l.time AS last_time
FROM users u
LEFT JOIN login_logs l ON u.id = l.user_id
ORDER BY time DESC
) AS q1
$where
GROUP BY q1.id
) AS q3
")->current()->total;
}
/**
......
*
* @author Michal Kliment
* @param integer $user_id
* @param int $sql_offset
* @param int $limit_results
* @param string $order_by
* @param string $order_by_direction
* @param string $filter_sql
* @return Mysql_Result
*/
public function get_all_login_logs_by_user($user_id = 0, $sql_offset = 0,
$limit_results = 500, $order_by = 'time', $order_by_direction = 'desc')
$limit_results = 500, $order_by = 'time', $order_by_direction = 'desc',
$filter_sql = '')
{
// order by check
if (!$this->has_column($order_by))
......
{
$order_by_direction = 'asc';
}
// where
$where = '';
if (!empty($filter_sql))
{
$where = 'AND ' . $filter_sql;
}
// query
return $this->db->query("
SELECT id, time, ip_address
FROM login_logs
WHERE user_id = ?
WHERE user_id = ? $where
ORDER BY $order_by $order_by_direction
LIMIT " . intval($sql_offset) . ", " . intval($limit_results) . "
", $user_id);
......
*
* @author Michal Kliment
* @param integer $user_id
* @param string $filter_sql
* @return integer
*/
public function count_all_login_logs_by_user($user_id = 0)
public function count_all_login_logs_by_user($user_id = 0, $filter_sql = '')
{
// where
$where = '';
if (!empty($filter_sql))
{
$where = 'AND ' . $filter_sql;
}
// query
return $this->db->query("
SELECT COUNT(*) AS count
FROM login_logs
WHERE user_id = ?
WHERE user_id = ? $where
", $user_id)->current()->count;
}

Také k dispozici: Unified diff