Skip to content

Commit

Permalink
Merge pull request #75 from leepeuker/user-name-selection-hotfix
Browse files Browse the repository at this point in the history
User name selection hotfix
  • Loading branch information
leepeuker authored Jul 27, 2022
2 parents f9f0273 + d788b6c commit 97f70e7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Application/User/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function fetchAllHavingWatchedMovie(int $movieId) : array

public function fetchAllHavingWatchedMoviesWithPerson(int $personId) : array
{
return $this->repository->fetchAllHavingWatchedMoviesWithPerson($personId);
return $this->repository->fetchAllHavingWatchedMovieWithPerson($personId);
}

public function fetchDateFormatId(int $userId) : int
Expand Down
14 changes: 8 additions & 6 deletions src/Application/User/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,30 @@ public function deleteUser(int $userId) : void

public function fetchAll() : array
{
return $this->dbConnection->fetchAllAssociative('SELECT * FROM `user`');
return $this->dbConnection->fetchAllAssociative('SELECT * FROM `user` ORDER BY name');
}

public function fetchAllHavingWatchedMovie(int $movieId) : array
{
return $this->dbConnection->fetchAllAssociative(
'SELECT user.name
'SELECT DISTINCT user.name
FROM `user`
JOIN movie_user_watch_dates muwd ON user.id = muwd.user_id
WHERE movie_id = ?',
WHERE movie_id = ?
ORDER BY name',
[$movieId]
);
}

public function fetchAllHavingWatchedMoviesWithPerson(int $personId) : array
public function fetchAllHavingWatchedMovieWithPerson(int $personId) : array
{
return $this->dbConnection->fetchAllAssociative(
'SELECT user.name
'SELECT DISTINCT user.name
FROM `user`
JOIN movie_user_watch_dates muwd ON user.id = muwd.user_id
JOIN movie_cast mc ON muwd.movie_id = mc.movie_id
WHERE person_id = ?',
WHERE person_id = ?
ORDER BY name',
[$personId]
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public static function createTwigEnvironment(ContainerInterface $container) : Tw
$dataFormatJavascript = DateFormat::getJavascriptById($user->getDateFormatId());
}

$twig->addGlobal('currentUsername', $user?->getName());
$twig->addGlobal('routeUsername', $routeUsername ?? $user?->getName());
$twig->addGlobal('dateFormatPhp', $dateFormatPhp);
$twig->addGlobal('dateFormatJavascript', $dataFormatJavascript);
Expand Down
7 changes: 6 additions & 1 deletion templates/component/user-select.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
<span class="input-group-text">User</span>
<select class="form-select" id="changeUserContextSelect">
<option disabled>Select user</option>
{% if currentUsername is not null %}
<option value="{{ currentUsername }}" {% if routeUsername == currentUsername %}selected{% endif %}>{{ currentUsername }}</option>
{% endif %}
{% for user in users %}
<option value="{{ user.name }}" {% if routeUsername == user.name %}selected{% endif %}>{{ user.name }}</option>
{% if currentUsername != user.name %}
<option value="{{ user.name }}" {% if routeUsername == user.name %}selected{% endif %}>{{ user.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
Expand Down

0 comments on commit 97f70e7

Please sign in to comment.