public function atomExists($atomId, $concept) { $tableInfo = Concept::getConceptTableInfo($concept); $table = $tableInfo['table']; $conceptCol = $tableInfo['cols'][0]; $newAtom = $this->typeConversion($atomId, $concept); $atomIdEsc = $this->escape($atomId); $query = "/* Check if atom exists */ SELECT `{$conceptCol}` FROM `{$table}` WHERE `{$conceptCol}` = '{$atomIdEsc}'"; $result = $this->Exe($query); if (empty($result)) { return false; } else { return true; } }
public static function createNewAtom($concept) { if (strpos($concept, '_AUTOINCREMENT') !== false) { // TODO: change to type definition when Ampersand is supporting IT-TYPE $database = Database::singleton(); $tableInfo = Concept::getConceptTableInfo($concept); $table = $tableInfo['table']; $col = $tableInfo['cols'][0]; $query = "SELECT MAX(`{$col}`) as `MAX` FROM `{$table}`"; $result = array_column($database->Exe($query), 'MAX'); if (empty($result)) { $atomId = 1; } else { $atomId = $result[0] + 1; } } else { $time = explode(' ', microTime()); // yields [seconds,microseconds] both in seconds, e.g. ["1322761879", "0.85629400"] $atomId = $concept . '_' . $time[1] . "_" . substr($time[0], 2, 6); // we drop the leading "0." and trailing "00" from the microseconds } return $atomId; }