MessageMapper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 0
cbo 0
dl 0
loc 62
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B getMessagesByConvId() 0 30 2
A getMessagesByConvIdLimit() 0 23 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 MessageMapper extends Mapper{
14
15
	public function __construct(IDb $api) {
16
		parent::__construct($api, 'chat_och_messages'); // tablename is news_feeds
17
	}
18
 
19
	public function getMessagesByConvId($convId, $user, $startpoint=0){
20
		$sql = <<<SQL
21
			SELECT
22
				*
23
			FROM
24
				*PREFIX*chat_och_messages
25
			WHERE
26
				`convid` = ?
27
			AND
28
				`timestamp` > (
29
					SELECT
30
						`joined`
31
					FROM
32
						*PREFIX*chat_och_users_in_conversation
33
					WHERE
34
						`user` = ?
35
					AND `conversation_id` = ?
36
				)
37
SQL;
38
		if($startpoint !== 0){
39
			$sql = $sql . <<<SQL
40
			AND
41
				`timestamp` > ?
42
SQL;
43
			return $this->findEntities($sql, array($convId, $user, $convId, $startpoint));
44
		} else {
45
			return $this->findEntities($sql, array($convId, $user, $convId));
46
		}
47
48
	}
49
50
	public function getMessagesByConvIdLimit($convId, $user, $limit){
51
		$sql = <<<SQL
52
			SELECT
53
				*
54
			FROM
55
				*PREFIX*chat_och_messages
56
			WHERE
57
				`convid` = ?
58
			AND
59
				`timestamp` > (
60
					SELECT
61
						`joined`
62
					FROM
63
						*PREFIX*chat_och_users_in_conversation
64
					WHERE
65
						`user` = ?
66
					AND `conversation_id` = ?
67
				)
68
			ORDER BY timestamp DESC
69
			LIMIT ?,?
70
SQL;
71
		return $this->findEntities($sql, array($convId, $user, $convId, $limit[0], $limit[1]));
72
	}
73
74
}
75