Skip to content

Commit

Permalink
Missing variable in template. Error appears because of twig
Browse files Browse the repository at this point in the history
strict_variable settings
  • Loading branch information
nikrou committed Nov 9, 2021
1 parent 14d3ae0 commit 6d5a06c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 26 deletions.
44 changes: 29 additions & 15 deletions admin/theme/template/rating_photos.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
{% extends "__layout.html.twig" %}

{% block breadcrumb_items %}
<li class="breadcrumb-item"><a href="{{U_PAGE}}">{{'Rating'|trans}}</a></li>
<li class="breadcrumb-item">{{NB_ELEMENTS}} {{'Photos'|trans}}</li>
<li class="breadcrumb-item">
<a href="{{U_PAGE}}">{{'Rating'|trans}}</a>
</li>
<li class="breadcrumb-item">{{NB_ELEMENTS}}
{{'Photos'|trans}}</li>
{% endblock %}

{% block content %}
<form action="{{F_ACTION}}" method="GET">
<p><a class="btn btn-submit" href="#form-filter" data-toggle="collapse">{{'Show/Hide form filter'|trans}}</a></p>
<p>
<a class="btn btn-submit" href="#form-filter" data-toggle="collapse">{{'Show/Hide form filter'|trans}}</a>
</p>
<div class="form-filter collapse" id="form-filter">
<h3>{{'Filter'|trans}}</h3>
<div class="form-group">
<label for="order-by">{{'Sort by'|trans}}</label>
<select name="order_by" id="order-by" class="form-control">
{% for option, label in order_by_options %}
<option value="{{option}}" {% if option == order_by_options_selected %}selected="selected"{% endif %}>{{label}}</option>
<option value="{{option}}" {% if option == order_by_options_selected %} selected="selected" {% endif %}>{{label}}</option>
{% endfor %}
</select>
</div>
Expand All @@ -24,7 +29,7 @@
<label for="users">{{'Users'|trans}}</label>
<select name="users" id="users" class="form-control">
{% for option, label in user_options %}
<option value="{{option}}" {% if option == user_options_selected %}selected="selected"{% endif %}>{{label}}</option>
<option value="{{option}}" {% if option == user_options_selected %} selected="selected" {% endif %}>{{label}}</option>
{% endfor %}
</select>
</div>
Expand Down Expand Up @@ -60,23 +65,32 @@
<tbody>
{% for image in images %}
<tr>
<td><a href="{{image.U_URL}}"><img src="{{image.U_THUMB}}" alt="{{image.FILE}}" title="{{image.FILE}}"></a></td>
<td><strong>{{image.NB_RATES}}/{{image.NB_RATES_TOTAL}}</strong></td>
<td><strong>{{image.SCORE_RATE}}</strong></td>
<td><strong>{{image.AVG_RATE}}</strong></td>
<td><strong>{{image.SUM_RATE}}</strong></td>
<td>
<a href="{{image.U_URL}}"><img src="{{image.U_THUMB}}" alt="{{image.FILE}}" title="{{image.FILE}}"></a>
</td>
<td>
<strong>{{image.NB_RATES}}/{{image.NB_RATES_TOTAL}}</strong>
</td>
<td>
<strong>{{image.SCORE_RATE}}</strong>
</td>
<td>
<strong>{{image.AVG_RATE}}</strong>
</td>
<td>
<strong>{{image.SUM_RATE}}</strong>
</td>
<td>
<table class="table">
{% for rate in image.rates %}
<tr id="rate-{{rate.md5sum}}">
<td>{{rate.rate}}</td>
<td><b>{{rate.USER}}</b></td>
<td>
<b>{{rate.USER}}</b>
</td>
<td>{{rate.date|date}}</td>
<td>
<button
data-confirm="{{'Are you sure?'|trans}}" data-action="{{WS_RATES_DELETE}}"
data-data="{'image_id': {{image.id}},'user_id': {{rate.user_id}}{% if rate.anonymous_id %},'anonymous_id': '{{rate.anonymous_id}}'{% endif %}}"
data-method="POST" data-delete="#rate-{{rate.md5sum}}" data-toggle="modal" data-target="#confirm-delete" class="btn btn-danger fa fa-trash"></button>
<button data-confirm="{{'Are you sure?'|trans}}" data-action="{{WS_RATES_DELETE}}" data-data="{'image_id': {{image.id}},'user_id': {{rate.user_id}}{% if rate.anonymous_id %},'anonymous_id': '{{rate.anonymous_id}}'{% endif %}}" data-method="POST" data-delete="#rate-{{rate.md5sum}}" data-toggle="modal" data-target="#confirm-delete" class="btn btn-danger fa fa-trash"></button>
</td>
</tr>
{% endfor %}
Expand Down
31 changes: 23 additions & 8 deletions src/Controller/Admin/AdminRatingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ protected function setTabsheet(string $section = 'photos'): array
return ['tabsheet' => $tabsheet];
}

public function photos(Request $request, Conf $conf, ImageStandardParams $image_std_params, TranslatorInterface $translator, UserMapper $userMapper,
UserRepository $userRepository, RateRepository $rateRepository, int $start = 0)
{
public function photos(
Request $request,
Conf $conf,
ImageStandardParams $image_std_params,
TranslatorInterface $translator,
UserMapper $userMapper,
UserRepository $userRepository,
RateRepository $rateRepository,
int $start = 0
) {
$tpl_params = [];
$this->translator = $translator;

Expand Down Expand Up @@ -111,7 +118,7 @@ public function photos(Request $request, Conf $conf, ImageStandardParams $image_

$tpl_params['images'] = [];
foreach ($rateRepository->getRatePerImage($guest_id, $operator_user_filter, $available_order_by[$order_by_index][1], $elements_per_page, $start) as $image) {
$tpl_params['images'][] = $image;
// $tpl_params['images'][] = $image;

$thumbnail_src = (new DerivativeImage(new SrcImage($image, $conf['picture_ext']), $image_std_params->getByType(ImageStandardParams::IMG_THUMB), $image_std_params))->getUrl();
$image_url = $this->generateUrl('admin_photo', ['image_id' => $image['id']]);
Expand Down Expand Up @@ -144,14 +151,15 @@ public function photos(Request $request, Conf $conf, ImageStandardParams $image_

$tpl_image['rates'][] = [
'USER' => $user_rate,
'user_id' => $rate->getUser()->getId(),
'md5sum' => md5($rate->getUser()->getId() . $rate->getImage()->getId() . $rate->getAnonymousId()),
'element_id' => $rate->getImage()->getId(),
'anonymous_id' => $rate->getAnonymousId(),
'rate' => $rate->getRate(),
'date' => $rate->getDate()
];
}
$tpl_params['images'][] = $tpl_image;
$tpl_params['images'][] = array_merge($tpl_image, $image);
}

$tpl_params['navbar'] = Utils::createNavigationBar($this->get('router'), 'admin_rating', $navbar_params, $nb_images, $start, $elements_per_page);
Expand All @@ -173,9 +181,16 @@ public function photos(Request $request, Conf $conf, ImageStandardParams $image_
return $this->render('rating_photos.html.twig', $tpl_params);
}

public function users(Request $request, Conf $conf, UserMapper $userMapper, ImageStandardParams $image_std_params,
TranslatorInterface $translator, UserRepository $userRepository, ImageMapper $imageMapper, RateRepository $rateRepository)
{
public function users(
Request $request,
Conf $conf,
UserMapper $userMapper,
ImageStandardParams $image_std_params,
TranslatorInterface $translator,
UserRepository $userRepository,
ImageMapper $imageMapper,
RateRepository $rateRepository
) {
$tpl_params = [];
$this->translator = $translator;

Expand Down
4 changes: 2 additions & 2 deletions src/Repository/RateRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public function calculateRateSummary(int $image_id)
return $qb->getQuery()->getOneOrNullResult(AbstractQuery::HYDRATE_SCALAR);
}

public function countImagesRatedForUser(int $user_id, string $operator = '') : int
public function countImagesRatedForUser(int $user_id, string $operator = null) : int
{
$qb = $this->createQueryBuilder('r');
$qb->select('COUNT(DISTINCT(r.image))');

if ($operator != '') {
if (!is_null($operator)) {
$qb->where('r.user ' . $operator . ' :user_id');
$qb->setParameter('user_id', $user_id);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/UpgradeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(ManagerRegistry $registry)
parent::__construct($registry, Upgrade::class);
}

public function addUpgrade(Upgrade $upgrade): int
public function addUpgrade(Upgrade $upgrade): string
{
$this->_em->persist($upgrade);
$this->_em->flush();
Expand Down

0 comments on commit 6d5a06c

Please sign in to comment.