-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing a new property of the user entity for custom structured U…
…I data and an endpoint for setting them.
- Loading branch information
Martin Krulis
committed
Jun 12, 2019
1 parent
e9584cb
commit 1af2dc3
Showing
7 changed files
with
208 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Model\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* Entity holding user-specific data stored by the UI. | ||
*/ | ||
class UserUiData | ||
{ | ||
public function __construct($data) { | ||
$this->setData($data); | ||
} | ||
|
||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="guid") | ||
* @ORM\GeneratedValue(strategy="UUID") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* Arbitrary user-specific JSON-structured data stored by the UI. | ||
* @ORM\Column(type="text") | ||
*/ | ||
protected $data; | ||
|
||
/** | ||
* Get parsed UI data structured as (nested) assoc array. | ||
* @return array | ||
*/ | ||
public function getData(): array { | ||
return json_decode($this->data, true); | ||
} | ||
|
||
/** | ||
* Set (overwrite) the UI data. | ||
* @param array|object $root Root of the structured data (must be JSON serializable) | ||
*/ | ||
public function setData($root) { | ||
$this->data = json_encode($root); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20190607231836 extends AbstractMigration | ||
{ | ||
public function getDescription() : string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema) : void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('CREATE TABLE user_ui_data (id CHAR(36) NOT NULL COMMENT \'(DC2Type:guid)\', data LONGTEXT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); | ||
$this->addSql('ALTER TABLE user ADD ui_data_id CHAR(36) DEFAULT NULL COMMENT \'(DC2Type:guid)\''); | ||
$this->addSql('ALTER TABLE user ADD CONSTRAINT FK_8D93D64925B58E7D FOREIGN KEY (ui_data_id) REFERENCES user_ui_data (id)'); | ||
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D64925B58E7D ON user (ui_data_id)'); | ||
} | ||
|
||
public function down(Schema $schema) : void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('ALTER TABLE user DROP FOREIGN KEY FK_8D93D64925B58E7D'); | ||
$this->addSql('DROP INDEX UNIQ_8D93D64925B58E7D ON user'); | ||
$this->addSql('ALTER TABLE user DROP ui_data_id'); | ||
$this->addSql('DROP TABLE user_ui_data'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters