/** * Gets record (retrieved from repository if exists, or create new record!) * * @param Table $table * @param array $data * @param bool $exists * @throws \UnexpectedValueException * @return Record */ public function getOrCreateRecord(Table $table, array $data, $exists = false) { $id = $table->getIdentifierAsString($data); if ($id !== false && $table->isInRepository($id)) { $record = $table->getFromRepository($id); } else { $record = $table->createRecord($data, $exists); } return $record; }
/** * @return null|string */ public function getStoredIdentifierAsString() { if ($this->isModified()) { $idFields = $this->_table->getIdentifierFields(); $identifierValues = array(); foreach ($idFields as $idField) { $identifierValues[$idField] = $this->isFieldModified($idField) ? $this->getModifiedFieldValue($idField) : $this->get($idField); } return $this->_table->getIdentifierAsString($identifierValues); } return $this->getIdentifierAsString(); }