}
    // Get list of all atoms for $resourceType (i.e. concept)
    $content = $concept->getAllAtomObjects();
    print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
$app->get('/resources/:resourceType/:resourceId', function ($resourceType, $resourceId) use($app) {
    $session = Session::singleton();
    $roleIds = $app->request->params('roleIds');
    $session->activateRoles($roleIds);
    $resource = new Atom($resourceId, Concept::getConcept($resourceType));
    // Checks
    if (!$session->isEditableConcept($resource->concept)) {
        throw new Exception("You do not have access for this call", 403);
    }
    // Get specific resource (i.e. atom)
    if (!$resource->atomExists()) {
        throw new Exception("Resource '{$resource->__toString()}' not found", 404);
    }
    $content = $resource->getAtom();
    print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
/**************************************************************************************************
 *
 * resource calls WITH interfaces
 *
 *************************************************************************************************/
$app->get('/resources/:resourceType/:resourceId/:ifcPath+', function ($resourceType, $resourceId, $ifcPath) use($app) {
    $session = Session::singleton();
    $roleIds = $app->request->params('roleIds');
    $session->activateRoles($roleIds);
    $options = $app->request->params();
 /**
  * Add (src,tgt) tuple in relation provided in this interface
  * @var array $patch
  * @throws Exception
  * @return void
  */
 public function doPatchAdd($patch)
 {
     // CRUD check
     if (!$this->crudU) {
         throw new Exception("Update is not allowed for path '{$this->path}'", 403);
     }
     if ($this->isRef()) {
         throw new Exception("Cannot update on reference interface in '{$this->path}'. See #498", 501);
     }
     // Check if patch value is provided
     if (!array_key_exists('value', $patch)) {
         throw new Exception("Cannot patch add. No 'value' specfied in '{$this->path}'", 400);
     }
     $tgtAtom = new Atom($patch['value'], $this->tgtConcept);
     // Interface is property
     if ($this->isProp()) {
         // Properties must be treated as a 'replace', so not handled here
         throw new Exception("Cannot patch add for property '{$this->path}'. Use patch replace instead", 500);
         // Interface is a relation to an object
     } elseif ($this->tgtConcept->isObject) {
         // Check if atom exists and may be created (crudC)
         if (!$tgtAtom->atomExists()) {
             if ($this->crudC) {
                 $tgtAtom->addAtom();
             } else {
                 throw new Exception("Resource '{$tgtAtom->__toString()}' does not exist and may not be created in {$this->path}", 403);
             }
         }
         // Add link when possible (relation is specified)
         if (is_null($this->relation)) {
             $this->logger->debug("addLink skipped because '{$this->path}' is not an editable expression");
         } else {
             $this->relation()->addLink($this->srcAtom, $tgtAtom, $this->relationIsFlipped);
         }
         // Interface is a relation to a scalar (i.e. not an object)
     } elseif (!$this->tgtConcept->isObject) {
         // Check: If interface is univalent, throw exception
         if ($this->isUni) {
             throw new Exception("Cannot patch add for univalent interface {$this->path}. Use patch replace instead", 500);
         }
         $this->relation()->addLink($this->srcAtom, $tgtAtom, $this->relationIsFlipped);
     } else {
         throw new Exception("Unknown patch add. Please contact the application administrator", 500);
     }
 }
 /**
  * 
  * @param PHPExcel_Worksheet $worksheet
  * @param InterfaceObject $ifc
  * @return void
  */
 private function ParseWorksheetWithIfc($worksheet, $ifc)
 {
     /* Use interface name as worksheet name. Format for content is as follows:
        #1 <srcConcept> | <ifc label x> | <ifc label y> | <etc>
        #2 <srcAtomA>   | <tgtAtom1>    | <tgtAtom2>    | <etc>
        #3 <srcAtomB>   | <tgtAtom3>    | <tgtAtom4>    | <etc>
        */
     $highestrow = $worksheet->getHighestRow();
     $highestcolumn = $worksheet->getHighestColumn();
     $highestcolumnnr = PHPExcel_Cell::columnIndexFromString($highestcolumn);
     $leftConcept = Concept::getConceptByLabel((string) $worksheet->getCell('A1'));
     if ($leftConcept != $ifc->tgtConcept) {
         throw new Exception("Target concept of interface '{$ifc->path}' does not match concept specified in cell {$worksheet->getTitle()}:A1", 500);
     }
     // Parse other columns of first row
     $header = array();
     for ($columnnr = 1; $columnnr < $highestcolumnnr; $columnnr++) {
         $columnletter = PHPExcel_Cell::stringFromColumnIndex($columnnr);
         $cell = $worksheet->getCell($columnletter . '1');
         $cellvalue = (string) $cell->getCalculatedValue();
         if ($cellvalue == '') {
             $header[$columnletter] = null;
         } else {
             $subIfc = $ifc->getSubinterfaceByLabel($cellvalue);
             if (!$subIfc->crudU || !$subIfc->relation) {
                 throw new Exception("Update not allowed/possible for {$subIfc->label} as specified in cell {$columnletter}1", 403);
             }
             $header[$columnletter] = $subIfc;
         }
     }
     for ($row = 2; $row <= $highestrow; $row++) {
         $firstCol = (string) $worksheet->getCell('A' . $row)->getCalculatedValue();
         if ($firstCol == '') {
             continue;
         } elseif ($firstCol == '_NEW') {
             if (!$ifc->crudC) {
                 throw new Exception("Trying to create new atom in cell A{$row}. This is not allowed.", 403);
             }
             $leftAtom = $leftConcept->createNewAtom()->addAtom();
         } else {
             $leftAtom = new Atom($firstCol, $leftConcept);
             if (!$leftAtom->atomExists() && !$ifc->crudC) {
                 throw new Exception("Trying to create new {$leftConcept} in cell A{$row}. This is not allowed.", 403);
             }
             $leftAtom->addAtom();
         }
         for ($columnnr = 1; $columnnr < $highestcolumnnr; $columnnr++) {
             $columnletter = PHPExcel_Cell::stringFromColumnIndex($columnnr);
             if (is_null($header[$columnletter])) {
                 continue;
             }
             // skip this column.
             $cell = $worksheet->getCell($columnletter . $row);
             $cellvalue = (string) $cell->getCalculatedValue();
             if ($cellvalue == '') {
                 continue;
             }
             // skip if not value provided
             // overwrite $cellvalue in case of datetime
             // the @ is a php indicator for a unix timestamp (http://php.net/manual/en/datetime.formats.compound.php), later used for typeConversion
             if (PHPExcel_Shared_Date::isDateTime($cell) && !empty($cellvalue)) {
                 $cellvalue = '@' . (string) PHPExcel_Shared_Date::ExcelToPHP($cellvalue);
             }
             $rightAtom = new Atom($cellvalue, $header[$columnletter]->tgtConcept);
             if (!$rightAtom->atomExists() && !$header[$columnletter]->crudC) {
                 throw new Exception("Trying to create new {$header[$columnletter]->tgtConcept} in cell {$columnletter}{$row}. This is not allowed.", 403);
             }
             $header[$columnletter]->relation()->addLink($leftAtom, $rightAtom, $header[$columnletter]->relationIsFlipped, 'ExcelImport');
         }
     }
 }
Beispiel #4
0
 /**
  * Constructor of Session class
  * private to prevent any outside instantiation of this object
  */
 private function __construct()
 {
     $this->logger = Logger::getLogger('FW');
     $this->database = Database::singleton();
     $conceptSession = Concept::getConceptByLabel('SESSION');
     // Also checks if 'SESSION' is defined as concept in Ampersand script
     $this->id = session_id();
     $this->sessionAtom = new Atom($this->id, $conceptSession);
     $this->logger->debug("Session id: {$this->id}");
     // Remove expired Ampersand sessions from __SessionTimeout__ and all concept tables and relations where it appears.
     $expiredSessionsAtoms = array_column((array) $this->database->Exe("SELECT SESSION FROM `__SessionTimeout__` WHERE `lastAccess` < " . (time() - Config::get('sessionExpirationTime'))), 'SESSION');
     foreach ($expiredSessionsAtoms as $expiredSessionAtom) {
         if ($expiredSessionAtom == $this->id) {
             // Notify user that session is expired when login functionality is enabled
             if (Config::get('loginEnabled')) {
                 Logger::getUserLogger()->warning("Your session has expired, please login again");
             }
             // 440 Login Timeout -> is redirected by frontend to login page
         }
         $this->destroyAmpersandSession($expiredSessionAtom);
     }
     // Create a new Ampersand session atom if not yet in SESSION table (browser started a new session or Ampersand session was expired)
     $sessionAtom = new Atom($this->id, $conceptSession);
     if (!$sessionAtom->atomExists()) {
         $sessionAtom->addAtom();
         $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() . "'");
     // Add public interfaces
     $this->accessibleInterfaces = InterfaceObject::getPublicInterfaces();
 }