UserOnlineMapper::deleteBySessionId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Copyright (c) 2014, Tobia De Koninck hey--at--ledfan.be
4
 * This file is licensed under the AGPL version 3 or later.
5
 * See the COPYING file.
6
 */
7
8
namespace OCA\Chat\OCH\Db;
9
10
use \OCP\AppFramework\Db\Mapper;
11
use \OCP\IDb;
12
13
class UserOnlineMapper extends Mapper {
14
15
	public function __construct(IDb $api) {
16
		parent::__construct($api, 'chat_och_users_online'); // tablename is news_feeds
17
	}
18
19
	public function getOnlineUsers(){
20
		$sql = <<<SQL
21
			SELECT
22
				`user`
23
			FROM
24
				`*PREFIX*chat_och_users_online`
25
SQL;
26
		$result = $this->execute($sql);
27
28
		$rows = array();
29
30
		while($row = $result->fetch()){
31
			array_push($rows, $row['user']);
32
		}
33
		return $rows;
34
	}
35
36
	public function getAll(){
37
		return $this->findEntities("SELECT * FROM " . $this->getTableName());
38
	}
39
	
40
	public function findByUser($user){
41
		$sql = <<<SQL
42
			SELECT
43
				*
44
			FROM `*PREFIX*chat_och_users_online`
45
			WHERE
46
				`user` = ?
47
SQL;
48
		$result = $this->findEntities($sql, array($user));
49
		return $result;
50
	}
51
52
	public function deleteBySessionId($sessionID){
53
		$sql = 'DELETE FROM `' . $this->getTableName() . '` WHERE `session_id` = ?';
54
		$this->execute($sql, array($sessionID));
55
	}
56
	
57
	public function updateLastOnline($sessionID, $timestamp){
58
		$sql = 'UPDATE `' . $this->getTableName() . '` SET `last_online` = ? WHERE `session_id` = ?';
59
		$this->execute($sql, array($timestamp, $sessionID));
60
	}
61
 
62
}
63