Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! Merge pull request #29 from…
Browse files Browse the repository at this point in the history
… TomasVotruba/training
  • Loading branch information
TomasVotruba committed Dec 28, 2018
1 parent 1775aeb commit b22a581
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
Move here:
https://docs.google.com/document/d/1bOHuZVbiHCfSnfza7h-fdG84gzpbL-04JXRypPDOMWQ/edit?ouid=107371378567698701347&usp=docs_home&ths=true

Inspire - https://www.vzhurudolu.cz/reklama

</div>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@
</div>

<div class="col-md">
Školitel
<strong>Školí</strong>:

{% if trainer.getWebsite() %}
<a href="{{ trainer.getWebsite() }}">
{% endif %}
{% if trainer.getWebsite() %}<a href="{{ trainer.getWebsite() }}">{% endif %}

{{ trainer.getName() }}

{% if trainer.getWebsite() %}
</a>
{% endif %}
{% if trainer.getWebsite() %}</a>{% endif %}

{% if trainer.getBio() %}
<p>„{{ trainer.getBio()|raw }}“</p>
Expand Down Expand Up @@ -73,12 +69,11 @@

<p>
{# translate! #}
Délka: <strong>{{ training.getDuration() }} hodin</strong>
Délka: <strong>{{ word_by_count(training.getDuration(), ['hodin', 'hodiny', 'hodin']) }}</strong>
</p>

<p>
{# translate! #}
Kapacita: <strong>{{ training.getCapacity() }} lidí</strong>
Kapacita: <strong>{{ word_by_count(training.getCapacity(), ['člověk', 'lidi', 'lidí']) }}</strong>
</p>

<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
</p>

<a href="{{ path('registration', { 'slug': training.getNearestTermSlug() }) }}" class="btn btn-success btn-xs-block-only">
<em class="fa fa-fw fa-handshake-o"></em>
<em class="fa fa-fw fa-handshake"></em>
&nbsp;
Přihlaš se
</a>
<br>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);

namespace OpenTraining\Exception\Twig;

use Exception;

final class InvalidWordCountException extends Exception
{

}
55 changes: 55 additions & 0 deletions projects/open-training/src/Twig/Extension/InflectionExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php declare(strict_types=1);

namespace OpenTraining\Twig\Extension;

use OpenTraining\Exception\Twig\InvalidWordCountException;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

/**
* @docs https://symfony.com/doc/current/templating/twig_extension.html
*
* Plural, singular,
*/
final class InflectionExtension extends AbstractExtension
{
/**
* @return TwigFunction[]
*
* @use "<a href="..." class="{{ active_item('blog']) }}">"
* @use "<a href="..." class="{{ active_item(['trainings', 'training-detail']) }}">"
*/
public function getFunctions(): array
{
return [
new TwigFunction('word_by_count', function (int $count, array $versions): string {
$this->ensureValidFormCountIsProvided($versions);
if ($count === 1) {
return $count . ' ' . $versions[0];
}

if ($count === 0 || $count < 5) {
return $count . ' ' . $versions[1];
}

return $count . ' ' . $versions[2];
}),
];
}

/**
* @param string[] $versions
*/
private function ensureValidFormCountIsProvided(array $versions): void
{
if (count($versions) === 3) {
return;
}

throw new InvalidWordCountException(sprintf(
'Provide exactly 3 options to word_by_count() function as 2nd argument. %d given',
count($versions)
));
}
}

0 comments on commit b22a581

Please sign in to comment.