[Poll] Added New Route, RespondPoll, Poll Response, PollResponseForm

This commit is contained in:
Daniel
2020-11-04 18:58:20 +00:00
committed by Hugo Sales
parent dbb55362c8
commit 3725818e4f
6 changed files with 286 additions and 25 deletions

View File

@@ -30,8 +30,8 @@ class Poll extends Entity
// {{{ Autocode
private int $id;
private string $uri;
private ?int $profile_id;
private ?string $uri;
private ?int $gsactor_id;
private ?string $question;
private ?string $options;
private DateTimeInterface $created;
@@ -47,26 +47,26 @@ class Poll extends Entity
return $this->id;
}
public function setUri(string $uri): self
public function setUri(?string $uri): self
{
$this->uri = $uri;
return $this;
}
public function getUri(): string
public function getUri(): ?string
{
return $this->uri;
}
public function setProfileId(?int $profile_id): self
public function setGsactorId(?int $gsactor_id): self
{
$this->profile_id = $profile_id;
$this->gsactor_id = $gsactor_id;
return $this;
}
public function getProfileId(): ?int
public function getGsactorId(): ?int
{
return $this->profile_id;
return $this->gsactor_id;
}
public function setQuestion(?string $question): self
@@ -113,17 +113,18 @@ class Poll extends Entity
'name' => 'poll',
'description' => 'Per-notice poll data for Poll plugin',
'fields' => [
'id' => ['type' => 'int', 'not null' => true],
'uri' => ['type' => 'varchar', 'length' => 191, 'not null' => true],
'profile_id' => ['type' => 'int'], //-> gsactor id?
'id' => ['type' => 'serial', 'not null' => true],
'uri' => ['type' => 'varchar', 'length' => 191],
// 'uri' => ['type' => 'varchar', 'length' => 191, 'not null' => true],
'gsactor_id' => ['type' => 'int'], //-> gsactor id?
'question' => ['type' => 'text'],
'options' => ['type' => 'text'],
'created' => ['type' => 'datetime', 'not null' => true],
],
'primary key' => ['id'],
'unique keys' => [
'poll_uri_key' => ['uri'],
],
// 'unique keys' => [
// 'poll_uri_key' => ['uri'],
// ],
];
}
@@ -132,6 +133,17 @@ class Poll extends Entity
return DB::find('poll', ['id' => $id]);
}
public static function make(string $question, array $opt): self
{
$options = implode("\n",$opt);
return self::create(['question' => $question, 'options' => $options]);
}
public function getOptionsArr()
{
return explode("\n", $this->options);
}
//from old version
/**
* Get a bookmark based on a notice
@@ -146,12 +158,6 @@ class Poll extends Entity
return self::getKV('uri', $notice->uri);
}
*/
/*
public function getOptions()
{
return explode("\n", $this->options);
}
*/
/**
* Is this a valid selection index?

136
src/Entity/PollResponse.php Normal file
View File

@@ -0,0 +1,136 @@
<?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 App\Entity;
use App\Core\Entity;
use DateTimeInterface;
class PollResponse extends Entity
{
// {{{ Autocode
private int $id;
private ?string $uri;
private string $poll_id;
private ?int $gsactor_id;
private ?int $selection;
private DateTimeInterface $created;
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 setPollId(string $poll_id): self
{
$this->poll_id = $poll_id;
return $this;
}
public function getPollId(): string
{
return $this->poll_id;
}
public function setGsactorId(?int $gsactor_id): self
{
$this->gsactor_id = $gsactor_id;
return $this;
}
public function getGsactorId(): ?int
{
return $this->gsactor_id;
}
public function setSelection(?int $selection): self
{
$this->selection = $selection;
return $this;
}
public function getSelection(): ?int
{
return $this->selection;
}
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.
*/
public static function schemaDef()
{
return [
'name' => 'pollresponse',
'description' => 'Record of responses to polls',
'fields' => [
'id' => ['type' => 'serial', 'not null' => true],
//'uri' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'UUID to the response notice'),
'uri' => ['type' => 'varchar', 'length' => 191, 'description' => 'UUID to the response notice'],
'poll_id' => ['type' => 'char', 'length' => 36, 'not null' => true, 'description' => 'UUID of poll being responded to'],
'gsactor_id' => ['type' => 'int'],
'selection' => ['type' => 'int'],
'created' => ['type' => 'datetime', 'not null' => true],
],
'primary key' => ['id'],
/*
'unique keys' => array(
'poll_uri_key' => array('uri'),
'poll_response_poll_id_profile_id_key' => array('poll_id', 'profile_id'),
),
'indexes' => array(
'poll_response_profile_id_poll_id_index' => array('profile_id', 'poll_id'),
)
*/
];
}
}