1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use mQueue\Model\Movie; |
4
|
|
|
use mQueue\Model\MovieMapper; |
5
|
|
|
use mQueue\Model\StatusMapper; |
6
|
|
|
use mQueue\Model\User; |
7
|
|
|
use mQueue\Model\UserMapper; |
8
|
|
|
|
9
|
|
|
class StatusController extends Zend_Controller_Action |
10
|
|
|
{ |
11
|
1 |
|
public function init(): void |
12
|
|
|
{ |
13
|
1 |
|
$contextSwitch = $this->_helper->getHelper('contextSwitch'); |
14
|
1 |
|
$contextSwitch->addActionContext('list', 'json') |
|
|
|
|
15
|
1 |
|
->addActionContext('index', 'json') |
16
|
1 |
|
->initContext(); |
17
|
1 |
|
} |
18
|
|
|
|
19
|
1 |
|
public function indexAction(): void |
20
|
|
|
{ |
21
|
1 |
|
$jsonCallback = $this->_request->getParam('jsoncallback'); |
22
|
1 |
|
if ($jsonCallback) { |
23
|
|
|
$this->_helper->layout->setLayout('jsonp'); |
|
|
|
|
24
|
|
|
$this->view->jsonCallback = $jsonCallback; |
25
|
|
|
} |
26
|
|
|
|
27
|
1 |
|
$idMovie = Movie::extractId($this->_request->getParam('movie')); |
28
|
|
|
|
29
|
1 |
|
if ($idMovie == null) { |
|
|
|
|
30
|
1 |
|
throw new Exception('no valid movie specified.'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
// If new rating is specified and we are logged in, save it and create movie if needed |
34
|
1 |
|
$rating = $this->_request->getParam('rating'); |
35
|
1 |
|
if (isset($rating) && User::getCurrent()) { |
36
|
|
|
$movie = MovieMapper::find($idMovie); |
|
|
|
|
37
|
|
|
|
38
|
|
|
if ($movie == null) { |
39
|
|
|
$movie = MovieMapper::getDbTable()->createRow(); |
40
|
|
|
$movie->setId($idMovie); |
41
|
|
|
$movie->save(); |
42
|
|
|
} |
43
|
|
|
$status = $movie->setStatus(User::getCurrent(), $rating); |
44
|
|
|
} else { |
45
|
1 |
|
$status = StatusMapper::find($idMovie, User::getCurrent()); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
if (!$jsonCallback) { |
49
|
1 |
|
$this->view->status = $status; |
50
|
|
|
} else { |
51
|
|
|
$html = $this->view->statusLinks($status); |
52
|
|
|
$this->view->status = $html; |
53
|
|
|
$this->view->id = $status->getUniqueId(); |
|
|
|
|
54
|
|
|
} |
55
|
1 |
|
} |
56
|
|
|
|
57
|
|
|
public function listAction(): void |
58
|
|
|
{ |
59
|
|
|
$jsonCallback = $this->_request->getParam('jsoncallback'); |
60
|
|
|
if ($jsonCallback) { |
61
|
|
|
$this->_helper->layout->setLayout('jsonp'); |
62
|
|
|
$this->view->jsonCallback = $jsonCallback; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$idMovies = []; |
66
|
|
|
foreach (explode(',', trim($this->_request->getParam('movies'), ',')) as $idMovie) { |
|
|
|
|
67
|
|
|
$idMovie = Movie::extractId($idMovie); |
68
|
|
|
if ($idMovie) { |
69
|
|
|
$idMovies[] = $idMovie; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$statuses = StatusMapper::findAll($idMovies, User::getCurrent()); |
74
|
|
|
|
75
|
|
|
$json = []; |
76
|
|
|
foreach ($statuses as $s) { |
77
|
|
|
$html = $this->view->statusLinks($s); |
78
|
|
|
$json[$s->getUniqueId()] = $html; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$this->view->status = $json; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function graphAction(): void |
85
|
|
|
{ |
86
|
|
|
$percent = $this->_request->getParam('percent'); |
87
|
|
|
$user = UserMapper::find($this->getParam('user')); |
88
|
|
|
$data = StatusMapper::getGraph($user, $percent); |
89
|
|
|
$chart = [ |
90
|
|
|
'chart' => [ |
91
|
|
|
'zoomType' => 'x', |
92
|
|
|
], |
93
|
|
|
'title' => [ |
94
|
|
|
'text' => '', |
95
|
|
|
], |
96
|
|
|
'xAxis' => [ |
97
|
|
|
'type' => 'datetime', |
98
|
|
|
], |
99
|
|
|
'yAxis' => [ |
100
|
|
|
'title' => [ |
101
|
|
|
'text' => 'Movies', |
102
|
|
|
], |
103
|
|
|
'min' => 0, |
104
|
|
|
], |
105
|
|
|
'series' => $data, |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
if ($percent) { |
109
|
|
|
$chart['chart']['type'] = 'area'; |
110
|
|
|
$chart['yAxis']['title']['text'] = $chart['yAxis']['title']['text'] . ' [%]'; |
111
|
|
|
$chart['plotOptions'] = [ |
112
|
|
|
'area' => [ |
113
|
|
|
'stacking' => 'percent', |
114
|
|
|
'marker' => [ |
115
|
|
|
'enabled' => false, |
116
|
|
|
], |
117
|
|
|
], |
118
|
|
|
]; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
echo Zend_Json::encode($chart, Zend_Json::TYPE_ARRAY); |
|
|
|
|
122
|
|
|
die(); |
|
|
|
|
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|