forked from GNUsocial/gnu-social
[Poll] Polls now have an associated note, poll templates, start_show_styles event, started css
This commit is contained in:
@@ -22,12 +22,19 @@
|
||||
namespace Plugin\Poll\Controller;
|
||||
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Form;
|
||||
use function App\Core\I18n\_m;
|
||||
use App\Core\Security;
|
||||
use App\Entity\Note;
|
||||
use App\Entity\Poll;
|
||||
use App\Util\Common;
|
||||
use App\Util\Exception\InvalidFormException;
|
||||
use App\Util\Exception\RedirectException;
|
||||
use Plugin\Poll\Forms\NewPollForm;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
@@ -61,19 +68,43 @@ class NewPoll
|
||||
{
|
||||
$user = Common::ensureLoggedIn();
|
||||
$numOptions = Common::clamp($num,MIN_OPTS,MAX_OPTS);
|
||||
$form = NewPollForm::make($numOptions);
|
||||
//$form = NewPollForm::make($numOptions);
|
||||
/*
|
||||
$opts =
|
||||
['visibility', ChoiceType::class, ['label' => _m('Visibility:'), 'expanded' => true, 'choices' => [_m('Public') => 'public', _m('Instance') => 'instance', _m('Private') => 'private']]],
|
||||
// ['to', ChoiceType::class, ['label' => _m('To:'), 'multiple' => true, 'expanded' => true, 'choices' => $to_tags]],
|
||||
['post', SubmitType::class, ['label' => _m('Post')]],
|
||||
];
|
||||
*/
|
||||
$opts[] = ['visibility', ChoiceType::class, ['label' => _m('Visibility:'), 'expanded' => true, 'choices' => [_m('Public') => 'public', _m('Instance') => 'instance', _m('Private') => 'private']]];
|
||||
$opts[] = ['Question', TextType::class, ['label' => _m(('Question'))]];
|
||||
|
||||
for ($i = 1; $i <= $numOptions; ++$i) {
|
||||
//['Option_i', TextType::class, ['label' => _m('Option i')]],
|
||||
$opts[] = ['Option_' . $i, TextType::class, ['label' => _m(('Option ' . $i))]];
|
||||
}
|
||||
//$subForm = Form::create($subOpts);
|
||||
//$opts[] = ['options',FormType::class,[$subForm]];
|
||||
$opts[] = ['post_poll', SubmitType::class, ['label' => _m('Post')]];
|
||||
|
||||
$form = Form::create($opts);
|
||||
|
||||
$form->handleRequest($request);
|
||||
$opt = [];
|
||||
if ($form->isSubmitted()) {
|
||||
if ($form->isValid()) {
|
||||
$data = $form->getData();
|
||||
|
||||
$note = Note::create(['gsactor_id' => $user->getId(), $is_local = true]);
|
||||
DB::persist($note);
|
||||
|
||||
Security::sanitize($question = $data['Question']);
|
||||
for ($i = 1; $i <= $numOptions; ++$i) {
|
||||
Security::sanitize($opt[$i - 1] = $data['Option_' . $i]);
|
||||
}
|
||||
|
||||
$options = implode("\n",$opt);
|
||||
$poll = Poll::create(['gsactor_id' => $user->getId(), 'question' => $question, 'options' => $options]);
|
||||
$poll = Poll::create(['gsactor_id' => $user->getId(), 'question' => $question, 'options' => $options, 'note_id' => $note->getId()]);
|
||||
DB::persist($poll);
|
||||
DB::flush();
|
||||
throw new RedirectException('showpoll', ['id' => $poll->getId()]);
|
||||
|
Reference in New Issue
Block a user