Skip to content

Commit

Permalink
Merge pull request #176 from skaut/povolit-zapis-programu-po-zaplaceni
Browse files Browse the repository at this point in the history
přidána možnost povolit zápis programů po zaplacení
  • Loading branch information
Jan Staněk authored Oct 28, 2016
2 parents 3b5c098 + 02ab6f2 commit 815941a
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 32 deletions.
6 changes: 0 additions & 6 deletions app/BackModule/ProgramModule/ApiPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,9 @@ public function actionGetCalendarConfig()
$calConfig['is_allowed_modify_schedule'] = false;
}

$calConfig['is_allowed_log_in_programs'] = (bool)$this->dbsettings->get('is_allowed_log_in_programs') &&
$this->user->isAllowed($this->resource, 'Vybírat si programy') &&
\DateTime::createFromFormat("d.m.Y H:i", $this->dbsettings->get('log_in_programs_from')) <= new \DateTime('now') &&
\DateTime::createFromFormat("d.m.Y H:i", $this->dbsettings->get('log_in_programs_to')) >= new \DateTime('now');

$response = new \Nette\Application\Responses\JsonResponse($calConfig);
$this->sendResponse($response);
$this->terminate();

}

/**
Expand Down
4 changes: 4 additions & 0 deletions app/BackModule/templates/Configuration/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
<td>{label is_allowed_log_in_programs/}</td>
<td>{input is_allowed_log_in_programs}</td>
</tr>
<tr>
<td>{label log_in_programs_after_payment/}</td>
<td>{input log_in_programs_after_payment}</td>
</tr>
<tr>
<td>{label log_in_programs_from/}</td>
<td>{input log_in_programs_from}</td>
Expand Down
11 changes: 9 additions & 2 deletions app/FrontModule/components/ProgramBox/ProgramBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ public function render()
$template->backlink = $this->presenter->context->httpRequest->url->path;
$dbsettings = $this->presenter->context->database->getRepository('\SRS\Model\Settings');

$template->isAllowedLogInPrograms = ((bool)$dbsettings->get('is_allowed_log_in_programs')) &&
$user = $this->presenter->context->user;

$template->logInProgramsAllowed = ((bool)$dbsettings->get('is_allowed_log_in_programs')) &&
\DateTime::createFromFormat("d.m.Y H:i", $dbsettings->get('log_in_programs_from')) <= new \DateTime('now') &&
\DateTime::createFromFormat("d.m.Y H:i", $dbsettings->get('log_in_programs_to')) >= new \DateTime('now');

$template->userHasPermission = $this->presenter->user->isAllowed(Resource::PROGRAM, Permission::CHOOSE_PROGRAMS);
$template->userHasPermission = $user->isAllowed(Resource::PROGRAM, Permission::CHOOSE_PROGRAMS);

if ($user->id !== null) {
$dbuser = $this->presenter->context->database->getRepository('\SRS\Model\User')->find($user->id);
$template->userIsPaid = !((bool)$dbsettings->get('log_in_programs_after_payment')) || $dbuser->isPaid() || !$dbuser->pays();
}

$template->render();
}
Expand Down
16 changes: 11 additions & 5 deletions app/FrontModule/components/ProgramBox/template.latte
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
</div>
{else}

{if !$isAllowedLogInPrograms}
{if !$logInProgramsAllowed}
<div class="notice">
Zapisování programů není v tuto chvíli povoleno.
</div>
{/if}

{if !$userHasPermission}
{elseif !$userHasPermission}
<div class="notice">
{$translator->translate('front.programBox.unapprovedLoginPrograms')}
</div>
{elseif !$userIsPaid}
<div class="notice">
Zapisování programů je povoleno až po zaplacení poplatku.
</div>
{/if}

<script>
var userAllowedLogInPrograms = {$logInProgramsAllowed && $userIsPaid && $userHasPermission};
</script>

<div id="app" ng-app="calendar" ng-controller="FrontCalendarCtrl">
<div class="span2">
<div id="jsMessages">
Expand Down Expand Up @@ -76,7 +82,7 @@
</div>

<div class="modal-footer" ng-model="config">
{if $isAllowedLogInPrograms && $userHasPermission}
{if $logInProgramsAllowed && $userIsPaid && $userHasPermission}
<button ng-hide="event.attends" ng-click="attend(event)" class="btn btn-success pull-left">Přihlásit se na program</button>
<button ng-show="event.attends" ng-click="unattend(event)" class="btn btn-danger pull-left">Odhlásit se z programu</button>
{/if}
Expand Down
17 changes: 11 additions & 6 deletions app/classes/SettingsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,25 @@ public static function create()
$userCustomBooleanCount = $config['common']['parameters']['user_custom_boolean_count'];
$userCustomTextCount = $config['common']['parameters']['user_custom_text_count'];

$settings = array();
$settings[] = new \SRS\Model\Settings('superadmin_created', 'Je vytvořen superadmin?', '0');
$settings[] = new \SRS\Model\Settings('schema_imported', 'Naimportována inicializační databázová data', '1');
$settings[] = new \SRS\Model\Settings('seminar_name', 'Jméno semináře', 'Konfigurace->Jméno semináře');
$settings[] = new \SRS\Model\Settings('seminar_email', 'Email', '[email protected]');
$today = new \DateTime('now');
$tommorow = new \DateTime('now');
$tommorow->modify('+1 day');
$yesterday = new \DateTime('now');
$yesterday->modify('-1 day');

$settings = array();
$settings[] = new \SRS\Model\Settings('superadmin_created', 'Je vytvořen superadmin?', '0');
$settings[] = new \SRS\Model\Settings('schema_imported', 'Naimportována inicializační databázová data', '1');
$settings[] = new \SRS\Model\Settings('seminar_name', 'Jméno semináře', 'Konfigurace->Jméno semináře');
$settings[] = new \SRS\Model\Settings('seminar_email', 'Email', '[email protected]');

$settings[] = new \SRS\Model\Settings('seminar_from_date', 'Začátek semináře', $today->format('d.m.Y'));
$settings[] = new \SRS\Model\Settings('seminar_to_date', 'Konec semináře', $tommorow->format('d.m.Y'));
$settings[] = new \SRS\Model\Settings('basic_block_duration', 'Základní délka trvání jednoho bloku semináře (minuty)', '60');
$settings[] = new \SRS\Model\Settings('is_allowed_add_block', 'Lze vytvářet programové bloky?', '1');
$settings[] = new \SRS\Model\Settings('is_allowed_modify_schedule', 'Lze upravovat harmonogram semináře?', '1');
$settings[] = new \SRS\Model\Settings('is_allowed_log_in_programs', 'Lze se přihlašovat na Programy?', '0');
$settings[] = new \SRS\Model\Settings('is_allowed_log_in_programs', 'Lze se přihlašovat na programy?', '0');
$settings[] = new \SRS\Model\Settings('log_in_programs_after_payment', 'Lze se přihlašovat na programy až po zaplacení?', '1');

// $settings[] = new \SRS\Model\Settings('skautis_app_id', 'skautis app id', '');
$settings[] = new \SRS\Model\Settings('skautis_seminar_id', 'skautis seminar id', '');
Expand All @@ -55,6 +58,8 @@ public static function create()
$settings[] = new \SRS\Model\Settings('log_in_programs_from', 'Přihlašování programů otevřeno od', $yesterday->format('d.m.Y H:i'));
$settings[] = new \SRS\Model\Settings('log_in_programs_to', 'Přihlašování programů otevřeno do', $today->format('d.m.Y H:i'));



$settings[] = new \SRS\Model\Settings('display_users_roles', 'Zobrazovat uživatelské role?', '1');


Expand Down
3 changes: 3 additions & 0 deletions app/forms/Configuration/SettingsFormProgram.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function __construct(IContainer $parent = NULL, $name = NULL, $dbsettings
$this->addCheckbox('is_allowed_log_in_programs', 'Je povoleno přihlašovat se na programové bloky?')
->setDefaultValue($this->dbsettings->get('is_allowed_log_in_programs'));

$this->addCheckbox('log_in_programs_after_payment', 'Povolit zápis programu až po uhrazení poplatku?')
->setDefaultValue($this->dbsettings->get('log_in_programs_after_payment'));

$this->addText('log_in_programs_from', 'Přihlašování programů otevřeno od')->setDefaultValue($this->dbsettings->get('log_in_programs_from'))
->addRule(FORM::PATTERN, 'Datum a čas, od kdy je možné se přihlašovat na programy, není ve správném tvaru', \SRS\Helpers::DATETIME_PATTERN)
->addRule(Form::FILLED, 'Zadejte datum a čas, od kdy je možné se přihlašovat na programy')->getControlPrototype()->class('datetimepicker');
Expand Down
14 changes: 14 additions & 0 deletions app/model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,20 @@ public function isInRole($roleName) {
return false;
}

public function pays() {
foreach ($this->roles as $role) {
if ($role->fee == null) {
return false;
}
}
return true;
}

public function isPaid() {
if ($this->paymentDate !== null)
return true;
}

public function countFee() {
$fee = 0;

Expand Down
6 changes: 3 additions & 3 deletions www/js/calendar/frontControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function FrontCalendarCtrl($scope, $http, $q, $timeout) {
}
}

setColorFront(event, $scope.config);
setColorFront(event);
});
bindCalendar($scope);
});
Expand Down Expand Up @@ -90,7 +90,7 @@ function FrontCalendarCtrl($scope, $http, $q, $timeout) {
}

for (i = $scope.events.length - 1; i >= 0; i--) {
setColorFront($scope.events[i], $scope.config);
setColorFront($scope.events[i]);
}
}
$('#calendar').fullCalendar('updateEvent', event);
Expand Down Expand Up @@ -124,7 +124,7 @@ function FrontCalendarCtrl($scope, $http, $q, $timeout) {
}

for (i = $scope.events.length - 1; i >= 0; i--) {
setColorFront($scope.events[i], $scope.config);
setColorFront($scope.events[i]);
}
}
$('#calendar').fullCalendar('updateEvent', event);
Expand Down
16 changes: 6 additions & 10 deletions www/js/calendar/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ var localization_config = {
slotMinutes:15,
snapMinutes:5,
timeFormat:'H:mm{ - H:mm}',
monthNames:['Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec',
'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec'],
monthNamesShort:['Led', 'Úno', 'Bře', 'Dub', 'Kvě', 'Čvn',
'Čvc', 'Srp', 'Zář', 'Říj', 'Lis', 'Pro'],
dayNames:['Neděle', 'Pondělí', 'Úterý', 'Středa',
'Čtvrtek', 'Pátek', 'Sobota'],
dayNamesShort:['Ne', 'Po', 'Út', 'St',
'Čt', 'Pá', 'So'],
monthNames:['Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec'],
monthNamesShort:['Led', 'Úno', 'Bře', 'Dub', 'Kvě', 'Čvn', 'Čvc', 'Srp', 'Zář', 'Říj', 'Lis', 'Pro'],
dayNames:['Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota'],
dayNamesShort:['Ne', 'Po', 'Út', 'St', 'Čt', 'Pá', 'So'],
buttonText:{
prev:'&nbsp;&#9668;&nbsp;', // left triangle
next:'&nbsp;&#9658;&nbsp;', // right triangle
Expand Down Expand Up @@ -81,8 +77,8 @@ function setColor(event) {
}
}

function setColorFront(event, config) {
if (event.attends == false && !config['is_allowed_log_in_programs']) {
function setColorFront(event) {
if (event.attends == false && !userAllowedLogInPrograms) {
event.color = COLOR_FULL;
}

Expand Down

0 comments on commit 815941a

Please sign in to comment.