[AUTOGENERATED][Poll] Add auto generated code for poll entity and new route

This commit is contained in:
Daniel 2020-10-29 18:32:35 +00:00 committed by Hugo Sales
parent 5978a069e9
commit 03f02bed4d
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
4 changed files with 109 additions and 19 deletions

View File

@ -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()];
}

View File

@ -0,0 +1,31 @@
<?php
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
namespace Plugin\PollPlugin\Controller;
use Symfony\Component\HttpFoundation\Request;
class ShowPoll
{
public function showpoll(Request $request)
{
}
}

View File

@ -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

View File

@ -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;
}
*/
}