2020-11-04 18:58:20 +00:00
|
|
|
<?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;
|
|
|
|
|
2020-11-08 16:36:06 +00:00
|
|
|
use App\Core\DB\DB;
|
2020-11-04 18:58:20 +00:00
|
|
|
use App\Core\Entity;
|
|
|
|
use DateTimeInterface;
|
|
|
|
|
|
|
|
class PollResponse extends Entity
|
|
|
|
{
|
|
|
|
// {{{ Autocode
|
|
|
|
|
|
|
|
private int $id;
|
|
|
|
private ?string $uri;
|
2020-11-08 16:36:06 +00:00
|
|
|
private int $poll_id;
|
2020-11-04 18:58:20 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-11-08 16:36:06 +00:00
|
|
|
public function setPollId(int $poll_id): self
|
2020-11-04 18:58:20 +00:00
|
|
|
{
|
|
|
|
$this->poll_id = $poll_id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-11-08 16:36:06 +00:00
|
|
|
public function getPollId(): int
|
2020-11-04 18:58:20 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
/**
|
2020-11-09 17:43:10 +00:00
|
|
|
* Entity schema definition
|
|
|
|
*
|
|
|
|
* @return array schema definition
|
2020-11-04 18:58:20 +00:00
|
|
|
*/
|
|
|
|
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'],
|
2020-11-08 16:36:06 +00:00
|
|
|
'poll_id' => ['type' => 'int', 'length' => 36, 'not null' => true, 'description' => 'UUID of poll being responded to'],
|
2020-11-04 18:58:20 +00:00
|
|
|
'gsactor_id' => ['type' => 'int'],
|
|
|
|
'selection' => ['type' => 'int'],
|
|
|
|
'created' => ['type' => 'datetime', 'not null' => true],
|
|
|
|
],
|
|
|
|
'primary key' => ['id'],
|
2020-11-08 16:36:06 +00:00
|
|
|
|
|
|
|
'unique keys' => [
|
|
|
|
//'poll_uri_key' => array('uri'),
|
|
|
|
//'poll_response_poll_id_gsactor_id_key' => ['poll_id', 'gsactor_id'], //doctrine bug?
|
|
|
|
],
|
|
|
|
|
|
|
|
'indexes' => [
|
|
|
|
'poll_response_gsactor_id_poll_id_index' => ['gsactor_id', 'poll_id'],
|
|
|
|
],
|
2020-11-04 18:58:20 +00:00
|
|
|
];
|
|
|
|
}
|
2020-11-08 16:36:06 +00:00
|
|
|
|
2020-11-09 17:43:10 +00:00
|
|
|
/**
|
|
|
|
* Checks if a user already responded to the poll
|
|
|
|
*
|
|
|
|
* @param int $pollId
|
|
|
|
* @param int $gsactorId user
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2020-11-08 16:36:06 +00:00
|
|
|
public static function exits(int $pollId, int $gsactorId): bool
|
|
|
|
{
|
|
|
|
$res = DB::dql('select pr from App\Entity\PollResponse pr
|
|
|
|
where pr.poll_id = :pollId and pr.gsactor_id = :gsactorId',
|
|
|
|
['pollId' => $pollId, 'gsactorId' => $gsactorId]);
|
|
|
|
//var_dump( $res);
|
|
|
|
return count($res) != 0;
|
|
|
|
}
|
2020-11-04 18:58:20 +00:00
|
|
|
}
|