Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vjekoart committed Jul 30, 2015
2 parents 236ce20 + 57b0414 commit 88ced11
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Controller/DashboardController.php
Expand Up @@ -85,7 +85,7 @@ public function getPresentationsAction(){
if($numOfUsers === 0)
$presentation['average'] = 0;
else
$presentation['average'] = $sum/$numOfUsers;
$presentation['average'] = round($sum/$numOfUsers, 2);
}

// Limit LiveResults to three presentations
Expand Down
21 changes: 19 additions & 2 deletions Controller/IndexController.php
Expand Up @@ -10,6 +10,7 @@
namespace Netgen\LiveVotingBundle\Controller;

use Netgen\LiveVotingBundle\Entity\Event;
use Netgen\LiveVotingBundle\Entity\Presentation;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -23,6 +24,7 @@
*/
class IndexController extends Controller
{
private $has_voting = false;
/**
* Lists all Events on /user/ landing page
* @return mixed
Expand All @@ -31,14 +33,29 @@ public function landingAction()
{
$events = $this->getDoctrine()->getManager()
->createQueryBuilder("e")
->select("e")
->select("e, p")
->from("LiveVotingBundle:event", "e")
->where('e.begin < :datetime')
->andWhere('e.end > :datetime')
->orderBy('e.event', 'ASC')
->leftjoin('e.presentations', "p")
->setParameter('datetime', new \DateTime())
->getQuery()->getResult();
$events = $this->sortEvents($events);
foreach($events as $key => $event) {
/**
* @var $event Event
*/
$this->has_voting = false;
foreach($event->getPresentations() as $presentationKey => $presentation) {
/**
* @var $presentation Presentation
*/
if($presentation->getVotingEnabled()) {
$this->has_voting = true;
}
}
$events[$key]->hasVoting = $this->has_voting;
}
return $this->render('LiveVotingBundle:Index:landing.html.twig',
array(
'events'=>$events
Expand Down
6 changes: 3 additions & 3 deletions Features/Result/Result.php
Expand Up @@ -56,7 +56,7 @@ public function getResults($event_id){
$tmp = $presentationResult[$vote->getPresentation()->getId()];
$tmp['numOfUsers']++;
$tmp['score'] += $vote->getRate();
$tmp['average'] = round($tmp['score']/$tmp['numOfUsers'], 5);
$tmp['average'] = round($tmp['score']/$tmp['numOfUsers'], 2);
$tmp1[$vote->getPresentation()->getId()] = $tmp;
$presentationResult[$vote->getPresentation()->getId()] = $tmp;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public function getLiveResults($event_id){
$data['numOfUsers']++;
}
if($data['numOfUsers']){
$data['average'] = round($data['score']/$data['numOfUsers'], 5);
$data['average'] = round($data['score']/$data['numOfUsers'], 2);
$result['presentations'][] = array(
'presentation'=>array('name'=>$presentation->getPresentationName(), 'entity'=>$presentation),
'score'=>$data);
Expand Down Expand Up @@ -128,7 +128,7 @@ public function getLiveResultsQuestion($event_id){
$data['numOfUsers']++;
}
if($data['numOfUsers']){
$data['average'] = round($data['score'] / $data['numOfUsers'], 5);
$data['average'] = round($data['score'] / $data['numOfUsers'], 2);
$result['questions'][] = array(
'question' => array(
'name' => $question->getQuestion(),
Expand Down
1 change: 1 addition & 0 deletions Form/PresentationType.php
Expand Up @@ -23,6 +23,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'data_class' => null,
'required' => false
))
->add('globalBrake', 'checkbox', array('attr' => array('class' => 'form-control'), "label" => "Global break (lunch, pause, etc.)"))
->add('hall', 'text' ,array('attr' => array('class' => 'form-control')))
->add('user', 'entity' ,array('attr' => array('class' => 'form-control'), 'class' => 'LiveVotingBundle:User', 'property' => 'email'))
->add('begin')
Expand Down
15 changes: 7 additions & 8 deletions Resources/views/Dashboard/index.html.twig
Expand Up @@ -239,6 +239,13 @@
$(this).removeClass('active');
}
});
this.element.find('.vote-option').each(function () {
if (this.value == vote_number) {
$(this).addClass('active');
} else {
$(this).removeClass('active');
}
});
};
Expand Down Expand Up @@ -392,9 +399,6 @@
}
function pequals(p, presentation) {
console.log("Comparing");
console.log(p);
console.log(presentation);
if(p.id != presentation.id) return false;
if(p.globalBrake != presentation.globalBrake) return false;
if(p.begin != presentation.begin) return false;
Expand All @@ -411,7 +415,6 @@
dataType: "json",
success: function (data) {
if('presentations' in data) {
console.log("Number of displayed presentations "+displayedPresentations.length);
if(displayedPresentations.length == 0) {
var result = $.grep(data.presentations, function(e){
return e.globalBrake;
Expand All @@ -436,17 +439,13 @@
//removing expired presentations
displayedPresentations.forEach(function(displayed_presentation, index, array) {
if(!presentationInArray(displayed_presentation, data.presentations)) {
console.log("Removing");
console.log(displayed_presentation);
$('#presentation-'+displayed_presentation.id).remove();
array.splice(index, 1);
}
});
//adding presentations scheduled next
data.presentations.forEach(function(presentation) {
if(!presentationInArray(presentation, displayedPresentations)) {
console.log("Adding");
console.log(presentation);
$(presentation_template(presentation)).hide().appendTo(srcDiv).fadeIn(1500);
displayedPresentations.push(presentation);
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Index/landing.html.twig
Expand Up @@ -25,7 +25,7 @@
<div class="clearfix visible-xs"></div>
<div class="col-xs-12 col-sm-5 col-lg-4">
<div class="text-right actions">
<a href="{{path('event', {'event_id':event.getId})}}" class="text-center"><i class="fa fa-thumbs-o-up"></i><span>Vote</span></a><!--
{% if event.hasVoting %}<a href="{{path('event', {'event_id':event.getId})}}" class="text-center"><i class="fa fa-thumbs-o-up"></i><span>Vote</span></a>{% endif %}<!--
{% if event.getAllowViewingResults %}
--><a href="{{path('result', {'event_id':event.getId})}}" class="text-center"><i class="fa fa-bar-chart"></i><span>Results</span></a><!--
{% endif %}
Expand Down

0 comments on commit 88ced11

Please sign in to comment.