* @package taoCe * @license GPL-2.0 * */ class TaoCe { /** * Check whether the current user has already been connected to the TAO backend. * * @return boolean true if this is the first time */ public static function isFirstTimeInTao() { $firstTime = common_session_SessionManager::getSession()->getUserPropertyValues(TaoOntology::PROPERTY_USER_FIRST_TIME); //for compatibility purpose we assume previous users are veterans return in_array(GenerisRdf::GENERIS_TRUE, $firstTime); } /** * The user knows TAO, he's now a veteran, the TaoOntology::PROPERTY_USER_FIRST_TIME property can be false (except if $notYet is true). * * @param core_kernel_classes_Resource $user a user or the current user if null/not set * @param boolean $notYet our veteran want to be still considered as a noob... */ public static function becomeVeteran() { $success = false; $userUri = common_session_SessionManager::getSession()->getUserUri(); if (!empty($userUri)) { $user = new \core_kernel_classes_Resource($userUri); if ($user->exists()) { // user in ontology $success = $user->editPropertyValues( new core_kernel_classes_Property(TaoOntology::PROPERTY_USER_FIRST_TIME), new core_kernel_classes_Resource(GenerisRdf::GENERIS_FALSE) ); } // else we fail; } return $success; } /** * Get the URL of the last visited extension * @param core_kernel_classes_Resource $user a user or the current user if null/not set (optional) * @return string the url or null */ public static function getLastVisitedUrl() { $urls = common_session_SessionManager::getSession()->getUserPropertyValues(TaoOntology::PROPERTY_USER_LAST_EXTENSION); if (!empty($urls)) { $lastUrl = current($urls); return ROOT_URL . $lastUrl; } else { return null; } } /** * Set the URL of the last visited extension to a user. * @param string $url a non empty URL where the user was the last time * @param core_kernel_classes_Resource $user a user or the current user if null/not set (optional) * @throws common_Exception */ public static function setLastVisitedUrl($url) { if (empty($url)) { throw new common_Exception('Cannot register an empty URL for the last visited extension'); } $success = false; $userUri = common_session_SessionManager::getSession()->getUserUri(); if (!empty($userUri)) { $user = new \core_kernel_classes_Resource($userUri); $user = new core_kernel_classes_Resource($userUri); if ($user->exists()) { // user in ontology //clean up what's stored $url = str_replace(ROOT_URL, '', $url); $success = $user->editPropertyValues(new core_kernel_classes_Property(TaoOntology::PROPERTY_USER_LAST_EXTENSION), $url); } // else we fail; } return $success; } }