]> git.mxchange.org Git - friendica.git/commitdiff
Polls are now displayed
authorMichael <heluecht@pirati.ca>
Mon, 16 May 2022 04:55:15 +0000 (04:55 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 16 May 2022 04:55:15 +0000 (04:55 +0000)
src/Model/Item.php
view/templates/content/question.tpl [new file with mode: 0644]

index 13c26c245ad061bdd12dfc3687dfde710f1d65ce..d08b938581e40f7e8e4988d553556c1d4c0e973a 100644 (file)
@@ -42,6 +42,7 @@ use Friendica\Util\Map;
 use Friendica\Util\Network;
 use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
+use Friendica\Util\Temporal;
 use Friendica\Worker\Delivery;
 use LanguageDetection\Language;
 
@@ -95,6 +96,7 @@ class Item
                'event-created', 'event-edited', 'event-start', 'event-finish',
                'event-summary', 'event-desc', 'event-location', 'event-type',
                'event-nofinish', 'event-ignore', 'event-id',
+               "question-id", "question-multiple", "question-voters", "question-end-time",
                'delivery_queue_count', 'delivery_queue_done', 'delivery_queue_failed'
        ];
 
@@ -2852,6 +2854,7 @@ class Item
                $s = self::addVisualAttachments($attachments, $item, $s, false);
                $s = self::addLinkAttachment($item['uri-id'], $attachments, $body, $s, false, $shared_links);
                $s = self::addNonVisualAttachments($attachments, $item, $s, false);
+               $s = self::addQuestions($item, $s);
 
                // Map.
                if (strpos($s, '<div class="map">') !== false && !empty($item['coord'])) {
@@ -3177,6 +3180,35 @@ class Item
                return $content;
        }
 
+       private static function addQuestions(array $item, string $content)
+       {
+               DI::profiler()->startRecording('rendering');
+               if (!empty($item['question-id'])) {
+                       $question = [
+                               'id'       => $item['question-id'],
+                               'multiple' => $item['question-multiple'],
+                               'voters'   => $item['question-voters'],
+                               'endtime'  => $item['question-end-time']
+                       ];
+
+                       $options = Post\QuestionOption::getByURIId($item['uri-id']);
+                       foreach ($options as $key => $option) {
+                               $percent = $question['voters'] ? ($option['replies'] / $question['voters'] * 100) : 0;
+
+                               $options[$key]['percent'] = $percent;
+                               $options[$key]['vote']    = DI::l10n()->t('%d%s: %s (%d votes)', round($percent, 1), '%', $option['name'], $option['replies']);
+                       }
+
+                       $content .= Renderer::replaceMacros(Renderer::getMarkupTemplate('content/question.tpl'), [
+                               '$question' => $question,
+                               '$options'  => $options,
+                               '$summary'  => DI::l10n()->t('%d voters. Poll end: %s', $question['voters'], Temporal::getRelativeDate($question['endtime'])),
+                       ]);
+       }
+               DI::profiler()->stopRecording();
+               return $content;
+       }
+
        /**
         * get private link for item
         *
diff --git a/view/templates/content/question.tpl b/view/templates/content/question.tpl
new file mode 100644 (file)
index 0000000..767cfda
--- /dev/null
@@ -0,0 +1,7 @@
+</p><ul>
+{{foreach $options as $option}}
+       <li>{{$option.vote}}</li>
+{{/foreach}}
+</ul>
+{{$summary}}
+</p>
\ No newline at end of file