Add filtering to activity admin page
This commit is contained in:
parent
e1b2f00a38
commit
751967c5fa
|
@ -8,11 +8,30 @@ require __DIR__ . '/../../../sql_config.php';
|
|||
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$customActivity = new \pvv\side\DBActivity($pdo);
|
||||
$events = $customActivity->getAllEvents();
|
||||
|
||||
$page = 1;
|
||||
if(isset($_GET['page'])){
|
||||
$page = $_GET['page'];
|
||||
}
|
||||
|
||||
$filterTitle = '';
|
||||
if(isset($_POST['title'])){
|
||||
$filterTitle = $_POST['title'];
|
||||
}
|
||||
|
||||
$filterOrganiser = '';
|
||||
if(isset($_POST['organiser'])){
|
||||
$filterOrganiser = $_POST['organiser'];
|
||||
}
|
||||
|
||||
// filter
|
||||
$events = array_values(array_filter(
|
||||
$events,
|
||||
function($event) use ($filterTitle, $filterOrganiser){
|
||||
return (preg_match('/.*'.$filterTitle.'.*/i', $event->getName()) and preg_match('/.*'.$filterOrganiser.'.*/i', $event->getOrganiser()));
|
||||
}
|
||||
));
|
||||
?>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
|
@ -42,7 +61,6 @@ if(isset($_GET['page'])){
|
|||
<?php
|
||||
$counter = 0;
|
||||
$pageLimit = 4;
|
||||
$events = $customActivity->getAllEvents();
|
||||
|
||||
for($i = ($pageLimit * ($page - 1)); $i < count($events) ;$i++){
|
||||
if($counter == $pageLimit){
|
||||
|
@ -91,6 +109,17 @@ if(isset($_GET['page'])){
|
|||
<div class="gridr">
|
||||
<h2>Verktøy</h2>
|
||||
<a class="btn adminbtn" href="edit.php?new=1">Legg inn ny aktivitet</a>
|
||||
<h2>Filter</h2>
|
||||
<form action="." method="post">
|
||||
<p class="no-chin">Navn</p>
|
||||
<?= '<input type="text" name="title" class="boxinput" value="' . $filterTitle . '">' ?><br>
|
||||
<p class="no-chin">Organisator</p>
|
||||
<?= '<input type="text" name="organiser" class="boxinput" value="' . $filterOrganiser . '">' ?><br>
|
||||
|
||||
<div style="margin-top: 2em;">
|
||||
<input type="submit" class="btn" value="Filtrer"></input>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
|
|
Loading…
Reference in New Issue