add events filter
This commit is contained in:
parent
164fa8dcb9
commit
75d502af03
|
@ -10,14 +10,30 @@ use App\Motion\SnapshotRepository;
|
||||||
class EventController extends AbstractController
|
class EventController extends AbstractController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @Route("/events", name="events")
|
* @Route("/events/{date}", name="events")
|
||||||
*/
|
*/
|
||||||
public function events(SnapshotRepository $snapshotRepository)
|
public function events(SnapshotRepository $snapshotRepository, string $date = null)
|
||||||
{
|
{
|
||||||
$snapshots = $snapshotRepository->find();
|
$date = $date ?? date('Y-m-d');
|
||||||
|
|
||||||
|
$snapshots = $snapshotRepository->find([
|
||||||
|
'order' => 'DESC',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$days = [];
|
||||||
|
|
||||||
|
foreach ($snapshots as $snapshot) {
|
||||||
|
$day = $snapshot->getDate()->format('d/m');
|
||||||
|
|
||||||
|
if (!in_array($day, $days)) {
|
||||||
|
$days[$snapshot->getDate()->format('Y-m-d')] = $day;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->render('events.html.twig', [
|
return $this->render('events.html.twig', [
|
||||||
'snapshots' => $snapshots,
|
'snapshots' => $snapshots,
|
||||||
|
'days' => $days,
|
||||||
|
'date' => $date,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,41 +14,56 @@ use App\Motion\Snapshot;
|
||||||
*/
|
*/
|
||||||
class SnapshotRepository
|
class SnapshotRepository
|
||||||
{
|
{
|
||||||
protected Finder $finder;
|
|
||||||
|
|
||||||
protected ParameterBagInterface $parameters;
|
protected ParameterBagInterface $parameters;
|
||||||
|
|
||||||
public function __construct(ParameterBagInterface $parameters)
|
public function __construct(ParameterBagInterface $parameters)
|
||||||
{
|
{
|
||||||
$this->finder = new Finder();
|
|
||||||
$this->parameters = $parameters;
|
$this->parameters = $parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find(): array
|
public function find(array $criteria = []): array
|
||||||
{
|
{
|
||||||
$objects = [];
|
$objects = [];
|
||||||
|
|
||||||
$files = $this->finder
|
$criteria['order'] ??= 'ASC';
|
||||||
->files()
|
|
||||||
|
$directoriesFinder = new Finder();
|
||||||
|
|
||||||
|
$directories = $directoriesFinder
|
||||||
|
->directories()
|
||||||
->in($this->parameters->get('motion_snapshots_directory'))
|
->in($this->parameters->get('motion_snapshots_directory'))
|
||||||
->name('/.*\.mp4$/s')
|
->sortByName();
|
||||||
->sortByModifiedTime();
|
|
||||||
|
$directories->sortByName();
|
||||||
|
|
||||||
|
foreach ($directories as $directory) {
|
||||||
|
$moviesFinder = new Finder();
|
||||||
|
|
||||||
|
$files = $moviesFinder
|
||||||
|
->files()
|
||||||
|
->in($directory->getPathName())
|
||||||
|
->name('*.mp4')
|
||||||
|
->sortByName();
|
||||||
|
|
||||||
|
$date = $directory->getFilename();
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$date = basename($file->getPath());
|
|
||||||
$time = str_replace(['.mp4', '-'], ['', ':'], $file->getBasename());
|
$time = str_replace(['.mp4', '-'], ['', ':'], $file->getBasename());
|
||||||
|
$thumbnail = str_replace('.mp4', '.jpg', $file->getPathName());
|
||||||
$movie = $file->getPath().'/'.$file->getBasename();
|
|
||||||
$thumbnail = str_replace('.mp4', '.jpg', $movie);
|
|
||||||
|
|
||||||
$snapshot = new Snapshot();
|
$snapshot = new Snapshot();
|
||||||
$snapshot
|
$snapshot
|
||||||
->setDate(new \DateTime($date.' '.$time))
|
->setDate(new \DateTime($date.' '.$time))
|
||||||
->setMovie($movie)
|
->setMovie($file->getPathName())
|
||||||
->setThumbnail($thumbnail);
|
->setThumbnail($thumbnail);
|
||||||
|
|
||||||
$objects[] = $snapshot;
|
$objects[] = $snapshot;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($criteria['order'] === 'DESC') {
|
||||||
|
$objects = array_reverse($objects);
|
||||||
|
}
|
||||||
|
|
||||||
return $objects;
|
return $objects;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,23 @@
|
||||||
{% block title %}{{ parent() }} - Évènements{% endblock %}
|
{% block title %}{{ parent() }} - Évènements{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
<div class="tabs">
|
||||||
|
<ul>
|
||||||
|
{% for key, name in days %}
|
||||||
|
<li {% if date == key %}class="is-active"{% endif %}>
|
||||||
|
<a href="{{ path('events', {date: key}) }}">{{ name }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{% for snapshot in snapshots|reverse %}
|
{% for snapshot in snapshots %}
|
||||||
|
{% if date == snapshot.date.format('Y-m-d') %}
|
||||||
<a href="{{ asset(snapshot.movie) }}" class="snapshot-link">
|
<a href="{{ asset(snapshot.movie) }}" class="snapshot-link">
|
||||||
<img src="{{ snapshot.thumbnail }}" alt="{{ snapshot.date.format('d/m/Y H:i:s') }}" class="box">
|
<img src="{{ snapshot.thumbnail }}" alt="{{ snapshot.date.format('d/m/Y H:i:s') }}" class="box">
|
||||||
</a>
|
</a>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue