private function __construct()
 {
     try {
         $this->id = session_id();
         $this->database = Database::singleton();
         // AMPERSAND SESSION
         Concept::getConcept('SESSION');
         // Remove expired Ampersand sessions from __SessionTimeout__ and all concept tables and relations where it appears.
         $expiredSessionsAtoms = array_column($this->database->Exe("SELECT SESSION FROM `__SessionTimeout__` WHERE `lastAccess` < " . (time() - Config::get('sessionExpirationTime'))), 'SESSION');
         foreach ($expiredSessionsAtoms as $expiredSessionAtom) {
             $this->destroyAmpersandSession($expiredSessionAtom);
         }
         // Create a new Ampersand session if session_id() is not in SESSION table (browser started a new session or Ampersand session was expired
         $sessionAtom = new Atom($this->id, 'SESSION');
         if (!$sessionAtom->atomExists()) {
             $this->database->addAtomToConcept($this->id, 'SESSION');
             $this->database->commitTransaction();
             //TODO: ook door Database->closeTransaction() laten doen, maar die verwijst terug naar Session class voor de checkrules. Oneindige loop
         }
         $this->database->Exe("INSERT INTO `__SessionTimeout__` (`SESSION`,`lastAccess`) VALUES ('" . $this->id . "', '" . time() . "') ON DUPLICATE KEY UPDATE `lastAccess` = '" . time() . "'");
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemple #2
0
 /**
  * @url GET resource/{concept}/{atomId}
  * @param string $concept
  * @param string $atomId
  * @param array $roleIds
  */
 public function getConceptAtom($concept, $atomId, $roleIds = null)
 {
     try {
         $session = Session::singleton();
         $session->activateRoles($roleIds);
         if (!in_array($concept, $session->getEditableConcepts())) {
             throw new Exception("You do not have access for this call", 403);
         }
         $atom = new Atom($atomId, $concept);
         if (!$atom->atomExists()) {
             throw new Exception("Resource '{$atomId}' not found", 404);
         }
         return $atom->getAtom();
     } catch (Exception $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     }
 }
Exemple #3
0
 /**
  * @url GET resource/{concept}/{atomId}
  */
 public function getConceptAtom($concept, $atomId)
 {
     try {
         // If login is enabled, check if users may request all atoms.
         if (Config::get('loginEnabled')) {
             $editableConcepts = array();
             $roles = Role::getAllSessionRoles();
             foreach ($roles as $role) {
                 $editableConcepts = array_merge($editableConcepts, $role->editableConcepts);
             }
             if (!in_array($concept, $editableConcepts)) {
                 throw new Exception("You do not have access for this call", 403);
             }
         }
         $atom = new Atom($atomId, $concept);
         if (!$atom->atomExists()) {
             throw new Exception("Resource '{$atomId}' not found", 404);
         }
         return $atom->getAtom();
     } catch (Exception $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     }
 }