Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
| DeliveryThemeDetailsProvider | |
0.00% |
0 / 33 |
|
0.00% |
0 / 10 |
306 | |
0.00% |
0 / 1 |
| getThemeId | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| isHeadless | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDeliveryIdFromSession | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getDeliveryThemeId | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| getDeliveryThemeIdFromCache | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| getDeliveryThemeIdFromDb | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| storeDeliveryThemeIdToCache | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getCacheKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDeliveryIdSessionKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCache | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoDelivery\models\classes\theme; |
| 23 | |
| 24 | use oat\oatbox\PhpSerializable; |
| 25 | use oat\oatbox\PhpSerializeStateless; |
| 26 | use oat\oatbox\service\ServiceManager; |
| 27 | use oat\tao\model\theme\ThemeDetailsProviderInterface; |
| 28 | |
| 29 | /** |
| 30 | * Class DeliveryThemeDetailsProvider |
| 31 | * |
| 32 | * @package oat\taoDelivery\models\classes\theme |
| 33 | * @deprecated It was moved to oat\taoDeliveryRdf\model\theme\DeliveryThemeDetailsProvider |
| 34 | */ |
| 35 | class DeliveryThemeDetailsProvider extends \Actions implements ThemeDetailsProviderInterface, PhpSerializable |
| 36 | { |
| 37 | use PhpSerializeStateless; |
| 38 | |
| 39 | |
| 40 | /** |
| 41 | * The delivery theme id uri. |
| 42 | */ |
| 43 | public const DELIVERY_THEME_ID_URI = 'http://www.tao.lu/Ontologies/TAODelivery.rdf#ThemeName'; |
| 44 | |
| 45 | /** |
| 46 | * @inheritdoc |
| 47 | */ |
| 48 | public function getThemeId() |
| 49 | { |
| 50 | |
| 51 | $deliveryExecutionId = \tao_helpers_Uri::decode($this->getRequestParameter('deliveryExecution')); |
| 52 | |
| 53 | $themeId = ''; |
| 54 | if (!empty($deliveryExecutionId)) { |
| 55 | $deliveryId = $this->getDeliveryIdFromSession($deliveryExecutionId); |
| 56 | if ($deliveryId !== false) { |
| 57 | $themeId = $this->getDeliveryThemeId($deliveryId); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return $themeId; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Tells if the page has to be headless: without header and footer. |
| 66 | * |
| 67 | * @return bool|mixed |
| 68 | */ |
| 69 | public function isHeadless() |
| 70 | { |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Returns the deliveryId from session. |
| 76 | * |
| 77 | * @param $deliveryExecutionId |
| 78 | * |
| 79 | * @return mixed |
| 80 | */ |
| 81 | public function getDeliveryIdFromSession($deliveryExecutionId) |
| 82 | { |
| 83 | if (\PHPSession::singleton()->hasAttribute(static::getDeliveryIdSessionKey($deliveryExecutionId))) { |
| 84 | return \PHPSession::singleton()->getAttribute(static::getDeliveryIdSessionKey($deliveryExecutionId)); |
| 85 | } |
| 86 | |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Returns the delivery theme id. |
| 92 | * |
| 93 | * @param $deliveryId |
| 94 | * |
| 95 | * @return string |
| 96 | */ |
| 97 | public function getDeliveryThemeId($deliveryId) |
| 98 | { |
| 99 | $themeId = $this->getDeliveryThemeIdFromCache($deliveryId); |
| 100 | if ($themeId === false) { |
| 101 | $themeId = $this->getDeliveryThemeIdFromDb($deliveryId); |
| 102 | $this->storeDeliveryThemeIdToCache($deliveryId, $themeId); |
| 103 | } |
| 104 | |
| 105 | return $themeId; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns the delivery theme id from cache or FALSE when it does not exist. |
| 110 | * |
| 111 | * @param $deliveryId |
| 112 | * |
| 113 | * @return bool|\common_Serializable |
| 114 | */ |
| 115 | public function getDeliveryThemeIdFromCache($deliveryId) |
| 116 | { |
| 117 | $cache = $this->getCache(); |
| 118 | $cacheKey = $this->getCacheKey($deliveryId); |
| 119 | if ($cache->has($cacheKey)) { |
| 120 | return $cache->get($cacheKey); |
| 121 | } |
| 122 | |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Returns delivery theme id from database. |
| 128 | * |
| 129 | * @param $deliveryId |
| 130 | * |
| 131 | * @return string |
| 132 | */ |
| 133 | public function getDeliveryThemeIdFromDb($deliveryId) |
| 134 | { |
| 135 | try { |
| 136 | $delivery = new \core_kernel_classes_Resource($deliveryId); |
| 137 | |
| 138 | $property = $delivery->getProperty(static::DELIVERY_THEME_ID_URI); |
| 139 | $themeId = (string)$delivery->getOnePropertyValue($property); |
| 140 | |
| 141 | return $themeId; |
| 142 | } catch (\common_exception_Error $e) { |
| 143 | return ''; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Stores the delivery theme id to cache. |
| 149 | * |
| 150 | * @param $deliveryId |
| 151 | * @param $themeId |
| 152 | * |
| 153 | * @return bool |
| 154 | */ |
| 155 | public function storeDeliveryThemeIdToCache($deliveryId, $themeId) |
| 156 | { |
| 157 | try { |
| 158 | return $this->getCache()->put($themeId, $this->getCacheKey($deliveryId), 60); |
| 159 | } catch (\common_exception_NotImplemented $e) { |
| 160 | return false; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Returns the cache key. |
| 166 | * |
| 167 | * @param $deliveryId |
| 168 | * |
| 169 | * @return string |
| 170 | */ |
| 171 | public function getCacheKey($deliveryId) |
| 172 | { |
| 173 | return 'deliveryThemeId:' . $deliveryId; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Returns the delivery id session key. |
| 178 | * |
| 179 | * @param $deliveryExecutionId |
| 180 | * |
| 181 | * @return string |
| 182 | */ |
| 183 | public static function getDeliveryIdSessionKey($deliveryExecutionId) |
| 184 | { |
| 185 | return 'deliveryIdForDeliveryExecution:' . $deliveryExecutionId; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Returns the cache instance. |
| 190 | * |
| 191 | * @return \common_cache_Cache |
| 192 | */ |
| 193 | public function getCache() |
| 194 | { |
| 195 | return ServiceManager::getServiceManager()->get(\common_cache_Cache::SERVICE_ID); |
| 196 | } |
| 197 | } |