mirror of
https://github.com/friendica/friendica
synced 2024-12-23 00:00:21 +00:00
Merge pull request #11520 from annando/display-polls
Display poll results
This commit is contained in:
commit
69984ac6bc
4 changed files with 523 additions and 473 deletions
|
@ -58,7 +58,7 @@ case "$MODE" in
|
|||
OUTFILE="$FULLPATH/../view/lang/C/messages.po"
|
||||
FINDSTARTDIR="."
|
||||
# skip addon folder
|
||||
FINDOPTS="( -path ./addon -or -path ./addons -or -path ./addons-extra -or -path ./tests -or -path ./view/lang -or -path ./view/smarty3 -or -path ./vendor ) -prune -or"
|
||||
FINDOPTS="( -path ./addon -or -path ./addons -or -path ./addons-extra -or -path ./tests -or -path ./view/lang -or -path ./view/smarty3 -or -path ./vendor -or -path ./local -or -path ./avatar -or -path ./proxy ) -prune -or"
|
||||
|
||||
F9KVERSION=$(cat ./VERSION);
|
||||
echo "Friendica version $F9KVERSION"
|
||||
|
|
|
@ -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('%s (%d%s, %d votes)', $option['name'], round($percent, 1), '%', $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
|
||||
*
|
||||
|
|
File diff suppressed because it is too large
Load diff
7
view/templates/content/question.tpl
Normal file
7
view/templates/content/question.tpl
Normal file
|
@ -0,0 +1,7 @@
|
|||
</p><ul>
|
||||
{{foreach $options as $option}}
|
||||
<li>{{$option.vote}}</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
{{$summary}}
|
||||
</p>
|
Loading…
Reference in a new issue