From 2230dd4e6b148346c0ec596b9e3e12996a762ed8 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 22 May 2014 12:28:28 -0400 Subject: Code refactoring (add autoloader and change files organization) --- app/Model/LastLogin.php | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 app/Model/LastLogin.php (limited to 'app/Model/LastLogin.php') diff --git a/app/Model/LastLogin.php b/app/Model/LastLogin.php new file mode 100644 index 00000000..56739b48 --- /dev/null +++ b/app/Model/LastLogin.php @@ -0,0 +1,91 @@ +db + ->table(self::TABLE) + ->eq('user_id', $user_id) + ->desc('date_creation') + ->findAllByColumn('id'); + + if (count($connections) >= self::NB_LOGINS) { + + $this->db->table(self::TABLE) + ->eq('user_id', $user_id) + ->notin('id', array_slice($connections, 0, self::NB_LOGINS - 1)) + ->remove(); + } + + return $this->db + ->table(self::TABLE) + ->insert(array( + 'auth_type' => $auth_type, + 'user_id' => $user_id, + 'ip' => $ip, + 'user_agent' => $user_agent, + 'date_creation' => time(), + )); + } + + /** + * Get the last connections for a given user + * + * @access public + * @param integer $user_id User id + * @return array + */ + public function getAll($user_id) + { + return $this->db + ->table(self::TABLE) + ->eq('user_id', $user_id) + ->desc('date_creation') + ->columns('id', 'auth_type', 'ip', 'user_agent', 'date_creation') + ->findAll(); + } +} -- cgit v1.2.3