Skip to content

Commit

Permalink
Merge pull request #515 from jan-stanek/oprava-roli
Browse files Browse the repository at this point in the history
helpers třída
  • Loading branch information
Jan Staněk authored Feb 28, 2018
2 parents ce977ed + fa7a2cb commit 3b310a2
Show file tree
Hide file tree
Showing 21 changed files with 114 additions and 99 deletions.
3 changes: 2 additions & 1 deletion app/ActionModule/presenters/MaturityPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use App\Services\ApplicationService;
use App\Services\MailService;
use App\Services\ProgramService;
use App\Utils\Helpers;


/**
Expand Down Expand Up @@ -150,7 +151,7 @@ public function actionCheck()
if ($maturityReminder !== NULL && $maturityReminderDate == $maturityDate) {
$this->mailService->sendMailFromTemplate($application->getUser(), '', Template::MATURITY_REMINDER, [
TemplateVariable::SEMINAR_NAME => $this->settingsRepository->getValue(Settings::SEMINAR_NAME),
TemplateVariable::APPLICATION_MATURITY => $maturityDate->format('j. n. Y')
TemplateVariable::APPLICATION_MATURITY => $maturityDate->format(Helpers::DATE_FORMAT)
]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Model\CMS\Document\DocumentRepository;
use App\Model\CMS\Document\TagRepository;
use App\Services\FilesService;
use App\Utils\Helpers;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
use Nette\Application\UI\Form;
Expand Down Expand Up @@ -103,7 +104,7 @@ public function createComponentDocumentsGrid($name)
$grid->addColumnText('description', 'admin.cms.documents_description');

$grid->addColumnDateTime('timestamp', 'admin.cms.documents_timestamp')
->setFormat('j. n. Y H:i');
->setFormat(Helpers::DATETIME_FORMAT);

$tagsOptions = $this->tagRepository->getTagsOptions();

Expand Down
3 changes: 2 additions & 1 deletion app/AdminModule/CMSModule/components/NewsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\AdminModule\CMSModule\Components;

use App\Model\CMS\NewsRepository;
use App\Utils\Helpers;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
use Ublaboo\DataGrid\DataGrid;
Expand Down Expand Up @@ -59,7 +60,7 @@ public function createComponentNewsGrid($name)
$grid->setPagination(FALSE);

$grid->addColumnDateTime('published', 'admin.cms.news_published')
->setFormat('j. n. Y H:i');
->setFormat(Helpers::DATETIME_FORMAT);

$columnMandatory = $grid->addColumnStatus('pinned', 'admin.cms.news_pinned');
$columnMandatory
Expand Down
17 changes: 5 additions & 12 deletions app/AdminModule/CMSModule/components/PagesGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,13 @@ public function createComponentPagesGrid($name)
->endOption()
->onChange[] = [$this, 'changeStatus'];

$grid->addColumnText('roles', 'admin.cms.pages_roles')
->setRenderer(function ($row) {
if (count($this->roleRepository->findAll()) == count($row->getRoles()))
return $this->translator->translate('admin.cms.pages_roles_all');
else {
$roles = [];
foreach ($row->getRoles() as $role) {
$roles[] = $role->getName();
}
return implode(", ", $roles);
}
$grid->addColumnText('roles', 'admin.cms.pages_roles', 'rolesText')
->setRendererOnCondition(function () {
return $this->translator->translate('admin.cms.pages_roles_all');
}, function (Page $page) {
return count($this->roleRepository->findAll()) == $page->getRoles()->count();
});


$rolesOptions = $this->roleRepository->getRolesWithoutRolesOptions([]);
$publicOptions = [
FALSE => 'admin.cms.pages_public_private',
Expand Down
6 changes: 3 additions & 3 deletions app/AdminModule/ConfigurationModule/forms/CustomInputForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ public function processForm(Form $form, \stdClass $values)
$this->customInput = new CustomSelect();

$options = explode(',', $values['options']);
$optionsCleaned = [];
$optionsTrimmed = [];
foreach ($options as $option)
$optionsCleaned[] = trim($option);
$this->customInput->setOptions(implode(', ', $optionsCleaned));
$optionsTrimmed[] = trim($option);
$this->customInput->setOptions(implode(', ', $optionsTrimmed));

break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Model\ACL\Role;
use App\Model\ACL\RoleRepository;
use App\Model\Mailing\MailRepository;
use App\Utils\Helpers;
use Doctrine\ORM\QueryBuilder;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
Expand Down Expand Up @@ -83,7 +84,7 @@ public function createComponentMailHistoryGrid($name)
->setFilterText();

$grid->addColumnDateTime('datetime', 'admin.mailing.history_datetime')
->setFormat('j. n. Y H:i');
->setFormat(Helpers::DATETIME_FORMAT);

$grid->addColumnText('automatic', 'admin.mailing.history_automatic')
->setReplacement([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,7 @@ public function createComponentProgramCategoriesGrid($name)

$grid->addColumnText('name', 'admin.program.categories_name');

$grid->addColumnText('registerableRoles', 'admin.program.categories_registerable_roles')
->setRenderer(function ($row) {
$roles = [];
foreach ($row->getRegisterableRoles() as $role) {
$roles[] = $role->getName();
}
return implode(", ", $roles);
});
$grid->addColumnText('registerableRoles', 'admin.program.categories_registerable_roles', 'registerableRolesText');

$rolesOptions = $this->roleRepository->getRolesWithoutRolesOptions([Role::GUEST, Role::UNAPPROVED, Role::NONREGISTERED]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Model\Program\Room;
use App\Model\Program\RoomRepository;
use App\Services\ExcelExportService;
use App\Utils\Helpers;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
use Ublaboo\DataGrid\DataGrid;
Expand Down Expand Up @@ -82,10 +83,10 @@ public function createComponentRoomScheduleGrid($name)
$grid->setPagination(FALSE);

$grid->addColumnDateTime('start', 'admin.program.rooms_schedule_program_start')
->setFormat('j. n. Y H:i');;
->setFormat(Helpers::DATETIME_FORMAT);;

$grid->addColumnDateTime('end', 'admin.program.rooms_schedule_program_end')
->setFormat('j. n. Y H:i');;
->setFormat(Helpers::DATETIME_FORMAT);;

$grid->addColumnText('name', 'admin.program.rooms_schedule_program_name', 'block.name');

Expand Down
5 changes: 3 additions & 2 deletions app/AdminModule/components/ApplicationsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Services\MailService;
use App\Services\PdfExportService;
use App\Services\ProgramService;
use App\Utils\Helpers;
use App\Utils\Validators;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
Expand Down Expand Up @@ -144,7 +145,7 @@ public function createComponentApplicationsGrid($name)


$grid->addColumnDateTime('applicationDate', 'admin.users.users_applications_application_date')
->setFormat('j. n. Y H:i');
->setFormat(Helpers::DATETIME_FORMAT);

$grid->addColumnText('roles', 'admin.users.users_applications_roles', 'rolesText');

Expand All @@ -155,7 +156,7 @@ public function createComponentApplicationsGrid($name)
$grid->addColumnText('variableSymbol', 'admin.users.users_applications_variable_symbol', 'variableSymbolText');

$grid->addColumnDateTime('maturityDate', 'admin.users.users_applications_maturity_date')
->setFormat('j. n. Y');
->setFormat(Helpers::DATE_FORMAT);

$grid->addColumnText('paymentMethod', 'admin.users.users_applications_payment_method')
->setRenderer(function ($row) {
Expand Down
5 changes: 3 additions & 2 deletions app/AdminModule/components/RolesGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Model\Program\ProgramRepository;
use App\Model\User\UserRepository;
use App\Services\ProgramService;
use App\Utils\Helpers;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
use Ublaboo\DataGrid\DataGrid;
Expand Down Expand Up @@ -96,10 +97,10 @@ public function createComponentRolesGrid($name)
->onChange[] = [$this, 'changeRegisterable'];

$grid->addColumnDateTime('registerableFrom', 'admin.acl.roles_registerable_from')
->setFormat('j. n. Y H:i');
->setFormat(Helpers::DATETIME_FORMAT);

$grid->addColumnDateTime('registerableTo', 'admin.acl.roles_registerable_to')
->setFormat('j. n. Y H:i');
->setFormat(Helpers::DATETIME_FORMAT);

$grid->addColumnText('occupancy', 'admin.acl.roles_occupancy', 'occupancy_text');

Expand Down
24 changes: 4 additions & 20 deletions app/AdminModule/components/UsersGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use App\Services\PdfExportService;
use App\Services\ProgramService;
use App\Services\UserService;
use App\Utils\Helpers;
use Doctrine\ORM\QueryBuilder;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
Expand Down Expand Up @@ -276,7 +277,7 @@ public function createComponentUsersGrid($name)
$grid->addColumnDateTime('lastPaymentDate', 'admin.users.users_last_payment_date');

$grid->addColumnDateTime('rolesApplicationDate', 'admin.users.users_roles_application_date')
->setFormat('j. n. Y H:i');
->setFormat(Helpers::DATETIME_FORMAT);

$columnAttended = $grid->addColumnStatus('attended', 'admin.users.users_attended');
$columnAttended
Expand Down Expand Up @@ -309,13 +310,13 @@ public function createComponentUsersGrid($name)
});

foreach ($this->customInputRepository->findAllOrderedByPosition() as $customInput) {
$grid->addColumnText('customInput' . $customInput->getId(), $this->truncate($customInput->getName(), 20))
$grid->addColumnText('customInput' . $customInput->getId(), Helpers::truncate($customInput->getName(), 20))
->setRenderer(function (User $row) use ($customInput) {
$customInputValue = $row->getCustomInputValue($customInput);
if ($customInputValue) {
switch ($customInputValue->getInput()->getType()) {
case CustomInput::TEXT:
return $this->truncate($customInputValue->getValue(), 20);
return Helpers::truncate($customInputValue->getValue(), 20);

case CustomInput::CHECKBOX:
return $customInputValue->getValue()
Expand Down Expand Up @@ -703,21 +704,4 @@ private function preparePaymentMethodOptionsWithoutEmpty()
$options[$type] = 'common.payment.' . $type;
return $options;
}

/**
* Zkrátí $text na $length znaků a doplní '...'.
* @param $text
* @param $length
* @return bool|string
*/
private function truncate($text, $length)
{
if (strlen($text) > $length) {
$text = $text . " ";
$text = mb_substr($text, 0, $length, 'UTF-8');
$text = mb_substr($text, 0, strrpos($text, ' '), 'UTF-8');
$text = $text . "...";
}
return $text;
}
}
5 changes: 3 additions & 2 deletions app/WebModule/components/ApplicationsGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use App\Services\PdfExportService;
use App\Services\ProgramService;
use App\Services\UserService;
use App\Utils\Helpers;
use App\Utils\Validators;
use Kdyby\Translation\Translator;
use Nette\Application\UI\Control;
Expand Down Expand Up @@ -179,7 +180,7 @@ public function createComponentApplicationsGrid($name)
$grid->setPagination(FALSE);

$grid->addColumnDateTime('applicationDate', 'web.profile.applications_application_date')
->setFormat('j. n. Y H:i');
->setFormat(Helpers::DATETIME_FORMAT);

if ($userHasFixedFeeRole)
$grid->addColumnText('roles', 'web.profile.applications_roles', 'rolesText');
Expand All @@ -192,7 +193,7 @@ public function createComponentApplicationsGrid($name)
$grid->addColumnText('variable_symbol', 'web.profile.applications_variable_symbol', 'variableSymbolText');

$grid->addColumnDateTime('maturityDate', 'web.profile.applications_maturity_date')
->setFormat('j. n. Y');
->setFormat(Helpers::DATE_FORMAT);

$grid->addColumnText('state', 'web.profile.applications_state')
->setRenderer(function (Application $row) {
Expand Down
8 changes: 8 additions & 0 deletions app/model/CMS/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ public function getRoles()
return $this->roles;
}

/**
* @return string
*/
public function getRolesText(): string
{
return implode(', ', $this->roles->map(function (Role $role) {return $role->getName();})->toArray());
}

/**
* @param Collection $roles
*/
Expand Down
28 changes: 18 additions & 10 deletions app/model/Program/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,39 +55,47 @@ public function __construct()
/**
* @return int
*/
public function getId()
public function getId(): int
{
return $this->id;
}

/**
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}

/**
* @param string $name
*/
public function setName($name)
public function setName(string $name): void
{
$this->name = $name;
}

/**
* @return Collection
* @return Role[]|Collection
*/
public function getRegisterableRoles()
public function getRegisterableRoles(): Collection
{
return $this->registerableRoles;
}

/**
* @param Collection $registerableRoles
* @return string
*/
public function getRegisterableRolesText(): string
{
return implode(', ', $this->registerableRoles->map(function (Role $role) {return $role->getName();})->toArray());
}

/**
* @param Role[]|Collection $registerableRoles
*/
public function setRegisterableRoles($registerableRoles)
public function setRegisterableRoles(Collection $registerableRoles)
{
$this->registerableRoles->clear();
foreach ($registerableRoles as $registerableRole)
Expand All @@ -97,16 +105,16 @@ public function setRegisterableRoles($registerableRoles)
/**
* @param Role $role
*/
public function addRole(Role $role)
public function addRole(Role $role): void
{
if (!$this->registerableRoles->contains($role))
$this->registerableRoles->add($role);
}

/**
* @return Collection
* @return Block[]|Collection
*/
public function getBlocks()
public function getBlocks(): Collection
{
return $this->blocks;
}
Expand Down
5 changes: 3 additions & 2 deletions app/model/Settings/SettingsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Model\Settings;

use App\Utils\Helpers;
use Doctrine\ORM\Mapping;
use Kdyby\Doctrine\EntityManager;
use Kdyby\Doctrine\EntityRepository;
Expand Down Expand Up @@ -112,7 +113,7 @@ public function getDateTimeValueText($item): ?string
$value = $this->getValue($item);
if ($value === NULL)
return NULL;
return (new \DateTime($value))->format('j. n. Y H:i');
return (new \DateTime($value))->format(Helpers::DATETIME_FORMAT);
}

/**
Expand Down Expand Up @@ -154,7 +155,7 @@ public function getDateValueText($item): ?string
$value = $this->getValue($item);
if ($value === NULL)
return NULL;
return (new \DateTime($value))->format('j. n. Y');
return (new \DateTime($value))->format(Helpers::DATE_FORMAT);
}

/**
Expand Down
Loading

0 comments on commit 3b310a2

Please sign in to comment.