Add poll 6

Add poll duration setting.
This commit is contained in:
Visman 2020-11-21 16:53:59 +07:00
parent 5f02e3f054
commit 54b228ccf1
9 changed files with 60 additions and 12 deletions

View file

@ -96,6 +96,7 @@ class Edit extends Page
'pollNoEdit' => ! $poll->canEdit,
'poll_enable' => $topic->poll_type > 0,
'poll' => [
'duration' => $topic->poll_type > 1000 ? $topic->poll_type - 1000 : 0, // ???? перенести в модель poll?
'hide_result' => $topic->poll_term > 0,
'question' => $poll->question,
'type' => $poll->type,
@ -236,7 +237,7 @@ class Edit extends Page
// редактирование
if ($v->poll_enable) {
# $topic->poll_type = 0;
$topic->poll_type = $v->poll['duration'] > 0 ? 1000 + $v->poll['duration'] : 1; // ???? перенести в модель poll?
# $topic->poll_time = 0;
$topic->poll_term = $v->poll['hide_result']
? ($topic->poll_term ?: $this->c->config->i_poll_term)
@ -259,7 +260,7 @@ class Edit extends Page
}
// добавление
} elseif ($v->poll_enable) {
$topic->poll_type = 1;
$topic->poll_type = $v->poll['duration'] > 0 ? 1000 + $v->poll['duration'] : 1; // ???? перенести в модель poll?
$topic->poll_time = \time();
$topic->poll_term = $v->poll['hide_result'] ? $this->c->config->i_poll_term : 0;
$topic->poll_votes = 0;

View file

@ -54,7 +54,7 @@ class Post extends Page
}
$this->fIswev = $v->getErrors();
$args['_vars'] = $v->getData(); //????
$args['_vars'] = $v->getData();
if (
null !== $v->preview
@ -257,7 +257,7 @@ class Post extends Page
$this->user->usePoll
&& $v->poll_enable
) {
$topic->poll_type = 1;
$topic->poll_type = $v->poll['duration'] > 0 ? 1000 + $v->poll['duration'] : 1; // ???? перенести в модель poll?
$topic->poll_time = $now;
$topic->poll_term = $v->poll['hide_result'] ? $this->c->config->i_poll_term : 0;
# $topic->poll_votes = ;

View file

@ -204,6 +204,15 @@ trait PostFormTrait
'checked' => (bool) ($vars['poll_enable'] ?? false),
'disabled' => $vars['pollNoEdit'] ?? null,
];
$fieldset["poll[duration]"] = [
'type' => 'number',
'min' => '0',
'max' => '366',
'value' => $vars['poll']['duration'] ?? 0,
'caption' => __('Poll duration label'),
'info' => __('Poll duration help'),
'disabled' => $vars['pollNoEdit'] ?? null,
];
$fieldset['poll[hide_result]'] = [
'type' => 'checkbox',
'label' => __('Hide poll results up to %s voters', $term),

View file

@ -203,6 +203,7 @@ trait PostValidatorTrait
'check_poll' => [$this, 'vCheckPoll'],
])->addRules([
'poll_enable' => 'checkbox|check_poll',
'poll.duration' => 'integer|min:0|max:366',
'poll.hide_result' => 'checkbox',
'poll.question.*' => 'string:trim|max:255',
'poll.type.*' => 'integer|min:1|max:' . $this->c->config->i_poll_max_fields,

View file

@ -73,6 +73,25 @@ class Model extends DataModel
return ! empty($this->c->DB->query($query, $vars)->fetch());
}
/**
* Статус открытости
*/
protected function getisOpen(): bool
{
return $this->tid < 1
|| (
0 === $this->parent->closed
&& ($type = $this->parent->poll_type) > 0
&& (
1 === $type
|| (
$type > 1000
&& ($type - 1000) * 86400 > \time() - $this->parent->poll_time
)
)
);
}
/**
* Статус возможности голосовать
*/
@ -80,8 +99,7 @@ class Model extends DataModel
{
return $this->tid > 0
&& $this->c->user->usePoll
&& 0 === $this->parent->closed
&& 1 === $this->parent->poll_type // ???? добавить ограничение по времени?
&& $this->isOpen
&& ! $this->userVoted;
}
@ -90,8 +108,15 @@ class Model extends DataModel
*/
protected function getcanSeeResult(): bool
{
return ($this->c->user->usePoll || '1' == $this->c->config->b_poll_guest)
&& (0 === $this->parent->poll_term || $this->parent->poll_term < $this->parent->poll_votes);
return (
$this->c->user->usePoll
|| '1' == $this->c->config->b_poll_guest
)
&& (
0 === $this->parent->poll_term
|| $this->parent->poll_term < $this->parent->poll_votes
|| ! $this->isOpen
);
}
/**

View file

@ -433,13 +433,13 @@ msgid "Poll edit time label"
msgstr "Edit time"
msgid "Poll edit time help"
msgstr "Poll editing time (in minutes). <b>0 removes restrictions.</b>"
msgstr "Poll editing time (in minutes). Set to 0 to disable."
msgid "Hidden voices label"
msgstr "Hidden voices"
msgid "Hidden voices help"
msgstr "The number of votes before which you can hide the poll results. <b>Set in the poll.</b>"
msgstr "The number of votes before which you can hide the poll results. Set in the poll."
msgid "Result for guest label"
msgstr "Result for guest"

View file

@ -62,3 +62,9 @@ msgstr "You can choose up to %s answers."
msgid "In total voted: %s"
msgstr "In total voted: %s"
msgid "Poll duration label"
msgstr "Duration"
msgid "Poll duration help"
msgstr "Duration of the poll (in days). Set to 0 to disable."

View file

@ -433,13 +433,13 @@ msgid "Poll edit time label"
msgstr "Время редактирования"
msgid "Poll edit time help"
msgstr "Время редактирования опроса (в минутах). <b>0 снимает ограничения.</b>"
msgstr "Время редактирования опроса (в минутах). 0 снимает ограничения."
msgid "Hidden voices label"
msgstr "Скрытые голоса"
msgid "Hidden voices help"
msgstr "Число голосов, до набора которых можно скрыть результаты опроса. <b>Включается в опросе.</b>"
msgstr "Число голосов, до набора которых можно скрыть результаты опроса. Включается в опросе."
msgid "Result for guest label"
msgstr "Результат для гостя"

View file

@ -62,3 +62,9 @@ msgstr "Можете выбрать до %s ответов."
msgid "In total voted: %s"
msgstr "Проголосовало: %s"
msgid "Poll duration label"
msgstr "Длительность"
msgid "Poll duration help"
msgstr "Продолжительность опроса (в днях). 0 снимает ограничения."