From a9c35def3f5169dfb2fb03c0205b602f6272c61d Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 29 Oct 2020 18:32:35 +0000 Subject: [PATCH] [AUTOGENERATED][Poll] Add auto generated code for poll entity and new route --- plugins/PollPlugin/Controller/NewPoll.php | 4 +- plugins/PollPlugin/Controller/ShowPoll.php | 31 +++++++++ plugins/PollPlugin/Entity/Poll.php | 80 +++++++++++++++++++--- plugins/PollPlugin/PollPlugin.php | 13 ++-- 4 files changed, 109 insertions(+), 19 deletions(-) create mode 100644 plugins/PollPlugin/Controller/ShowPoll.php diff --git a/plugins/PollPlugin/Controller/NewPoll.php b/plugins/PollPlugin/Controller/NewPoll.php index b4519e67ab..2c952c294b 100644 --- a/plugins/PollPlugin/Controller/NewPoll.php +++ b/plugins/PollPlugin/Controller/NewPoll.php @@ -46,9 +46,11 @@ class NewPoll $data = $form->getData(); } - //$test = Poll::create(['id' => '0']); //not working till generating things + //testing + $test = Poll::create(['id' => '0', 'uri' => 'a']); //DB::persist($test); //DB::flush(); + //$loadpoll = Poll::getFromId('0'); //need to add plugin support for DB::__callStatic return ['_template' => 'Poll/newpoll.html.twig', 'form' => $form->createView()]; } diff --git a/plugins/PollPlugin/Controller/ShowPoll.php b/plugins/PollPlugin/Controller/ShowPoll.php new file mode 100644 index 0000000000..82544f3c5d --- /dev/null +++ b/plugins/PollPlugin/Controller/ShowPoll.php @@ -0,0 +1,31 @@ +. + +// }}} + +namespace Plugin\PollPlugin\Controller; + +use Symfony\Component\HttpFoundation\Request; + +class ShowPoll +{ + public function showpoll(Request $request) + { + } +} diff --git a/plugins/PollPlugin/Entity/Poll.php b/plugins/PollPlugin/Entity/Poll.php index 8b813875a2..a664ea0f70 100644 --- a/plugins/PollPlugin/Entity/Poll.php +++ b/plugins/PollPlugin/Entity/Poll.php @@ -21,32 +21,89 @@ namespace Plugin\PollPlugin\Entity; +use App\Core\DB\DB; use App\Core\Entity; use DateTimeInterface; class Poll extends Entity { - public int $id; // char(36) primary key not null -> UUID - public ?string $uri; // varchar(191) not 255 because utf8mb4 takes more space - public ?int $profile_id; // int -> profile.id - public ?string $question; // text - public ?string $options; // text; newline(?)-delimited - public ?DateTimeInterface $created; // datetime + // {{{ Autocode - //need to generate_entity_diagrams/fields + private int $id; + private string $uri; + private ?int $profile_id; + private ?string $question; + private ?string $options; + private DateTimeInterface $created; - public function setId($id): self + public function setId(int $id): self { $this->id = $id; return $this; } + public function getId(): int + { + return $this->id; + } + + public function setUri(string $uri): self + { + $this->uri = $uri; + return $this; + } + + public function getUri(): string + { + return $this->uri; + } + + public function setProfileId(?int $profile_id): self + { + $this->profile_id = $profile_id; + return $this; + } + + public function getProfileId(): ?int + { + return $this->profile_id; + } + + public function setQuestion(?string $question): self + { + $this->question = $question; + return $this; + } + + public function getQuestion(): ?string + { + return $this->question; + } + + public function setOptions(?string $options): self + { + $this->options = $options; + return $this; + } + + public function getOptions(): ?string + { + return $this->options; + } + public function setCreated(DateTimeInterface $created): self { $this->created = $created; return $this; } + public function getCreated(): DateTimeInterface + { + return $this->created; + } + + // }}} Autocode + /** * The One True Thingy that must be defined and declared. */ @@ -56,7 +113,7 @@ class Poll extends Entity 'name' => 'poll', 'description' => 'Per-notice poll data for Poll plugin', 'fields' => [ - 'id' => ['type' => 'char', 'length' => 36, 'not null' => true, 'description' => 'UUID'], //int? + 'id' => ['type' => 'int', 'not null' => true], 'uri' => ['type' => 'varchar', 'length' => 191, 'not null' => true], 'profile_id' => ['type' => 'int'], //-> gsactor id? 'question' => ['type' => 'text'], @@ -70,6 +127,11 @@ class Poll extends Entity ]; } + public static function getFromId(int $id): ?self + { + return DB::find('poll', ['id' => $id]); //not working yet + } + //from old version /** * Get a bookmark based on a notice diff --git a/plugins/PollPlugin/PollPlugin.php b/plugins/PollPlugin/PollPlugin.php index ed6f2b8812..b2b8e0b7a1 100644 --- a/plugins/PollPlugin/PollPlugin.php +++ b/plugins/PollPlugin/PollPlugin.php @@ -22,6 +22,9 @@ namespace Plugin\PollPlugin; use App\Core\Event; use App\Core\Module; +use Plugin\PollPlugin\Entity\Poll; + +const ID_FMT = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'; class PollPlugin extends Module { @@ -61,16 +64,8 @@ class PollPlugin extends Module public function onAddRoute($r) { $r->connect('newpoll', 'main/poll/new', [Controller\NewPoll::class, 'newpoll']); + $r->connect('showpoll', 'main/poll/{id<' . ID_FMT . '>}' , [Controller\ShowPoll::class, 'showpoll']); return Event::next; } - /* - public function onCheckSchema() - { - $schema = Schema::get(); - $schema->ensureTable('poll', Poll::schemaDef()); - - return Event::next; - } - */ }