Skip to content

Commit

Permalink
Avancement
Browse files Browse the repository at this point in the history
  • Loading branch information
GCalmels committed Dec 5, 2014
1 parent dd40030 commit 1cc4aa2
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 3 deletions.
27 changes: 26 additions & 1 deletion src/CG/PlatformBundle/Controller/PlatformController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use CG\PlatformBundle\Form\EventType;
use CG\PlatformBundle\Entity\Event;
use CG\UserBundle\Entity\User;

class PlatformController extends Controller
{
Expand Down Expand Up @@ -73,7 +74,31 @@ public function showRatingsAction()
{
// Les évènements avec le plus de dons
$repository = $this->getDoctrine()->getRepository('CGPlatformBundle:Event');
$events = $repository->findAllByDonations();
$m_events = $repository->findAll();

// Les évènements avec le moins de dons
$l_events = $repository->findAll();

// Les utilisateurs ayant fait le plus de dons
$repository = $this->getDoctrine()->getRepository('CGUserBundle:User');
//$donors = $repository->findOrderByDonations();

$donors = $repository->findAll();
// Les utilisateurs ayant le plus de points
$users = $repository->findOrderByPoints();


return $this->render('CGPlatformBundle:Ratings:list.html.twig', array(
'most_donated_events' => $m_events,
'best_users' => $users,
'best_donors' => $donors,
'less_donated_events' => $l_events));
}


public function showRewardsAction()
{
return $this->render('CGPlatformBundle:Platform:rewards.html.twig');
}

}
46 changes: 46 additions & 0 deletions src/CG/PlatformBundle/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,50 @@ public function getDonationKind()
{
return $this->donationKind;
}

/**
* Get the sum of donations
*
* @return integer
*/
public function getSum()
{
$sum = 0;
foreach ($this->donations as $donation)
{
$sum += $donation->getAmount();
}
return $sum;
}

/**
* Get the count of donations
*
* @return integer
*/
public function getCount()
{
$count = 0;
foreach ($this->donations as $donation)
{
$count += 1;
}
return $count;
}

/**
* Get the average of donations
*
* @return float
*/
public function getAvg()
{
if ($this->getCount() > 0)
{
return $this->getSum() / $this->getCount();
} else {
return 0.0;
}
}

}
5 changes: 4 additions & 1 deletion src/CG/PlatformBundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ cg_platform_event_view:
defaults: { _controller: CGPlatformBundle:Platform:showEvent }
cg_platform_ratings:
path: /ratings
defaults: { _controller: CGPlatformBundle:Platform:showRatings }
defaults: { _controller: CGPlatformBundle:Platform:showRatings }
cg_platform_rewards:
path: /rewards
defaults: { _controller: CGPlatformBundle:Platform:showRewards }
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ cg:
page_header: Accueil
presentation: >
Plate-forme Humanitaire Charity Game !
rewards:
page_header: Récompenses
user:
profile:
modify_button: Modifier
Expand Down Expand Up @@ -32,4 +34,20 @@ event:
menu:
events: Les évènements
ratings: Classements

rewards: Récompenses
ratings:
list:
page_header: Classements
event:
sum: Fonds récoltés
avg: Moyenne par donneur
donor: Donateurs
most_donated: Le plus de dons
best_donors: Les plus donateurs
less_donated: Ces évènements ont besoin de votre aide
best_users: Les utilisateurs les plus actifs
user:
points: Nombre de points
sum: Argent donnée
count_events: Nombre de dons
avg: Montant moyen par donation
3 changes: 3 additions & 0 deletions src/CG/PlatformBundle/Resources/views/Layout/header.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<li>
<a href="{{ path('cg_platform_ratings')}}">{{ 'menu.ratings'|trans({}, 'CGPlatformBundle') }}</a>
</li>
<li>
<a href="{{ path('cg_platform_rewards')}}">{{ 'menu.rewards'|trans({}, 'CGPlatformBundle') }}</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
Expand Down
43 changes: 43 additions & 0 deletions src/CG/PlatformBundle/Resources/views/Platform/rewards.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% trans_default_domain 'CGPlatformBundle' %}

{% extends "CGPlatformBundle:Layout:layout.html.twig" %}

{% block title %}{{ parent() }} | {{ 'cg.rewards.page_header'|trans }} {% endblock %}

{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('bundles/cgplatform/css/home.css') }}">
{% endblock %}

{% block body %}

<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Récompense Jedi</h3>
</div>
<div class="panel-body">
Pour devenir un jedi, il faudra entièrement controller la Force, pour cela, il faudra avoir 10 000 points.
Pour gagner des points, rien de plus simple, faire partager ce site, aider les associations humanitaires et trouver les codes cachés
</div>
</div>

<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Récompense Master</h3>
</div>
<div class="panel-body">
Pour devenir un master, il faudra trouver la bonne ramification sur GitHub et avoir 1 000 points.
</div>
</div>

<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Récompense Padawan</h3>
</div>
<div class="panel-body">
C'est la première récompense, la plus facile, il faut faire un geste humanitaire. Faites un don!
</div>
</div>

{% endblock %}

79 changes: 79 additions & 0 deletions src/CG/PlatformBundle/Resources/views/Ratings/list.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{% trans_default_domain 'CGPlatformBundle' %}

{% extends "CGPlatformBundle:Layout:layout.html.twig" %}

{% block title %}
{{ parent() }} | {{ 'ratings.list.page_header'|trans }}
{% endblock %}

{% block body %}
<div>
<ul>
<div class="row">
<h2>{{ 'ratings.list.most_donated'|trans }}</h2>
{% for event in most_donated_events %}
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<div class="caption">
<h4>{{ event.name }}</h4>
<p>{{ 'ratings.list.event.sum'|trans }}: {{ event.getSum }}</p>
<p>{{ 'ratings.list.event.donor'|trans }}: {{ event.getCount }}</p>
<p>{{ 'ratings.list.event.avg'|trans }}: {{ event.getAvg }}</p>
</div>
</div>
</div>
{% endfor %}
</div>

<div class="row">
<h2>{{ 'ratings.list.best_donors'|trans }}</h2>
{% for user in best_donors %}
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<div class="caption">
<h4>{{ user.username }}</h4>
<p>{{ 'ratings.list.user.sum'|trans }}: {{ user.getSum }}</p>
<p>{{ 'ratings.list.user.count_events'|trans }}: {{ user.getCount }}</p>
<p>{{ 'ratings.list.user.avg'|trans }}: {{ user.getAvg }}</p>
</div>
</div>
</div>
{% endfor %}
</div>

<div class="row">
<h2>{{ 'ratings.list.best_users'|trans }}</h2>
{% for user in best_users %}
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<div class="caption">
<h4>{{ user.username }}</h4>
<p>{{ 'ratings.list.user.points'|trans }}: {{ user.points }}</p>
</div>
</div>
</div>
{% endfor %}
</div>

<div class="row">
<h2>{{ 'ratings.list.less_donated'|trans }}</h2>
{% for event in less_donated_events %}
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<div class="caption">
<h4>{{ event.name }}</h4>
<p>{{ 'ratings.list.event.sum'|trans }}: {{ event.getSum }}</p>
<p>{{ 'ratings.list.event.donor'|trans }}: {{ event.getCount }}</p>
<p>{{ 'ratings.list.event.avg'|trans }}: {{ event.getAvg }}</p>
</div>
</div>
</div>
{% endfor %}
</div>
</ul>
</div>
{% endblock body %}

{% block javascripts %}
{{ parent() }}
{% endblock javascripts %}
46 changes: 46 additions & 0 deletions src/CG/UserBundle/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,50 @@ public function getDonations()
{
return $this->donations;
}

/**
* Get the sum of donations
*
* @return integer
*/
public function getSum()
{
$sum = 0;
foreach ($this->donations as $donation)
{
$sum += $donation->getAmount();
}
return $sum;
}

/**
* Get the count of donations
*
* @return integer
*/
public function getCount()
{
$count = 0;
foreach ($this->donations as $donation)
{
$count += 1;
}
return $count;
}

/**
* Get the average of donations
*
* @return float
*/
public function getAvg()
{
if ($this->getCount() > 0)
{
return $this->getSum() / $this->getCount();
} else {
return 0.0;
}
}

}
19 changes: 19 additions & 0 deletions src/CG/UserBundle/Entity/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,23 @@
*/
class UserRepository extends EntityRepository
{
public function findOrderByPoints()
{
return $this->getEntityManager()
->createQuery(
'SELECT user FROM CGUserBundle:User user ORDER BY user.points DESC'
)
->setMaxResults(3)
->getResult();
}

public function findOrderByDonations()
{
return $this->getEntityManager()
->createQuery(
'SELECT user, SUM(donation.amount) AS money FROM CGUserBundle:User user, CGPlatformBundle:Donation donation WHERE donation.user = user GROUP BY user ORDER BY money DESC'
)
->setMaxResults(3)
->getResult();
}
}

0 comments on commit 1cc4aa2

Please sign in to comment.