This repository has been archived by the owner on Nov 2, 2022. It is now read-only.
/
UserQuery.php
71 lines (54 loc) · 1.58 KB
/
UserQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Jalle19\StatusManager\Database;
use Jalle19\StatusManager\Database\Base\UserQuery as BaseUserQuery;
use Propel\Runtime\ActiveQuery\Criteria;
/**
* @package Jalle19\StatusManager\Database
* @copyright Copyright © Sam Stenvall 2015-
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0
*/
class UserQuery extends BaseUserQuery
{
use LimitTrait;
/**
* @param string $instanceName
* @param string $userName
*
* @return bool
*/
public function hasUser($instanceName, $userName)
{
return $this->filterByInstanceName($instanceName)->filterByName($userName)->findOne() !== null;
}
/**
* @param array $ignoredUsers
*
* @return UserQuery
*/
public function filterIgnoredUsers(array $ignoredUsers)
{
// Always ignore system users
$ignoredUsers[] = User::NAME_DVR;
foreach ($ignoredUsers as $ignoredUser)
$this->filterByName($ignoredUser, Criteria::NOT_EQUAL);
return $this;
}
/**
* @param Instance $instance
*
* @return UserQuery
* @throws \Propel\Runtime\Exception\PropelException
*/
public function getMostActiveWatchersQuery($instance)
{
$this->withColumn('user.name', 'userName');
$this->withColumn('SUM((julianday(subscription.stopped) - julianday(subscription.started)) * 86400)',
'totalTimeSeconds');
$this->select(['userName', 'totalTimeSeconds']);
$this->useSubscriptionQuery()->filterByStopped(null, Criteria::NOT_EQUAL)->endUse();
$this->filterByInstance($instance);
$this->groupBy('userName');
$this->orderBy('totalTimeSeconds', Criteria::DESC);
return $this;
}
}