Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
$rules = [
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
'@autoPHPMigration:risky' => true,

// overwrite some Symfony rules
'braces_position' => [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Then you will need to build the assets with `npm run build` or `npm run dev`. Th
2. Run SQL from `install.sql`.
3. Configure the event information in `app/Config/local.neon` as described in the [configuration documentation](docs/configuration.md). Do not forget to set up admin password and database credentials in either `app/Config/local.neon` or `app/Config/private.neon`.
4. Make `temp` and `log` directories writeable.
5. Change e-mail templates in `app/Templates/Mail`.
5. Change e-mail templates in `app/Presenters/templates/Mail`.
6. The entry point of the application is in the `www` directory, configure your web server accordingly.

## Thanks
Expand Down
3 changes: 1 addition & 2 deletions app/Components/BootstrapRadioList.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
* Because Bs5FormRenderer only gets us so far.
*/
final class BootstrapRadioList extends Controls\RadioList {
/** @var bool */
public $generateId = true;
public bool $generateId = true;

public function getControl(): Html {
if ($this->hasErrors()) {
Expand Down
14 changes: 9 additions & 5 deletions app/Components/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
use Stringable;

/**
* Nette forms helper modified to work better with Bootstrap styles.
* A subset of `Nette\Forms\Helpers` modified to work better with Bootstrap styles.
*/
class Helpers extends Nette\Forms\Helpers {
final class Helpers {
/**
* The difference from `Nette\Forms\Helpers` is that we move `label` tag after the `input` tag, instead of having the former wrap the latter.
*
* @param array<string, mixed> $inputAttrs
* @param array<string, mixed> $labelAttrs
* @param Html|Stringable|null $wrapper
Expand All @@ -24,7 +26,7 @@ public static function createInputList(
array $items,
?array $inputAttrs = null,
?array $labelAttrs = null,
$wrapper = null
$wrapper = null,
): string {
[$inputAttrs, $inputTag] = self::prepareAttrs($inputAttrs, 'input');
[$labelAttrs, $labelTag] = self::prepareAttrs($labelAttrs, 'label');
Expand All @@ -44,7 +46,7 @@ public static function createInputList(

$input->value = $value;
$res .= ($res === '' && $wrapperEnd === '' ? '' : $wrapper)
. $inputTag . $input->attributes() . (Html::$xhtml ? ' />' : '>')
. $inputTag . $input->attributes() . '>'
. $labelTag . $label->attributes() . '>'
. ($caption instanceof Nette\HtmlStringable ? $caption : htmlspecialchars((string) $caption, \ENT_NOQUOTES, 'UTF-8'))
. '</label>'
Expand All @@ -55,6 +57,8 @@ public static function createInputList(
}

/**
* This is copied as is from `Nette\Forms\Helpers` since we cannot access it from here.
*
* @param array<string, mixed> $attrs
*
* @return array{array<string, array<string, mixed>>, string}
Expand All @@ -66,7 +70,7 @@ private static function prepareAttrs(?array $attrs, string $name): array {
$p = substr($k, 0, -1);
unset($attrs[$k], $attrs[$p]);
if ($k[-1] === '?') {
$dynamic[$p] = array_fill_keys((array) $v, true);
$dynamic[$p] = array_fill_keys((array) $v, value: true);
} elseif (\is_array($v) && $v) {
$dynamic[$p] = $v;
} else {
Expand Down
15 changes: 7 additions & 8 deletions app/Config/common.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ parameters:

application:
errorPresenter: Error
mapping:
*: App\*Module\Presenters\*Presenter
mapping: App\*Module\Presenters\*Presenter

di:
export:
Expand All @@ -31,7 +30,7 @@ latte:
strictTypes: true
strictParsing: true
extensions:
- App\Templates\Accessory\LatteExtension
- App\Presenters\Accessory\LatteExtension

session:
autoStart: yes
Expand Down Expand Up @@ -60,17 +59,17 @@ orm:

services:
- App\Helpers\EmailFactory(%appDir%)
- App\Helpers\Parameters(%parameters%)
- App\Helpers\Parameters(@container::getParameters())
- App\Helpers\SpaydQrGenerator
- App\Model\Configuration\Entries::from(%entries%)
- App\Model\TeamManager(%adminPassword%)
- App\Forms\FormFactory
- App\Forms\TeamFormFactory
- App\Router\RouterFactory::createRouter
- App\Templates\Filters\CategoryFormatFilter
- App\Templates\Filters\CurrencyExchangeFilter
- App\Templates\Filters\PriceFilter
- App\Templates\Filters\WrapInParagraphsFilter
- App\Presenters\Accessory\Filters\CategoryFormatFilter
- App\Presenters\Accessory\Filters\CurrencyExchangeFilter
- App\Presenters\Accessory\Filters\PriceFilter
- App\Presenters\Accessory\Filters\WrapInParagraphsFilter
exchange: Money\Exchange\FixedExchange([])

translation:
Expand Down
2 changes: 1 addition & 1 deletion app/Exporters/CsvExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\Model\Configuration\Fields;
use App\Model\Orm\Person\Person;
use App\Model\Orm\Team\Team;
use App\Templates\Filters\CategoryFormatFilter;
use App\Presenters\Accessory\Filters\CategoryFormatFilter;
use Nextras\Orm\Collection\ICollection;
use SplFileObject;

Expand Down
2 changes: 1 addition & 1 deletion app/Exporters/MeosExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace App\Exporters;

use App\Model\Orm\Team\Team;
use App\Templates\Filters\CategoryFormatFilter;
use App\Presenters\Accessory\Filters\CategoryFormatFilter;
use Nette\Utils\Strings;
use Nextras\Orm\Collection\ICollection;
use SplFileObject;
Expand Down
5 changes: 4 additions & 1 deletion app/Helpers/EmailFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ public function __construct(
) {
}

/**
* @param non-empty-string $mailHtml
*/
public function create(string $mailHtml): string {
$css = @file_get_contents($this->appDir . '/Templates/Mail/style.css');
$css = @file_get_contents($this->appDir . '/Presenters/templates/Mail/style.css');
\assert($css !== false, 'E-mail stylesheet must be readable');
$domDocument = CssInliner::fromHtml($mailHtml)
->inlineCss($css)
Expand Down
2 changes: 1 addition & 1 deletion app/Helpers/NeonIntlLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class NeonIntlLoader extends Translation\Loaders\Neon {
public function load(
mixed $resource,
string $locale,
string $domain = 'messages'
string $domain = 'messages',
): MessageCatalogue {
return parent::load($resource, $locale, $domain . '+intl-icu');
}
Expand Down
12 changes: 10 additions & 2 deletions app/Locale/Translated.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

namespace App\Locale;

interface Translated {
public function getMessage(string $locale): string;
use Exception;
use Stringable;

abstract class Translated implements Stringable {
abstract public function getMessage(string $locale): string;

public function __toString(): string {
// We rely on custom Translator to call getMessage instead.
throw new Exception(__CLASS__ . ' should not be Stringified');
}
}
2 changes: 1 addition & 1 deletion app/Locale/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Translator extends ContributeTranslator {
public function translate(
$message,
...$parameters
...$parameters,
): string {
if ($message instanceof Translated) {
return $message->getMessage($this->getLocale());
Expand Down
2 changes: 1 addition & 1 deletion app/Model/Configuration/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function from(
string $key,
array $category,
Fees $parentFees,
DateTimeInterface $eventDate
DateTimeInterface $eventDate,
): self {
$fees = Fees::from($category['fees'] ?? [], $parentFees);
if ($fees->person === null) {
Expand Down
2 changes: 1 addition & 1 deletion app/Model/Configuration/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function parseTranslatable(string $context, mixed $translatable, a
if (\is_array($translatable)) {
self::checkAllLocalesPresent($context, $translatable, $allLocales);

return new class($translatable) implements Translated {
return new class($translatable) extends Translated {
public function __construct(
private readonly array $translatable,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Templates\Filters;
namespace App\Presenters\Accessory\Filters;

use App\Model\Configuration\Entries;
use App\Model\Orm\Team\Team;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Templates\Filters;
namespace App\Presenters\Accessory\Filters;

use Money\Converter;
use Money\Currencies\ISOCurrencies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Templates\Filters;
namespace App\Presenters\Accessory\Filters;

use Contributte\Translation\Translator;
use Money\Currencies\ISOCurrencies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Templates\Filters;
namespace App\Presenters\Accessory\Filters;

final class WrapInParagraphsFilter {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

declare(strict_types=1);

namespace App\Templates\Accessory;
namespace App\Presenters\Accessory;

use App\Templates\Filters;
use Latte\Extension;

final class LatteExtension extends Extension {
Expand Down
28 changes: 0 additions & 28 deletions app/Presenters/BasePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,4 @@ protected function startup(): void {
throw new Nette\InvalidStateException('Missing siteTitle argument');
}
}

/**
* Formats layout template file names.
*
* @return string[]
*/
public function formatLayoutTemplateFiles(): array {
$list = array_map(
fn(string $path): string => str_replace('/templates/', '/Templates/', $path),
parent::formatLayoutTemplateFiles(),
);

return $list;
}

/**
* Formats view template file names.
*
* @return string[]
*/
public function formatTemplateFiles(): array {
$list = array_map(
fn(string $path): string => str_replace('/templates/', '/Templates/', $path),
parent::formatTemplateFiles(),
);

return $list;
}
}
19 changes: 10 additions & 9 deletions app/Presenters/CommunicationPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private function composeFormPreview(SubmitButton $button): void {
foreach ($teams as $id => $team) {
\assert($team !== null); // For PHPStan.
$grant = $this->tokens->createForTeam($team);
$this->template->previewMessage = $this->renderMessageBody(
$this->template->previewMessage = $this->_renderMessageBody(
team: $team,
subject: $values['subject'],
grant: $grant,
Expand Down Expand Up @@ -231,7 +231,7 @@ private function composeFormEnqueue(SubmitButton $button): void {
\assert($team !== null); // For PHPStan.

$grant = $this->tokens->createForTeam($team);
$body = $this->renderMessageBody(
$body = $this->_renderMessageBody(
team: $team,
subject: $subject,
grant: $grant,
Expand Down Expand Up @@ -275,11 +275,10 @@ private function composeFormEnqueue(SubmitButton $button): void {
}
}

private function renderMessageBody(Team $team, string $subject, string $grant, string $body): string {
private function _renderMessageBody(Team $team, string $subject, string $grant, string $body): string {
$latte = $this->latteFactory->create();

$appDir = $this->parameters->getAppDir();
$layout = file_get_contents($appDir . '/Templates/Mail/@layout.latte');
$layout = file_get_contents(__DIR__ . '/templates/Mail/@layout.latte');
\assert(\is_string($layout));

$latte->setLoader(new Latte\Loaders\StringLoader([
Expand All @@ -291,7 +290,7 @@ private function renderMessageBody(Team $team, string $subject, string $grant, s

$messageHtml = $latte->renderToString(
'message.latte',
new App\Templates\Mail\Message(
new templates\Mail\Message(
// Define variables for use in the e-mail template.
accountNumber: $this->parameters->accountNumber,
accountNumberIban: $this->parameters->accountNumberIban !== null ? $this->parameters->accountNumberIban->asString() : null,
Expand All @@ -314,6 +313,8 @@ private function renderMessageBody(Team $team, string $subject, string $grant, s
),
);

\assert($messageHtml !== '');

// Inline styles into the e-mail
$messageHtml = $this->emailFactory->create($messageHtml);

Expand Down Expand Up @@ -385,8 +386,6 @@ public function actionSend(): void {
throw new ForbiddenRequestException();
}

$appDir = $this->parameters->getAppDir();

$total = null;
$count = 0;
try {
Expand All @@ -399,7 +398,9 @@ public function actionSend(): void {

foreach ($messages as $message) {
// Inline styles into the e-mail
$mailHtml = $this->emailFactory->create($message->body);
$mailHtml = $message->body;
\assert($mailHtml !== '');
$mailHtml = $this->emailFactory->create($mailHtml);

$mail = new Nette\Mail\Message();
$firstMemberAddress = iterator_to_array($message->team->persons)[0]->email;
Expand Down
4 changes: 2 additions & 2 deletions app/Presenters/Error4xxPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ protected function checkHttpMethod(): void {
public function renderDefault(Nette\Application\BadRequestException $exception): void {
// renders the appropriate error template based on the HTTP status code
$code = $exception->getCode();
$file = is_file($file = __DIR__ . "/../Templates/Error/$code.latte")
$file = is_file($file = __DIR__ . "/templates/Error/$code.latte")
? $file
: __DIR__ . '/../Templates/Error/4xx.latte';
: __DIR__ . '/templates/Error/4xx.latte';
$this->template->httpCode = $code;
$this->template->setFile($file);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Presenters/ErrorAccessPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function renderDefault(LimitedAccessException $exception): void {

$this->template->errorType = $errorType;

$file = __DIR__ . '/../Templates/Error/access.latte';
$file = __DIR__ . '/templates/Error/access.latte';
$this->template->setFile($file);
}
}
2 changes: 1 addition & 1 deletion app/Presenters/ErrorPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function run(Nette\Application\Request $request): Nette\Application\Respo

return new Responses\CallbackResponse(function(Http\IRequest $httpRequest, Http\IResponse $httpResponse): void {
if (preg_match('#^text/html(?:;|$)#', (string) $httpResponse->getHeader('Content-Type')) === 1) {
require __DIR__ . '/../Templates/Error/500.phtml';
require __DIR__ . '/templates/Error/500.phtml';
}
});
}
Expand Down
Loading