Completed
Push — master ( 9804ea...45188d )
by Sam
02:27
created

UserQuery   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hasUser() 0 4 1
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
14
{
15
16
	/**
17
	 * @param string $instanceName
18
	 * @param string $userName
19
	 *
20
	 * @return bool
21
	 */
22
	public function hasUser($instanceName, $userName)
23
	{
24
		return $this->filterByInstanceName($instanceName)->filterByName($userName)->findOne() !== null;
25
	}
26
27
28
	/**
29
	 * @param Instance $instance
30
	 *
31
	 * @return UserQuery
32
	 * @throws \Propel\Runtime\Exception\PropelException
33
	 */
34
	public function getMostActiveWatchersQuery($instance)
35
	{
36
		$this->withColumn('user.name', 'userName');
37
		$this->withColumn('SUM((julianday(subscription.stopped) - julianday(subscription.started)) * 86400)',
38
			'totalTimeSeconds');
39
40
		$this->select(['userName', 'totalTimeSeconds']);
41
42
		$this->useSubscriptionQuery()->filterByStopped(null, Criteria::NOT_EQUAL)->endUse();
43
		$this->filterByInstance($instance);
44
45
		$this->groupBy('userName');
46
		$this->orderBy('totalTimeSeconds', Criteria::DESC);
47
48
		return $this;
49
	}
50
51
}
52