| 1 | <?php |
||
| 2 | namespace EWW\Dpf\Session; |
||
| 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 | class Session |
||
| 18 | { |
||
| 19 | const ROOT_KEY = "tx_dpf"; |
||
| 20 | const LIST_ACTION_KEY = "list_action"; |
||
| 21 | const WORKSPACE = "workspace"; |
||
| 22 | const BULKIMPORT = "bulkimport"; |
||
| 23 | |||
| 24 | |||
| 25 | /** |
||
| 26 | * @return SearchSessionData $data |
||
| 27 | */ |
||
| 28 | public function getWorkspaceData() |
||
| 29 | { |
||
| 30 | $sessionData = $this->getData(); |
||
| 31 | if (array_key_exists(self::WORKSPACE, $sessionData)) { |
||
| 32 | return unserialize($sessionData[self::WORKSPACE]); |
||
| 33 | } |
||
| 34 | |||
| 35 | return new SearchSessionData(); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param SearchSessionData $data |
||
| 40 | */ |
||
| 41 | public function setWorkspaceData(SearchSessionData $data) |
||
| 42 | { |
||
| 43 | $sessionData[self::WORKSPACE] = serialize($data); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 44 | $this->setData($sessionData); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @return BulkImportSessionData |
||
| 49 | */ |
||
| 50 | public function getBulkImportData() |
||
| 51 | { |
||
| 52 | $sessionData = $this->getData(); |
||
| 53 | if (array_key_exists(self::BULKIMPORT, $sessionData)) { |
||
| 54 | return unserialize($sessionData[self::BULKIMPORT]); |
||
| 55 | } |
||
| 56 | |||
| 57 | return new BulkImportSessionData(); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param BulkImportSessionData $data |
||
| 62 | */ |
||
| 63 | public function setBulkImportData(BulkImportSessionData $data) |
||
| 64 | { |
||
| 65 | $sessionData = $this->getData(); |
||
| 66 | $sessionData[self::BULKIMPORT] = serialize($data); |
||
| 67 | $this->setData($sessionData); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Stores the given action name, controller name and uri. |
||
| 72 | * |
||
| 73 | * @param $action |
||
| 74 | * @param $controller |
||
| 75 | */ |
||
| 76 | public function setStoredAction($action, $controller, $uri = null) |
||
| 77 | { |
||
| 78 | $sessionData = $this->getData(); |
||
| 79 | $sessionData[self::LIST_ACTION_KEY] = [$action, $controller, $uri]; |
||
| 80 | $this->setData($sessionData); |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Returns the stored action name, controller name and uri. |
||
| 85 | * [ 0 => 'action name', 1 => 'controller name', 2 => 'uri'] |
||
| 86 | * |
||
| 87 | * @return array|mixed |
||
| 88 | */ |
||
| 89 | public function getStoredAction() |
||
| 90 | { |
||
| 91 | $sessionData = $this->getData(); |
||
| 92 | if (is_array($sessionData) && array_key_exists(self::LIST_ACTION_KEY, $sessionData)) { |
||
| 93 | return $sessionData[self::LIST_ACTION_KEY]; |
||
| 94 | } |
||
| 95 | return []; |
||
| 96 | } |
||
| 97 | |||
| 98 | |||
| 99 | /** |
||
| 100 | * Set session data |
||
| 101 | * |
||
| 102 | * @param array $data |
||
| 103 | */ |
||
| 104 | public function setData($data) |
||
| 105 | { |
||
| 106 | $userGlobals = $this->getUserGlobals(); |
||
| 107 | |||
| 108 | if ($userGlobals) { |
||
| 109 | $userGlobals->setAndSaveSessionData(self::ROOT_KEY, $data); |
||
| 110 | } |
||
| 111 | |||
| 112 | return; |
||
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Get session data |
||
| 117 | * |
||
| 118 | * @return array |
||
| 119 | */ |
||
| 120 | public function getData() |
||
| 121 | { |
||
| 122 | $userGlobals = $this->getUserGlobals(); |
||
| 123 | |||
| 124 | $sessionData = null; |
||
| 125 | |||
| 126 | if ($userGlobals) { |
||
| 127 | $sessionData = $userGlobals->getSessionData(self::ROOT_KEY); |
||
| 128 | } |
||
| 129 | |||
| 130 | if ($sessionData && is_array($sessionData)) { |
||
| 131 | return $sessionData; |
||
| 132 | } |
||
| 133 | |||
| 134 | return []; |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Gets the global user object. |
||
| 139 | * |
||
| 140 | * @return mixed|null |
||
| 141 | */ |
||
| 142 | protected function getUserGlobals() |
||
| 143 | { |
||
| 144 | $userGlobals = null; |
||
| 145 | |||
| 146 | if (!empty($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) { |
||
| 147 | |||
| 148 | $userGlobals = $GLOBALS['TSFE']->fe_user; |
||
| 149 | |||
| 150 | } else if (!empty($GLOBALS['BE_USER']) && is_object($GLOBALS['BE_USER'])) { |
||
| 151 | |||
| 152 | $userGlobals = $GLOBALS['BE_USER']; |
||
| 153 | |||
| 154 | } |
||
| 155 | |||
| 156 | return $userGlobals; |
||
| 157 | } |
||
| 158 | |||
| 159 | } |
||
| 160 |