[!!!][FEATURE] Introduce PSR-7-based Routing for Backend AJAX Requests
[Packages/TYPO3.CMS.git] / typo3 / sysext / taskcenter / Classes / TaskStatus.php
1 <?php
2 namespace TYPO3\CMS\Taskcenter;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19
20 /**
21 * Status of tasks
22 */
23 class TaskStatus {
24
25 /**
26 * Saves the section toggle state of tasks in the backend user's uc
27 *
28 * @param ServerRequestInterface $request
29 * @param ResponseInterface $response
30 * @return ResponseInterface
31 */
32 public function saveCollapseState(ServerRequestInterface $request, ResponseInterface $response) {
33 // Remove 'el_' in the beginning which is needed for the saveSortingState()
34 $item = isset($request->getParsedBody()['item']) ? $request->getParsedBody()['item'] : $request->getQueryParams()['item'];
35 $item = substr(htmlspecialchars($item), 3);
36 $state = (bool)(isset($request->getParsedBody()['state']) ? $request->getParsedBody()['state'] : $request->getQueryParams()['state']);
37
38 $this->getBackendUserAuthentication()->uc['taskcenter']['states'][$item] = $state;
39 $this->getBackendUserAuthentication()->writeUC();
40
41 return $response;
42 }
43
44 /**
45 * Saves the sorting order of tasks in the backend user's uc
46 *
47 * @param ServerRequestInterface $request
48 * @param ResponseInterface $response
49 * @return ResponseInterface
50 */
51 public function saveSortingState(ServerRequestInterface $request, ResponseInterface $response) {
52 $sort = array();
53 $data = isset($request->getParsedBody()['data']) ? $request->getParsedBody()['data'] : $request->getQueryParams()['data'];
54
55 $items = explode('&', $data);
56 foreach ($items as $item) {
57 $sort[] = substr($item, 12);
58 }
59 $this->getBackendUserAuthentication()->uc['taskcenter']['sorting'] = serialize($sort);
60 $this->getBackendUserAuthentication()->writeUC();
61
62 return $response;
63 }
64
65 /**
66 * Returns BackendUserAuthentication
67 *
68 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
69 */
70 protected function getBackendUserAuthentication() {
71 return $GLOBALS['BE_USER'];
72 }
73
74 }