diff --git a/src/app/Models/Item.php b/src/app/Models/Item.php index da9a4e2..9bab386 100644 --- a/src/app/Models/Item.php +++ b/src/app/Models/Item.php @@ -60,8 +60,11 @@ class Item extends Model protected $appends = [ 'DescriptionLang', 'CompletionStatus', - 'TranscriptionText', - 'Properties' + 'Transcription', + 'Properties', + 'EditStart', + 'Places', + 'Persons' ]; public function htrData() @@ -99,14 +102,15 @@ public function getCompletionStatusAttribute() /** * Get the current version of Item Transcription */ - public function getTranscriptionTextAttribute() + public function getTranscriptionAttribute() { if ($this->TranscriptionSource === 'manual') { $manualTranscription = $this ->hasMany(Transcription::class, 'ItemId') + ->select('UserId', 'TextNoTags as TranscriptionText', 'CurrentVersion') ->firstWhere('CurrentVersion', 1); - return $manualTranscription ? $manualTranscription->TextNoTags : ''; + return $manualTranscription ? $manualTranscription : []; } if ($this->TranscriptionSource === 'htr') { @@ -118,7 +122,35 @@ public function getTranscriptionTextAttribute() ->latest() ->first(); - return $latest ? $latest->htrDataRevision->pluck('TranscriptionText')->first() : ''; + return $latest ? $latest->htrDataRevision->first() : []; + } + + return []; + } + + /** + * Get the timestamp od first transcription + */ + public function getEditStartAttribute() + { + if ($this->TranscriptionSource === 'manual') { + $dateStart = $this + ->hasMany(Transcription::class, 'ItemId') + ->orderBy('Timestamp', 'asc') + ->pluck('Timestamp') + ->first(); + + return $dateStart ? $dateStart : ''; + } + + if ($this->TranscriptionSource === 'htr') { + $dateStart = $this + ->hasMany(HtrData::class, 'ItemId') + ->orderBy('Timestamp', 'asc') + ->pluck('Timestamp') + ->first(); + + return $dateStart ? $dateStart : ''; } return ''; @@ -141,4 +173,28 @@ public function getPropertiesAttribute() return $plucked; } + + /** + * Get the Item places + */ + public function getPlacesAttribute() + { + $places = $this + ->hasMany(Place::class, 'ItemId') + ->get(); + + return $places ? $places : []; + } + + /** + * Get the Item persons + */ + public function getPersonsAttribute() + { + $persons = $this + ->hasMany(Person::class, 'ItemId') + ->get(); + + return $persons ? $persons : []; + } } diff --git a/src/app/Models/Person.php b/src/app/Models/Person.php new file mode 100644 index 0000000..7d8d1bd --- /dev/null +++ b/src/app/Models/Person.php @@ -0,0 +1,30 @@ + 'boolean']; +} diff --git a/src/storage/api-docs/api-docs.yaml b/src/storage/api-docs/api-docs.yaml index 0671ea5..f68eeaa 100644 --- a/src/storage/api-docs/api-docs.yaml +++ b/src/storage/api-docs/api-docs.yaml @@ -1,7 +1,7 @@ openapi: 3.0.3 info: - version: 1.18.0 + version: 1.19.0 title: Transcribathon Platform API v2 description: This is the documentation of the Transcribathon API v2 used by [https:transcribathon.eu](https://transcribathon.eu/).
For authorization you can use the the bearer token you are provided with. diff --git a/src/storage/api-docs/items-schema.yaml b/src/storage/api-docs/items-schema.yaml index f149aa9..090dd1d 100644 --- a/src/storage/api-docs/items-schema.yaml +++ b/src/storage/api-docs/items-schema.yaml @@ -108,11 +108,43 @@ ItemsAdditionalDataReferenceSchema: ItemsAdditionalGetReferenceSchema: properties: - TranscriptionText: - type: string - nullable: true - description: plain text of the current selected transcription (of source manual or HTR) - example: Plain text representation oft the transcription data + Transcription: + type: object + properties: + TranscriptionText: + type: string + nullable: true + description: plain text of the current selected transcription (of source manual or HTR) + example: Plain text representation oft the transcription data + UserId: + type: integer + description: the ID of the user of this transcription + example: 1392 + CurrentVersion: + type: integer + description: determine if this is the current/active transcription (only if transcription is manual) + example: 1 + HtrDataId: + type: integer + description: ID of the HTR data entry (only if HTR data) + example: 2 + Timestamp: + type: string + description: Time of creation of the HTR transcription (only if HTR data) + example: '2022-02-23T09:57:03.000000Z' + LastUpdated: + type: string + description: Time of last update of the HTR transcription (only if HTR data) + example: '2022-02-23T09:57:03.000000Z' + TranscriptionData: + type: string + nullable: true + description: HTR data data as XML string (only if HTR data) + example: '' + HtrDataRevisionId: + type: integer + description: ID of the HTR data revision entry (only if HTR data) + example: 2 PropertiesReference: type: array