diff --git a/src/Dao/EntityConverters/PostNoteEntityConverter.php b/src/Dao/EntityConverters/PostNoteEntityConverter.php new file mode 100644 index 00000000..63f70f93 --- /dev/null +++ b/src/Dao/EntityConverters/PostNoteEntityConverter.php @@ -0,0 +1,33 @@ + $entity->getId(), + 'postId' => $entity->getPostId(), + 'x' => $entity->getLeft(), + 'y' => $entity->getTop(), + 'width' => $entity->getWidth(), + 'height' => $entity->getHeight(), + 'text' => $entity->getText(), + ]; + } + + public function toBasicEntity(array $array) + { + $entity = new PostNote($array['id']); + $entity->setPostId($array['postId']); + $entity->setLeft($array['x']); + $entity->setTop($array['y']); + $entity->setWidth($array['width']); + $entity->setHeight($array['height']); + $entity->setText($array['text']); + return $entity; + } +} diff --git a/src/Dao/PostNoteDao.php b/src/Dao/PostNoteDao.php new file mode 100644 index 00000000..472a8c07 --- /dev/null +++ b/src/Dao/PostNoteDao.php @@ -0,0 +1,15 @@ +postId; + } + + public function setPostId($postId) + { + $this->postId = $postId; + } + + public function getLeft() + { + return $this->left; + } + + public function setLeft($left) + { + $this->left = $left; + } + + public function getTop() + { + return $this->top; + } + + public function setTop($top) + { + $this->top = $top; + } + + public function getWidth() + { + return $this->width; + } + + public function setWidth($width) + { + $this->width = $width; + } + + public function getHeight() + { + return $this->height; + } + + public function setHeight($height) + { + $this->height = $height; + } + + public function getText() + { + return $this->text; + } + + public function setText($text) + { + $this->text = $text; + } +} diff --git a/src/Upgrades/Upgrade27.php b/src/Upgrades/Upgrade27.php new file mode 100644 index 00000000..4e3b022c --- /dev/null +++ b/src/Upgrades/Upgrade27.php @@ -0,0 +1,23 @@ +getPDO(); + $driver = $databaseConnection->getDriver(); + + $pdo->exec( + 'CREATE TABLE postNotes ( + id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ', + postId INTEGER NOT NULL, + x INTEGER NOT NULL, + y INTEGER NOT NULL, + height INTEGER NOT NULL, + width INTEGER NOT NULL, + text TEXT NOT NULL + )'); + } +} diff --git a/src/di.php b/src/di.php index 9de1121d..5da89260 100644 --- a/src/di.php +++ b/src/di.php @@ -42,6 +42,7 @@ return [ $container->get(\Szurubooru\Upgrades\Upgrade24::class), $container->get(\Szurubooru\Upgrades\Upgrade25::class), $container->get(\Szurubooru\Upgrades\Upgrade26::class), + $container->get(\Szurubooru\Upgrades\Upgrade27::class), ]; }), diff --git a/tests/Dao/PostNoteDaoTest.php b/tests/Dao/PostNoteDaoTest.php new file mode 100644 index 00000000..45887e41 --- /dev/null +++ b/tests/Dao/PostNoteDaoTest.php @@ -0,0 +1,31 @@ +setPostId(5); + $expected->setLeft(5); + $expected->setTop(10); + $expected->setWidth(50); + $expected->setHeight(50); + $expected->setText('text'); + + $postNoteDao = $this->getPostNoteDao(); + $postNoteDao->save($expected); + + $actual = $postNoteDao->findById($expected->getId()); + $this->assertEntitiesEqual($actual, $expected); + } + + private function getPostNoteDao() + { + return new PostNoteDao($this->databaseConnection); + } +} +