Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| TaoCe | |
0.00% |
0 / 35 |
|
0.00% |
0 / 4 |
110 | |
0.00% |
0 / 1 |
| isFirstTimeInTao | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| becomeVeteran | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| getLastVisitedUrl | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| setLastVisitedUrl | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
20 | |||
| 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) 2014 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\tao\helpers; |
| 24 | |
| 25 | use common_Exception; |
| 26 | use common_session_SessionManager; |
| 27 | use core_kernel_classes_Resource; |
| 28 | use core_kernel_classes_Property; |
| 29 | use oat\generis\model\GenerisRdf; |
| 30 | use oat\tao\model\TaoOntology; |
| 31 | |
| 32 | /** |
| 33 | * Helper for TaoCe related operations |
| 34 | * |
| 35 | * @author Joel Bout <joel@taotesting.com> |
| 36 | * @package taoCe |
| 37 | * @license GPL-2.0 |
| 38 | * |
| 39 | */ |
| 40 | class TaoCe |
| 41 | { |
| 42 | /** |
| 43 | * Check whether the current user has already been connected to the TAO backend. |
| 44 | * |
| 45 | * @return boolean true if this is the first time |
| 46 | */ |
| 47 | public static function isFirstTimeInTao() |
| 48 | { |
| 49 | $firstTime = common_session_SessionManager::getSession()->getUserPropertyValues( |
| 50 | TaoOntology::PROPERTY_USER_FIRST_TIME |
| 51 | ); |
| 52 | |
| 53 | //for compatibility purpose we assume previous users are veterans |
| 54 | return in_array(GenerisRdf::GENERIS_TRUE, $firstTime); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * The user knows TAO, he's now a veteran, the TaoOntology::PROPERTY_USER_FIRST_TIME property can be false |
| 59 | * (except if $notYet is true). |
| 60 | * |
| 61 | * @param core_kernel_classes_Resource $user a user or the current user if null/not set |
| 62 | * @param boolean $notYet our veteran want to be still considered as a noob... |
| 63 | */ |
| 64 | public static function becomeVeteran() |
| 65 | { |
| 66 | $success = false; |
| 67 | |
| 68 | $userUri = common_session_SessionManager::getSession()->getUserUri(); |
| 69 | if (!empty($userUri)) { |
| 70 | $user = new \core_kernel_classes_Resource($userUri); |
| 71 | if ($user->exists()) { |
| 72 | // user in ontology |
| 73 | $success = $user->editPropertyValues( |
| 74 | new core_kernel_classes_Property(TaoOntology::PROPERTY_USER_FIRST_TIME), |
| 75 | new core_kernel_classes_Resource(GenerisRdf::GENERIS_FALSE) |
| 76 | ); |
| 77 | } // else we fail; |
| 78 | } |
| 79 | return $success; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | /** |
| 84 | * Get the URL of the last visited extension |
| 85 | * @param core_kernel_classes_Resource $user a user or the current user if null/not set (optional) |
| 86 | * @return string the url or null |
| 87 | */ |
| 88 | public static function getLastVisitedUrl() |
| 89 | { |
| 90 | $urls = common_session_SessionManager::getSession()->getUserPropertyValues( |
| 91 | TaoOntology::PROPERTY_USER_LAST_EXTENSION |
| 92 | ); |
| 93 | if (!empty($urls)) { |
| 94 | $lastUrl = current($urls); |
| 95 | return ROOT_URL . $lastUrl; |
| 96 | } else { |
| 97 | return null; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Set the URL of the last visited extension to a user. |
| 103 | * @param string $url a non empty URL where the user was the last time |
| 104 | * @param core_kernel_classes_Resource $user a user or the current user if null/not set (optional) |
| 105 | * @throws common_Exception |
| 106 | */ |
| 107 | public static function setLastVisitedUrl($url) |
| 108 | { |
| 109 | if (empty($url)) { |
| 110 | throw new common_Exception('Cannot register an empty URL for the last visited extension'); |
| 111 | } |
| 112 | $success = false; |
| 113 | |
| 114 | $userUri = common_session_SessionManager::getSession()->getUserUri(); |
| 115 | if (!empty($userUri)) { |
| 116 | $user = new \core_kernel_classes_Resource($userUri); |
| 117 | $user = new core_kernel_classes_Resource($userUri); |
| 118 | if ($user->exists()) { |
| 119 | // user in ontology |
| 120 | |
| 121 | //clean up what's stored |
| 122 | $url = str_replace(ROOT_URL, '', $url); |
| 123 | $success = $user->editPropertyValues( |
| 124 | new core_kernel_classes_Property(TaoOntology::PROPERTY_USER_LAST_EXTENSION), |
| 125 | $url |
| 126 | ); |
| 127 | } // else we fail; |
| 128 | } |
| 129 | return $success; |
| 130 | } |
| 131 | } |