diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitDocumentsApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitDocumentsApiController.php index 73578c81..03e08372 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitDocumentsApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitDocumentsApiController.php @@ -88,6 +88,7 @@ class OAuth2SummitDocumentsApiController extends OAuth2ProtectedController 'label' => 'required|string:512', 'description' => 'nullable|string', 'event_types' => 'sometimes|int_array', + 'show_always' => 'sometimes|boolean', ]; // Creates a Validator instance and validates the data. @@ -150,6 +151,7 @@ class OAuth2SummitDocumentsApiController extends OAuth2ProtectedController 'label' => 'nullable|string:512', 'description' => 'nullable|string', 'event_types' => 'sometimes|int_array', + 'show_always' => 'sometimes|boolean', ]; // Creates a Validator instance and validates the data. @@ -173,6 +175,7 @@ class OAuth2SummitDocumentsApiController extends OAuth2ProtectedController $document_id, HTMLCleaner::cleanData($payload, $fields) ); + return $this->updated(SerializerRegistry::getInstance()->getSerializer($document)->serialize()); } catch (EntityNotFoundException $ex1) diff --git a/app/ModelSerializers/Summit/SummitDocumentSerializer.php b/app/ModelSerializers/Summit/SummitDocumentSerializer.php index bc719e5f..f8bf0519 100644 --- a/app/ModelSerializers/Summit/SummitDocumentSerializer.php +++ b/app/ModelSerializers/Summit/SummitDocumentSerializer.php @@ -23,6 +23,7 @@ class SummitDocumentSerializer extends SilverStripeSerializer protected static $array_mappings = [ 'Name' => 'name:json_string', 'Description' => 'description:json_string', + 'ShowAlways' => 'show_always:json_boolean', 'Label' => 'label:json_string', 'SummitId' => 'summit_id:json_int', 'FileUrl' => 'file:json_url', diff --git a/app/Models/Foundation/Summit/Factories/SummitDocumentFactory.php b/app/Models/Foundation/Summit/Factories/SummitDocumentFactory.php index 09100abc..5844585d 100644 --- a/app/Models/Foundation/Summit/Factories/SummitDocumentFactory.php +++ b/app/Models/Foundation/Summit/Factories/SummitDocumentFactory.php @@ -37,10 +37,16 @@ final class SummitDocumentFactory public static function populate(Summit $summit, SummitDocument $document, array $payload):SummitDocument { if(isset($payload['name'])) $document->setName(trim($payload['name'])); + if(isset($payload['label'])) $document->setLabel(trim($payload['label'])); + + if(isset($payload['show_always'])) + $document->setShowAlways(boolval($payload['show_always'])); + if(isset($payload['description'])) $document->setDescription(trim($payload['description'])); + return $document; } } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/SummitDocument.php b/app/Models/Foundation/Summit/SummitDocument.php index 14d3aa59..9505c134 100644 --- a/app/Models/Foundation/Summit/SummitDocument.php +++ b/app/Models/Foundation/Summit/SummitDocument.php @@ -49,6 +49,12 @@ class SummitDocument extends SilverstripeBaseModel */ private $label; + /** + * @ORM\Column(name="ShowAlways", type="boolean") + * @var bool + */ + private $show_always; + /** * @ORM\ManyToOne(targetEntity="models\main\File", cascade={"persist","remove"}) * @ORM\JoinColumn(name="FileID", referencedColumnName="ID") @@ -77,6 +83,7 @@ class SummitDocument extends SilverstripeBaseModel $this->label = ''; $this->description = ''; $this->name = ''; + $this->show_always = false; } /** @@ -195,4 +202,21 @@ class SummitDocument extends SilverstripeBaseModel return $fileUrl; } + /** + * @return bool + */ + public function isShowAlways(): bool + { + return $this->show_always; + } + + /** + * @param bool $show_always + */ + public function setShowAlways(bool $show_always): void + { + $this->show_always = $show_always; + } + + } \ No newline at end of file diff --git a/database/migrations/model/Version20210419181056.php b/database/migrations/model/Version20210419181056.php new file mode 100644 index 00000000..0f589caa --- /dev/null +++ b/database/migrations/model/Version20210419181056.php @@ -0,0 +1,49 @@ +hasTable("SummitDocument")) { + $builder->table('SummitDocument', function (Table $table) { + $table->boolean("ShowAlways")->setDefault(false)->setNotnull(true); + }); + } + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema):void + { + $builder = new Builder($schema); + if($schema->hasTable("SummitDocument")) { + $builder->table('SummitDocument', function (Table $table) { + $table->dropColumn("ShowAlways"); + }); + } + } +}