Skip to content

Commit

Permalink
Merge branch 'master' into feature/VSVGVQ-112
Browse files Browse the repository at this point in the history
# Conflicts:
#	public/css/style.css.map
  • Loading branch information
blemmie committed Aug 30, 2018
2 parents 624edb2 + 6a2562c commit 32b1518
Show file tree
Hide file tree
Showing 28 changed files with 672 additions and 96 deletions.
4 changes: 2 additions & 2 deletions assets/scss/components/_footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
height: auto;
max-height: 80px;
max-width: 150px;
margin-bottom: $global-margin;
margin: $global-margin/2 0;
}
}

Expand All @@ -24,7 +24,7 @@
img {
height: auto;
max-width: 100%;
margin-bottom: $global-margin/2;
margin: $global-margin/4 0;
}
}

Expand Down
4 changes: 4 additions & 0 deletions assets/scss/components/_overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ input, button, select, optgroup, textarea {
padding-left: 1em;
}

.fixed-table-pagination .dropdown-menu.show {
transform: translate3d(0px, -100%, 0px) !important;
}

.page-link {
color: $color-primary;
font-weight: bold;
Expand Down
24 changes: 24 additions & 0 deletions config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,36 @@
accounts_view_index:
path: /
controller: VSV\GVQ_API\Account\Controllers\AccountViewController::index
accounts_inschrijven:
path: /{_locale}/inschrijven
controller: VSV\GVQ_API\Account\Controllers\AccountViewController::register
methods: [GET, POST]
requirements:
_locale: nl
accounts_inscription:
path: /{_locale}/inscription
controller: VSV\GVQ_API\Account\Controllers\AccountViewController::register
methods: [GET, POST]
requirements:
_locale: fr
accounts_view_register:
path: /{_locale}/view/accounts/register
controller: VSV\GVQ_API\Account\Controllers\AccountViewController::register
methods: [GET, POST]
requirements:
_locale: nl|fr
accounts_info:
path: /{_locale}/info
controller: VSV\GVQ_API\Account\Controllers\AccountViewController::info
methods: [GET]
requirements:
_locale: nl|fr
accounts_view_info:
path: /{_locale}/view/accounts/info
controller: VSV\GVQ_API\Account\Controllers\AccountViewController::info
methods: [GET]
requirements:
_locale: nl|fr
accounts_view_register_success:
path: /{_locale}/view/accounts/register/success
controller: VSV\GVQ_API\Account\Controllers\AccountViewController::registerSuccess
Expand Down
8 changes: 8 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ services:
$year: '@quiz_year'
$allowedDelay: '@quiz_delay'

statistics_service:
class: VSV\GVQ_API\Statistics\Service\StatisticsService
arguments:
$startedQuizRepository: '@started_quiz_redis_repository'
$finishedQuizRepository: '@finished_quiz_redis_repository'

### CONTROLLERS ###
VSV\GVQ_API\Account\Controllers\AccountController:
arguments:
Expand Down Expand Up @@ -305,6 +311,8 @@ services:
tags: ['controller.service_arguments']

VSV\GVQ_API\Statistics\Controllers\StatisticsViewController:
arguments:
$statisticsService: '@statistics_service'
tags: ['controller.service_arguments']

VSV\GVQ_API\Dashboard\Controllers\DashboardViewController:
Expand Down
7 changes: 5 additions & 2 deletions public/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions public/css/style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Account/Controllers/AccountViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ public function register(Request $request): Response
);
}

/**
* @return Response
*/
public function info(): Response
{
return $this->render('accounts/info.html.twig');
}

/**
* @return Response
*/
Expand Down
17 changes: 17 additions & 0 deletions src/Quiz/ValueObjects/StatisticsKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,21 @@ public static function createFromQuiz(Quiz $quiz): StatisticsKey

return new StatisticsKey($statisticsKey);
}

/**
* @return StatisticsKey[]
*/
public static function getAllKeys(): array
{
return [
new StatisticsKey(self::INDIVIDUAL_NL),
new StatisticsKey(self::INDIVIDUAL_FR),
new StatisticsKey(self::PARTNER_NL),
new StatisticsKey(self::PARTNER_FR),
new StatisticsKey(self::COMPANY_NL),
new StatisticsKey(self::COMPANY_FR),
new StatisticsKey(self::CUP_NL),
new StatisticsKey(self::CUP_FR),
];
}
}
25 changes: 24 additions & 1 deletion src/Statistics/Controllers/StatisticsViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,37 @@

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use VSV\GVQ_API\Statistics\Service\StatisticsService;

class StatisticsViewController extends AbstractController
{
/**
* @var StatisticsService
*/
private $statisticsService;

/**
* @param StatisticsService $statisticsService
*/
public function __construct(StatisticsService $statisticsService)
{
$this->statisticsService = $statisticsService;
}

/**
* @return Response
*/
public function statistics(): Response
{
return $this->render('statistics/statistics.html.twig');
$startedCounts = $this->statisticsService->getStartedQuizCounts();
$finishedCounts = $this->statisticsService->getFinishedQuizCounts();

return $this->render(
'statistics/statistics.html.twig',
[
'startedCounts' => $startedCounts,
'finishedCounts' => $finishedCounts,
]
);
}
}
95 changes: 95 additions & 0 deletions src/Statistics/Service/StatisticsService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php declare(strict_types=1);

namespace VSV\GVQ_API\Statistics\Service;

use VSV\GVQ_API\Quiz\Repositories\CounterRepository;
use VSV\GVQ_API\Quiz\Repositories\FinishedQuizRepository;
use VSV\GVQ_API\Quiz\Repositories\StartedQuizRepository;
use VSV\GVQ_API\Quiz\ValueObjects\StatisticsKey;

class StatisticsService
{
/**
* @var StartedQuizRepository
*/
private $startedQuizRepository;

/**
* @var FinishedQuizRepository
*/
private $finishedQuizRepository;

/**
* @var StatisticsKey[]
*/
private $statisticsKeys;

/**
* @param StartedQuizRepository $startedQuizRepository
* @param FinishedQuizRepository $finishedQuizRepository
*/
public function __construct(
StartedQuizRepository $startedQuizRepository,
FinishedQuizRepository $finishedQuizRepository
) {
$this->startedQuizRepository = $startedQuizRepository;
$this->finishedQuizRepository = $finishedQuizRepository;

$this->statisticsKeys = StatisticsKey::getAllKeys();
}

/**
* @return int[]
*/
public function getStartedQuizCounts(): array
{
return $this->getCountsFromRepository($this->startedQuizRepository);
}

/**
* @return int[]
*/
public function getFinishedQuizCounts(): array
{
return $this->getCountsFromRepository($this->finishedQuizRepository);
}

/**
* @param CounterRepository $counterRepository
* @return array
*/
private function getCountsFromRepository(CounterRepository $counterRepository): array
{
$totalNL = 0;
$totalFR = 0;
$counts = [];

foreach ($this->statisticsKeys as $statisticsKey) {
$key = $statisticsKey->toNative();
$counts[$key] = $counterRepository->getCount($statisticsKey);
if (substr($key, -2) === 'nl') {
$totalNL += $counts[$key];
} else {
$totalFR += $counts[$key];
}

$totalKey = substr($key, 0, -2).'total';

if (key_exists($totalKey, $counts)) {
$counts[$totalKey] += $counts[$key];
} else {
$counts[$totalKey] = $counts[$key];
}
}

$counts['quiz_total_nl'] = $totalNL - $counts['cup_nl'];
$counts['quiz_total_fr'] = $totalFR - $counts['cup_fr'];
$counts['quiz_total'] = $counts['quiz_total_nl'] + $counts['quiz_total_fr'];
$counts['total_nl'] = $totalNL;
$counts['total_fr'] = $totalFR;
$counts['total'] = $totalNL + $totalFR;


return $counts;
}
}
Loading

0 comments on commit 32b1518

Please sign in to comment.