MatchActivityQueryBuilder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B includeMatchActivity() 0 28 2
1
<?php
2
3
/**
4
 * @property BaseModel $type
5
 */
6
class MatchActivityQueryBuilder extends QueryBuilder
7
{
8
    protected function includeMatchActivity($selectColumns, $leftJoinOn, $useMatchParticipationTable = false)
9
    {
10
        $type = $this->type;
11
        $columns = $type::getEagerColumns($this->getFromAlias());
12
13
        $this->columns['activity'] = 'activity';
14
        $this->extraColumns = 'SUM(m2.activity) AS activity';
15
        $this->extras .= '
16
          LEFT JOIN
17
            (SELECT
18
              m.id,'
19
              . implode(',', $selectColumns) . ',
20
              TIMESTAMPDIFF(SECOND, timestamp, NOW()) / 86400 AS days_passed,
21
              (0.0116687059537612 * (POW((45 - LEAST((SELECT days_passed), 45)), (1/6)) + ATAN(31 - (SELECT days_passed)) / 2)) AS activity
22
            FROM
23
              matches m' .
24
            ($useMatchParticipationTable ? ' INNER JOIN match_participation mp ON m.id = mp.match_id ' : '')
25
            . '
26
            WHERE
27
              DATEDIFF(NOW(), timestamp) <= 45
28
            ORDER BY
29
              timestamp DESC) m2 ON ' . $leftJoinOn
30
        ;
31
32
        $this->groupQuery = 'GROUP BY ' . $columns;
33
34
        return $this;
35
    }
36
}
37