Completed
Push — master ( f4f098...90bd67 )
by Matthew
17:19
created

LiveJobsGridSource   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 33
c 0
b 0
f 0
dl 0
loc 80
ccs 41
cts 41
cp 1
rs 10
wmc 15

9 Methods

Rating   Name   Duplication   Size   Complexity  
A isRunning() 0 3 1
A getRunningQueryBuilder() 0 11 1
A getQueryBuilder() 0 10 2
A setColumns() 0 11 4
A setRunning() 0 3 1
A getId() 0 3 2
A getColumns() 0 6 2
A getDefaultSort() 0 3 1
A __construct() 0 7 1
1
<?php
2
3
namespace Dtc\QueueBundle\ODM;
4
5
use Doctrine\ODM\MongoDB\DocumentManager;
6
use Dtc\GridBundle\Grid\Column\GridColumn;
7
use Dtc\GridBundle\Grid\Source\ColumnExtractionTrait;
8
use Dtc\GridBundle\Grid\Source\DocumentGridSource;
9
use Dtc\QueueBundle\Model\BaseJob;
10
11
class LiveJobsGridSource extends DocumentGridSource
12
{
13
    protected $jobManager;
14
    protected $running = false;
15 1
16
    use ColumnExtractionTrait;
0 ignored issues
show
Deprecated Code introduced by
The trait Dtc\GridBundle\Grid\Source\ColumnExtractionTrait has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

16
    use /** @scrutinizer ignore-deprecated */ ColumnExtractionTrait;

This trait has been deprecated. The supplier of the trait has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the trait will be removed and what other trait to use instead.

Loading history...
introduced by
The trait Dtc\GridBundle\Grid\Source\ColumnExtractionTrait requires some properties which are not provided by Dtc\QueueBundle\ODM\LiveJobsGridSource: $sortable, $label, $direction, $searchable, $order, $actions, $column, $route, $sort
Loading history...
17 1
18
    public function getId()
19
    {
20 7
        return 'dtc_queue.grid_source.jobs_'.($this->isRunning() ? 'running' : 'waiting').'.odm';
21
    }
22 7
23 7
    public function setRunning($flag)
24
    {
25 2
        $this->running = $flag;
26
    }
27 2
28
    public function isRunning()
29
    {
30 1
        return $this->running;
31
    }
32
33 1
    protected function getRunningQueryBuilder()
34 1
    {
35 1
        /** @var DocumentManager $documentManager */
36 1
        $documentManager = $this->jobManager->getObjectManager();
37 1
        $builder = $documentManager->createQueryBuilder($this->jobManager->getJobClass());
38 1
        $builder->field('status')->equals(BaseJob::STATUS_RUNNING);
39
        $builder->sort('startedAt', 'desc');
40 1
        $builder->limit($this->limit);
41
        $builder->skip($this->offset);
42
43 7
        return $builder;
44
    }
45 7
46
    public function __construct(JobManager $jobManager)
47
    {
48 7
        $this->jobManager = $jobManager;
49 7
50 7
        /** @var DocumentManager $documentManager */
51
        $documentManager = $jobManager->getObjectManager();
52 2
        parent::__construct($documentManager, $jobManager->getJobClass());
53
    }
54 2
55 1
    public function setColumns($columns)
56
    {
57 2
        if ($columns) {
58
            foreach ($columns as $column) {
59 2
                if ($column instanceof GridColumn) {
60
                    $column->setOption('sortable', false);
61
                }
62 2
            }
63
        }
64 2
65 2
        parent::setColumns($columns);
66 2
    }
67 2
68 2
    public function getColumns() {
69
        if ($columns = parent::getColumns()) {
70
            return $columns;
71
        }
72 2
        $this->autoDiscoverColumns();
73
        return parent::getColumns();
74 2
    }
75
76 2
    public function getDefaultSort()
77
    {
78
        return null;
79 1
    }
80
81 1
    protected function getQueryBuilder()
82 1
    {
83
        if ($this->isRunning()) {
84 1
            return $this->getRunningQueryBuilder();
85 1
        }
86 1
        $builder = $this->jobManager->getJobQueryBuilder();
87
        $builder->limit($this->limit);
88 1
        $builder->skip($this->offset);
89
90
        return $builder;
91
    }
92
}
93