1 | <?php |
||
25 | class StorageController extends BaseController |
||
26 | { |
||
27 | /** |
||
28 | * Link to guide, how add a new storage. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | const GUIDE_LINK = '/guide/storage/add.html'; |
||
33 | |||
34 | /** |
||
35 | * Storage list. |
||
36 | * |
||
37 | * @param Request $request |
||
38 | * |
||
39 | * @return Response |
||
40 | */ |
||
41 | public function listAction(Request $request) |
||
42 | { |
||
43 | $response = $this->getCacheTimeKeeper()->getResponse('AnimeDbCatalogBundle:Storage'); |
||
44 | // response was not modified for this request |
||
45 | if ($response->isNotModified($request)) { |
||
46 | return $response; |
||
47 | } |
||
48 | |||
49 | /* @var $rep StorageRepository */ |
||
50 | $rep = $this->getDoctrine()->getRepository('AnimeDbCatalogBundle:Storage'); |
||
51 | |||
52 | return $this->render('AnimeDbCatalogBundle:Storage:list.html.twig', [ |
||
53 | 'storages' => $rep->getList(), |
||
54 | ], $response); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Change storage. |
||
59 | * |
||
60 | * @param Storage $storage |
||
61 | * @param Request $request |
||
62 | * |
||
63 | * @return Response |
||
64 | */ |
||
65 | public function changeAction(Storage $storage, Request $request) |
||
66 | { |
||
67 | $response = $this->getCacheTimeKeeper()->getResponse($storage->getDateUpdate()); |
||
68 | // response was not modified for this request |
||
69 | if ($response->isNotModified($request)) { |
||
70 | return $response; |
||
71 | } |
||
72 | |||
73 | /* @var $form Form */ |
||
74 | $form = $this->createForm(new StorageForm(), $storage); |
||
75 | |||
76 | if ($request->getMethod() == 'POST') { |
||
77 | $form->handleRequest($request); |
||
78 | if ($form->isValid()) { |
||
79 | $em = $this->getDoctrine()->getManager(); |
||
80 | $em->persist($storage); |
||
81 | $em->flush(); |
||
82 | |||
83 | return $this->redirect($this->generateUrl('storage_list')); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | return $this->render('AnimeDbCatalogBundle:Storage:change.html.twig', [ |
||
88 | 'storage' => $storage, |
||
89 | 'form' => $form->createView(), |
||
90 | ], $response); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Add storage. |
||
95 | * |
||
96 | * @param Request $request |
||
97 | * |
||
98 | * @return Response |
||
99 | */ |
||
100 | public function addAction(Request $request) |
||
101 | { |
||
102 | $storage = new Storage(); |
||
103 | |||
104 | /* @var $form Form */ |
||
105 | $form = $this->createForm(new StorageForm(), $storage); |
||
106 | |||
107 | if ($request->getMethod() == 'POST') { |
||
108 | $form->handleRequest($request); |
||
109 | if ($form->isValid()) { |
||
110 | $em = $this->getDoctrine()->getManager(); |
||
111 | $em->persist($storage); |
||
112 | $em->flush(); |
||
113 | |||
114 | return $this->redirect($this->generateUrl('storage_list')); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | return $this->render('AnimeDbCatalogBundle:Storage:add.html.twig', [ |
||
119 | 'form' => $form->createView(), |
||
120 | 'guide' => $this->get('anime_db.api.client')->getSiteUrl(self::GUIDE_LINK), |
||
121 | ]); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Delete storage. |
||
126 | * |
||
127 | * @param Storage $storage |
||
128 | * |
||
129 | * @return Response |
||
130 | */ |
||
131 | public function deleteAction(Storage $storage) |
||
139 | |||
140 | /** |
||
141 | * Get storage path. |
||
142 | * |
||
143 | * @param Request $request |
||
144 | * |
||
145 | * @return Response |
||
146 | */ |
||
147 | public function getPathAction(Request $request) |
||
166 | |||
167 | /** |
||
168 | * Scan storage. |
||
169 | * |
||
170 | * @param Storage $storage |
||
171 | * |
||
172 | * @return Response |
||
173 | */ |
||
174 | public function scanAction(Storage $storage) |
||
182 | |||
183 | /** |
||
184 | * Get storage scan output. |
||
185 | * |
||
186 | * @param Storage $storage |
||
187 | * @param Request $request |
||
188 | * |
||
189 | * @return JsonResponse |
||
190 | */ |
||
191 | public function scanOutputAction(Storage $storage, Request $request) |
||
221 | |||
222 | /** |
||
223 | * Get storage scan progress. |
||
224 | * |
||
225 | * @param Storage $storage |
||
226 | * |
||
227 | * @return JsonResponse |
||
228 | */ |
||
229 | public function scanProgressAction(Storage $storage) |
||
241 | } |
||
242 |