/** * Constructor of RelationTable * @param string $name * @param string|null $tableOf ('src', 'tgt' or null) */ public function __construct($name, $tableOf) { parent::__construct($name); switch ($tableOf) { case 'src': case 'tgt': case null: $this->tableOf = $tableOf; break; default: throw new Exception("Unknown tableOf value '{$tableOf}' specified for RelationTable {$this->name}", 500); } }
/** * Generate a new atom identifier for this concept * @return string */ public function createNewAtomId() { static $prevTime = null; if (strpos($this->name, '_AI') !== false && $this->isInteger()) { $firstCol = current($this->mysqlConceptTable->getCols()); $query = "SELECT MAX(`{$firstCol->name}`) as `MAX` FROM `{$this->mysqlConceptTable->name}`"; $result = array_column((array) $this->database->Exe($query), 'MAX'); if (empty($result)) { $atomId = 1; } else { $atomId = $result[0] + 1; } } else { $now = explode(' ', microTime()); // yields ["microseconds", "seconds"] both in seconds, e.g. ["0.85629400", "1322761879"] $time = $now[1] . substr($now[0], 2, 6); // we drop the leading "0." and trailing "00" from the microseconds // Guarantee that time is increased if ($time <= $prevTime) { $time = ++$prevTime; } else { $prevTime = $time; } $atomId = $this->name . '_' . $time; } return $atomId; }