Completed
Push — master ( 6e7141...c85fa9 )
by Sam
02:48
created

UserQuery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 29.4%

Importance

Changes 6
Bugs 0 Features 2
Metric Value
wmc 4
c 6
b 0
f 2
lcom 0
cbo 1
dl 0
loc 59
ccs 5
cts 17
cp 0.294
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasUser() 0 4 1
A filterIgnoredUsers() 0 10 2
A getMostActiveWatchersQuery() 0 16 1
1
<?php
2
3
namespace Jalle19\StatusManager\Database;
4
5
use Jalle19\StatusManager\Database\Base\UserQuery as BaseUserQuery;
6
use Propel\Runtime\ActiveQuery\Criteria;
7
8
/**
9
 * @package   Jalle19\StatusManager\Database
10
 * @copyright Copyright &copy; Sam Stenvall 2015-
11
 * @license   https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0
12
 */
13
class UserQuery extends BaseUserQuery
0 ignored issues
show
Bug introduced by
There is one abstract method limit in this class; you could implement it, or declare this class as abstract.
Loading history...
14
{
15
16
	use LimitTrait;
17
18
19
	/**
20
	 * @param string $instanceName
21
	 * @param string $userName
22
	 *
23
	 * @return bool
24
	 */
25
	public function hasUser($instanceName, $userName)
26
	{
27
		return $this->filterByInstanceName($instanceName)->filterByName($userName)->findOne() !== null;
28
	}
29
30
31
	/**
32
	 * @param array $ignoredUsers
33
	 *
34
	 * @return UserQuery
35
	 */
36 1
	public function filterIgnoredUsers(array $ignoredUsers)
37
	{
38
		// Always ignore system users
39 1
		$ignoredUsers[] = User::NAME_DVR;
40
41 1
		foreach ($ignoredUsers as $ignoredUser)
42 1
			$this->filterByName($ignoredUser, Criteria::NOT_EQUAL);
43
44 1
		return $this;
45
	}
46
47
48
	/**
49
	 * @param Instance $instance
50
	 *
51
	 * @return UserQuery
52
	 * @throws \Propel\Runtime\Exception\PropelException
53
	 */
54
	public function getMostActiveWatchersQuery($instance)
55
	{
56
		$this->withColumn('user.name', 'userName');
57
		$this->withColumn('SUM((julianday(subscription.stopped) - julianday(subscription.started)) * 86400)',
58
			'totalTimeSeconds');
59
60
		$this->select(['userName', 'totalTimeSeconds']);
61
62
		$this->useSubscriptionQuery()->filterByStopped(null, Criteria::NOT_EQUAL)->endUse();
63
		$this->filterByInstance($instance);
64
65
		$this->groupBy('userName');
66
		$this->orderBy('totalTimeSeconds', Criteria::DESC);
67
68
		return $this;
69
	}
70
71
}
72