Merge branch 'master' of https://github.com/v1r0x/polls into language-fix
This commit is contained in:
Коммит
4669388c7b
|
@ -168,7 +168,7 @@ class PageController extends Controller {
|
|||
*/
|
||||
public function gotoPoll($hash) {
|
||||
$poll = $this->eventMapper->findByHash($hash);
|
||||
if($poll->getType() === '0') {
|
||||
if($poll->getType() == '0') {
|
||||
$dates = $this->dateMapper->findByPoll($poll->getId());
|
||||
$votes = $this->participationMapper->findByPoll($poll->getId());
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ class PageController extends Controller {
|
|||
public function editPoll($hash) {
|
||||
$poll = $this->eventMapper->findByHash($hash);
|
||||
if($this->userId !== $poll->getOwner()) return new TemplateResponse('polls', 'no.create.tmpl');
|
||||
if($poll->getType() === '0') $dates = $this->dateMapper->findByPoll($poll->getId());
|
||||
if($poll->getType() == '0') $dates = $this->dateMapper->findByPoll($poll->getId());
|
||||
else $dates = $this->textMapper->findByPoll($poll->getId());
|
||||
return new TemplateResponse('polls', 'create.tmpl', ['poll' => $poll, 'dates' => $dates, 'userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]);
|
||||
}
|
||||
|
@ -341,15 +341,10 @@ class PageController extends Controller {
|
|||
$ins = $this->eventMapper->insert($event);
|
||||
$poll_id = $ins->getId();
|
||||
sort($chosenDates);
|
||||
$tz = \OC::$server->getConfig()->getUserValue($this->userId, 'core', 'timezone', 'UTC');
|
||||
$timezone = new \DateTimeZone($tz);
|
||||
foreach ($chosenDates as $el) {
|
||||
$date = new Date();
|
||||
$date->setPollId($poll_id);
|
||||
$dateTime = new \DateTime(date(\DateTime::ATOM, $el), $timezone);
|
||||
$offset = $timezone->getOffset($dateTime);
|
||||
$dateTime->setTimestamp($dateTime->getTimestamp() + $timezone->getOffset($dateTime));
|
||||
$date->setDt($dateTime->format('Y-m-d H:i:s'));
|
||||
$date->setDt(date('Y-m-d H:i:s', $el));
|
||||
$this->dateMapper->insert($date);
|
||||
}
|
||||
} else {
|
||||
|
@ -401,10 +396,10 @@ class PageController extends Controller {
|
|||
if($changed === 'true') {
|
||||
$dates = json_decode($dates);
|
||||
$types = json_decode($types);
|
||||
if($poll->getType() === '0') $this->participationMapper->deleteByPollAndUser($pollId, $userId);
|
||||
if($poll->getType() == '0') $this->participationMapper->deleteByPollAndUser($pollId, $userId);
|
||||
else $this->participationTextMapper->deleteByPollAndUser($pollId, $userId);
|
||||
for($i=0; $i<count($dates); $i++) {
|
||||
if($poll->getType() === '0') {
|
||||
if($poll->getType() == '0') {
|
||||
$part = new Participation();
|
||||
$part->setPollId($pollId);
|
||||
$part->setUserId($userId);
|
||||
|
|
45
js/vote.js
45
js/vote.js
|
@ -4,6 +4,8 @@ var newUserTypes = [];
|
|||
var max_votes = 0;
|
||||
var values_changed = false;
|
||||
|
||||
var tzOffset = new Date().getTimezoneOffset();
|
||||
|
||||
$.fn.switchClass = function(a, b) {
|
||||
this.removeClass(a);
|
||||
this.addClass(b);
|
||||
|
@ -11,6 +13,49 @@ $.fn.switchClass = function(a, b) {
|
|||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
// count how many times in each date
|
||||
var arr_dates = []; // will be like: [21.02] => 3
|
||||
var arr_years = []; // [1992] => 6
|
||||
var prev = '';
|
||||
var dateStr = '';
|
||||
$('.hidden-dates').each(function(i, obj) {
|
||||
var exDt = new Date(obj.value+'+0000'); // add +0000 = UTC
|
||||
var day = ('0' + exDt.getDate()).substr(-2);
|
||||
var month = ('0' + (exDt.getMonth()+1)).substr(-2);
|
||||
var day_month = day + '.' + month;
|
||||
var year = exDt.getFullYear();
|
||||
|
||||
if(typeof arr_dates[day_month] != 'undefined') {
|
||||
arr_dates[day_month] += 1;
|
||||
} else {
|
||||
arr_dates[day_month] = 1;
|
||||
}
|
||||
if(typeof arr_years[year] != 'undefined') {
|
||||
arr_years[year] += 1;
|
||||
} else {
|
||||
arr_years[year] = 1;
|
||||
}
|
||||
var c = (prev != (year + day_month) ? ' bordered' : '');
|
||||
prev = (year + day_month);
|
||||
var ch_obj = ('0' + (exDt.getHours())).substr(-2) + ':' + ('0' + exDt.getMinutes()).substr(-2)
|
||||
dateStr += '<th class="time-slot-cell' + c + '">' + ch_obj + '</th>';
|
||||
});
|
||||
|
||||
var for_string_dates = '';
|
||||
for(var k in arr_dates) {
|
||||
for_string_dates += '<th colspan="' + arr_dates[k] + '" class="bordered">' + k + '</th>';
|
||||
}
|
||||
|
||||
var for_string_years = '';
|
||||
for(var k in arr_years) {
|
||||
for_string_years += '<th colspan="' + arr_years[k] + '" class="bordered">' + k + '</th>';
|
||||
}
|
||||
|
||||
$(for_string_years).insertAfter('.year-row');
|
||||
$('.date-row').append(for_string_dates);
|
||||
$('#time-row-header').append(dateStr);
|
||||
$(dateStr).insertAfter('#time-row-footer');
|
||||
|
||||
$('#submit_finish_vote').click(function() {
|
||||
var form = document.finish_vote;
|
||||
var ac = document.getElementById('user_name');
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
$dates = $_['dates'];
|
||||
$chosen = '[';
|
||||
foreach($dates as $d) {
|
||||
if($poll->getType() === '0') $chosen .= strtotime($d->getDt());
|
||||
if($poll->getType() == '0') $chosen .= strtotime($d->getDt());
|
||||
else $chosen .= '"' . $d->getText() . '"';
|
||||
$chosen .= ',';
|
||||
}
|
||||
|
@ -97,11 +97,11 @@
|
|||
|
||||
<label class="input_title"><?php p($l->t('Type')); ?></label>
|
||||
|
||||
<input type="radio" name="pollType" id="event" value="event" <?php if(!$isUpdate || $poll->getType() === '0') print_unescaped('checked'); ?> />
|
||||
<input type="radio" name="pollType" id="event" value="event" <?php if(!$isUpdate || $poll->getType() == '0') print_unescaped('checked'); ?> />
|
||||
<label for="event"><?php p($l->t('Event schedule')); ?></label>
|
||||
|
||||
<!-- TODO texts to db -->
|
||||
<input type="radio" name="pollType" id="text" value="text" <?php if($isUpdate && $poll->getType() === '1') print_unescaped('checked'); ?>>
|
||||
<input type="radio" name="pollType" id="text" value="text" <?php if($isUpdate && $poll->getType() == '1') print_unescaped('checked'); ?>>
|
||||
<label for="text"><?php p($l->t('Text based')); ?></label>
|
||||
|
||||
<label for="isAnonymous" class="input_title"><?php p($l->t('Anonymous')) ?></label>
|
||||
|
@ -122,13 +122,13 @@
|
|||
</div>
|
||||
<div class="col-50">
|
||||
<h2><?php p($l->t('Choices')); ?></h2>
|
||||
<div id="date-select-container" <?php if($isUpdate && $poll->getType() === '1') print_unescaped('style="display:none;"'); ?> >
|
||||
<div id="date-select-container" <?php if($isUpdate && $poll->getType() == '1') print_unescaped('style="display:none;"'); ?> >
|
||||
<label for="datetimepicker" class="input_title"><?php p($l->t('Dates')); ?></label>
|
||||
<input id="datetimepicker" type="text" />
|
||||
<table id="selected-dates-table" class="choices">
|
||||
</table>
|
||||
</div>
|
||||
<div id="text-select-container" <?php if(!$isUpdate || $poll->getType() === '0') print_unescaped('style="display:none;"'); ?> >
|
||||
<div id="text-select-container" <?php if(!$isUpdate || $poll->getType() == '0') print_unescaped('style="display:none;"'); ?> >
|
||||
<label for="text-title" class="input_title"><?php p($l->t('Text item')); ?></label>
|
||||
<div class="input-group">
|
||||
<input type="text" id="text-title" placeholder="<?php print_unescaped('Insert text...'); ?>" />
|
||||
|
|
|
@ -25,37 +25,15 @@ if ($poll->getExpire() === null) {
|
|||
$expired = time() > strtotime($poll->getExpire());
|
||||
}
|
||||
|
||||
if ($poll->getType() === '0') {
|
||||
// count how many times in each date
|
||||
$arr_dates = null; // will be like: [21.02] => 3
|
||||
$arr_years = null; // [1992] => 6
|
||||
foreach($dates as $d) {
|
||||
$day_month = date('d.m', strtotime($d->getDt()));
|
||||
$year = date('Y', strtotime($d->getDt()));
|
||||
?>
|
||||
|
||||
if (isset($arr_dates[$day_month])) {
|
||||
$arr_dates[$day_month] += 1;
|
||||
} else {
|
||||
$arr_dates[$day_month] = 1;
|
||||
}
|
||||
<?php if($poll->getType() == '0') : ?>
|
||||
<?php foreach($dates as $d) : ?>
|
||||
<input class="hidden-dates" type="hidden" value="<?php print_unescaped($d->getDt()); ?>" />
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
|
||||
if (isset($arr_years[$year])) {
|
||||
$arr_years[$year] += 1;
|
||||
} else {
|
||||
$arr_years[$year] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$for_string_dates = '';
|
||||
foreach (array_keys($arr_dates) as $dt) {
|
||||
$for_string_dates .= '<th colspan="' . $arr_dates[$dt] . '" class="bordered">' . $dt . '</th>';
|
||||
}
|
||||
|
||||
$for_string_years = '';
|
||||
foreach (array_keys($arr_years) as $year) {
|
||||
$for_string_years .= '<th colspan="' . $arr_years[$year] . '" class="bordered">' . $year . '</th>';
|
||||
}
|
||||
}
|
||||
<?php
|
||||
if ($poll->getDescription() !== null && $poll->getDescription() !== '') {
|
||||
$description = nl2br($poll->getDescription());
|
||||
} else {
|
||||
|
@ -104,9 +82,8 @@ $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' =>
|
|||
<thead>
|
||||
<tr>
|
||||
<?php
|
||||
if ($poll->getType() === '0') {
|
||||
print_unescaped('<th rowspan=3></th>');
|
||||
print_unescaped($for_string_years);
|
||||
if ($poll->getType() == '0') {
|
||||
print_unescaped('<th rowspan=3 class="year-row"></th>');
|
||||
print_unescaped('<th class="bordered" rowspan=3>' . $l->t('All') . '</th>');
|
||||
} else {
|
||||
print_unescaped('<th></th>');
|
||||
|
@ -118,17 +95,8 @@ $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' =>
|
|||
?>
|
||||
</tr>
|
||||
<?php
|
||||
if ($poll->getType() === '0'){
|
||||
print_unescaped('<tr>' . $for_string_dates . '</tr><tr>');
|
||||
$prev = "";
|
||||
for ($i = 0; $i < count($dates); $i++) {
|
||||
$c = ($prev != date('Y-m-d', strtotime($dates[$i]->getDt())) ? ' bordered' : '');
|
||||
$prev = date('Y-m-d', strtotime($dates[$i]->getDt()));
|
||||
$ch_obj = date('H:i', strtotime($dates[$i]->getDt()));
|
||||
print_unescaped('<th class="time-slot-cell' . $c . '">' . $ch_obj . '</th>');
|
||||
|
||||
}
|
||||
print_unescaped('</tr>');
|
||||
if ($poll->getType() == '0'){
|
||||
print_unescaped('<tr class="date-row"></tr><tr id="time-row-header"></tr>');
|
||||
}
|
||||
?>
|
||||
</thead>
|
||||
|
@ -177,7 +145,7 @@ $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' =>
|
|||
// loop over dts
|
||||
$i_tot = 0;
|
||||
foreach($dates as $dt) {
|
||||
if ($poll->getType() === '0') {
|
||||
if ($poll->getType() == '0') {
|
||||
$date_id = strtotime($dt->getDt());
|
||||
} else {
|
||||
$date_id = $dt->getText();
|
||||
|
@ -186,16 +154,16 @@ $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' =>
|
|||
$found = false;
|
||||
foreach ($others[$usr] as $vote) {
|
||||
$voteVal = null;
|
||||
if($poll->getType() === '0') {
|
||||
if($poll->getType() == '0') {
|
||||
$voteVal = strtotime($vote->getDt());
|
||||
} else {
|
||||
$voteVal = $vote->getText();
|
||||
}
|
||||
if ($date_id === $voteVal) {
|
||||
if ($vote->getType() === '1') {
|
||||
if ($vote->getType() == '1') {
|
||||
$cl = 'poll-cell-is';
|
||||
$total_y[$i_tot]++;
|
||||
} else if ($vote->getType() === '0') {
|
||||
} else if ($vote->getType() == '0') {
|
||||
$cl = 'poll-cell-not';
|
||||
$total_n[$i_tot]++;
|
||||
} else {
|
||||
|
@ -234,7 +202,7 @@ $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' =>
|
|||
}
|
||||
$i_tot = 0;
|
||||
foreach ($dates as $dt) {
|
||||
if ($poll->getType() === '0') {
|
||||
if ($poll->getType() == '0') {
|
||||
$date_id = strtotime($dt->getDt());
|
||||
} else {
|
||||
$date_id = $dt->getText();
|
||||
|
@ -244,19 +212,19 @@ $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' =>
|
|||
if (isset($user_voted)) {
|
||||
foreach ($user_voted as $obj) {
|
||||
$voteVal = null;
|
||||
if($poll->getType() === '0') {
|
||||
if($poll->getType() == '0') {
|
||||
$voteVal = strtotime($obj->getDt());
|
||||
} else {
|
||||
$voteVal = $obj->getText();
|
||||
}
|
||||
if ($voteVal === $date_id) {
|
||||
if ($obj->getType() === '1') {
|
||||
if ($obj->getType() == '1') {
|
||||
$cl = 'poll-cell-active-is';
|
||||
$total_y[$i_tot]++;
|
||||
} else if ($obj->getType() === '0') {
|
||||
} else if ($obj->getType() == '0') {
|
||||
$cl = 'poll-cell-active-not';
|
||||
$total_n[$i_tot]++;
|
||||
} else if($obj->getType() === '2'){
|
||||
} else if($obj->getType() == '2'){
|
||||
$cl = 'poll-cell-active-maybe';
|
||||
}
|
||||
break;
|
||||
|
@ -283,7 +251,7 @@ $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' =>
|
|||
<?php for ($i = 0 ; $i < count($dates) ; $i++) : ?>
|
||||
<td class="total">
|
||||
<?php
|
||||
$classSuffix = $poll->getType() === '0' ? strtotime($dates[$i]->getDt()) : str_replace(' ', '_', $dates[$i]->getText());
|
||||
$classSuffix = $poll->getType() == '0' ? strtotime($dates[$i]->getDt()) : str_replace(' ', '_', $dates[$i]->getText());
|
||||
if (isset($total_y[$i])) {
|
||||
$val = $total_y[$i];
|
||||
} else {
|
||||
|
@ -316,23 +284,16 @@ $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' =>
|
|||
</tbody>
|
||||
<tfoot>
|
||||
<?php
|
||||
if ($poll->getType() === '0') {
|
||||
print_unescaped('<tr><th rowspan=3></th>');
|
||||
$prev = "";
|
||||
for ($i = 0; $i < count($dates); $i++) {
|
||||
$c = ($prev != date('Y-m-d', strtotime($dates[$i]->getDt())) ? ' bordered' : '');
|
||||
$prev = date('Y-m-d', strtotime($dates[$i]->getDt()));
|
||||
$ch_obj = date('H:i', strtotime($dates[$i]->getDt()));
|
||||
print_unescaped('<th class="time-slot-cell' . $c . '">' . $ch_obj . '</th>');
|
||||
}
|
||||
if ($poll->getType() == '0') {
|
||||
print_unescaped('<tr><th rowspan=3 id="time-row-footer"></th>');
|
||||
print_unescaped('<th rowspan=3 class="bordered">' . $l->t('All') . '</th></tr>');
|
||||
print_unescaped('<tr>' . $for_string_dates . '</tr>');
|
||||
print_unescaped('<tr class="date-row"></tr>');
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<?php
|
||||
if ($poll->getType() === '0') {
|
||||
print_unescaped($for_string_years);
|
||||
if ($poll->getType() == '0') {
|
||||
print_unescaped('<th colspan=0 class="year-row" style="display: none;"></th>');
|
||||
} else {
|
||||
print_unescaped('<th></th>');
|
||||
foreach ($dates as $el) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче