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
|
|
|
private $columnSource; |
16
|
|
|
|
17
|
|
|
use ColumnExtractionTrait; |
|
|
|
|
18
|
|
|
|
19
|
1 |
|
public function getId() |
20
|
|
|
{ |
21
|
1 |
|
return 'dtc_queue.grid_source.jobs_'.($this->isRunning() ? 'running' : 'waiting').'.odm'; |
22
|
|
|
} |
23
|
|
|
|
24
|
7 |
|
public function setRunning($flag) |
25
|
|
|
{ |
26
|
7 |
|
$this->running = $flag; |
27
|
7 |
|
} |
28
|
|
|
|
29
|
2 |
|
public function isRunning() |
30
|
|
|
{ |
31
|
2 |
|
return $this->running; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function setColumnSource(\Dtc\GridBundle\Grid\Source\ColumnSource $columnSource) |
35
|
|
|
{ |
36
|
|
|
$this->columnSource = $columnSource; |
37
|
|
|
} |
38
|
|
|
|
39
|
1 |
|
protected function getRunningQueryBuilder() |
40
|
|
|
{ |
41
|
|
|
/** @var DocumentManager $documentManager */ |
42
|
1 |
|
$documentManager = $this->jobManager->getObjectManager(); |
43
|
1 |
|
$builder = $documentManager->createQueryBuilder($this->jobManager->getJobClass()); |
44
|
1 |
|
$builder->field('status')->equals(BaseJob::STATUS_RUNNING); |
45
|
1 |
|
$builder->sort('startedAt', 'desc'); |
46
|
1 |
|
$builder->limit($this->limit); |
47
|
1 |
|
$builder->skip($this->offset); |
48
|
|
|
|
49
|
1 |
|
return $builder; |
50
|
|
|
} |
51
|
|
|
|
52
|
7 |
|
public function __construct(JobManager $jobManager) |
53
|
|
|
{ |
54
|
7 |
|
$this->jobManager = $jobManager; |
55
|
|
|
|
56
|
|
|
/** @var DocumentManager $documentManager */ |
57
|
7 |
|
$documentManager = $jobManager->getObjectManager(); |
58
|
7 |
|
parent::__construct($documentManager, $jobManager->getJobClass()); |
59
|
7 |
|
} |
60
|
|
|
|
61
|
2 |
|
public function setColumns($columns) |
62
|
|
|
{ |
63
|
2 |
|
if ($columns) { |
64
|
2 |
|
foreach ($columns as $column) { |
65
|
2 |
|
if ($column instanceof GridColumn) { |
66
|
2 |
|
$column->setOption('sortable', false); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
2 |
|
parent::setColumns($columns); |
72
|
2 |
|
} |
73
|
|
|
|
74
|
2 |
|
public function getColumns() |
75
|
|
|
{ |
76
|
2 |
|
if ($columns = parent::getColumns()) { |
77
|
1 |
|
return $columns; |
78
|
|
|
} |
79
|
|
|
|
80
|
2 |
|
if (!$this->columnSource) { |
81
|
2 |
|
$this->autoDiscoverColumns(); |
82
|
|
|
|
83
|
2 |
|
return parent::getColumns(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$columnSourceInfo = $this->columnSource->getColumnSourceInfo($this->objectManager, 'Dtc\QueueBundle\Document\Job', false); |
87
|
|
|
$this->setColumns($columnSourceInfo->columns); |
88
|
|
|
$this->setDefaultSort($columnSourceInfo->sort); |
89
|
|
|
$this->setIdColumn($columnSourceInfo->idColumn); |
90
|
|
|
|
91
|
|
|
return parent::getColumns(); |
92
|
|
|
} |
93
|
|
|
|
94
|
2 |
|
public function getDefaultSort() |
95
|
|
|
{ |
96
|
2 |
|
return null; |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
protected function getQueryBuilder() |
100
|
|
|
{ |
101
|
1 |
|
if ($this->isRunning()) { |
102
|
1 |
|
return $this->getRunningQueryBuilder(); |
103
|
|
|
} |
104
|
1 |
|
$builder = $this->jobManager->getJobQueryBuilder(); |
105
|
1 |
|
$builder->limit($this->limit); |
106
|
1 |
|
$builder->skip($this->offset); |
107
|
|
|
|
108
|
1 |
|
return $builder; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
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.