Fix the filter in Mine Projekter to seach description and pagination
I also expanded the page size from 4 to 8
This commit is contained in:
parent
34668cb0ea
commit
1147c1a7af
|
@ -20,23 +20,16 @@ if(isset($_GET['page'])){
|
||||||
$page = $_GET['page'];
|
$page = $_GET['page'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$filterTitle = '';
|
$filter = '';
|
||||||
if(isset($_POST['title'])){
|
if(isset($_GET['filter'])){
|
||||||
$filterTitle = $_POST['title'];
|
$filter = $_GET['filter'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
$filterOrganiser = '';
|
|
||||||
if(isset($_POST['organiser'])){
|
|
||||||
$filterOrganiser = $_POST['organiser'];
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// filter
|
// filter
|
||||||
$projects = array_values(array_filter(
|
$projects = array_values(array_filter(
|
||||||
$projects,
|
$projects,
|
||||||
function($project) use ($filterTitle){
|
function($project) use ($filter){
|
||||||
return (preg_match('/.*'.$filterTitle.'.*/i', $project->getName()));
|
return (preg_match('/.*'.$filter.'.*/i', $project->getName()) or preg_match('/.*'.$filter.'.*/i', implode(" ", $project->getDescription())));
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
?>
|
?>
|
||||||
|
@ -62,7 +55,7 @@ $projects = array_values(array_filter(
|
||||||
<ul class="event-list">
|
<ul class="event-list">
|
||||||
<?php
|
<?php
|
||||||
$counter = 0;
|
$counter = 0;
|
||||||
$pageLimit = 4;
|
$pageLimit = 8;
|
||||||
|
|
||||||
for($i = ($pageLimit * ($page - 1)); $i < count($projects); $i++){
|
for($i = ($pageLimit * ($page - 1)); $i < count($projects); $i++){
|
||||||
if($counter == $pageLimit){
|
if($counter == $pageLimit){
|
||||||
|
@ -76,8 +69,10 @@ $projects = array_values(array_filter(
|
||||||
<li>
|
<li>
|
||||||
<div class="event">
|
<div class="event">
|
||||||
<div class="event-info">
|
<div class="event-info">
|
||||||
<h3 class="no-chin"><?= '<a href="edit.php?id=' . $project->getID() . '">' . $project->getName() . '</a>'; ?></h3>
|
<a href="edit.php?id=<?= $project->getID() ?>">
|
||||||
<p><?= implode($project->getDescription(), "<br>"); ?></p>
|
<h3 class="no-chin"><?= $project->getName()?></h3>
|
||||||
|
</a>
|
||||||
|
<p style="text-decoration: none;"><?= implode("<br>", $project->getDescription()); ?></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
@ -90,11 +85,11 @@ $projects = array_values(array_filter(
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if($page != 1){
|
if($page != 1){
|
||||||
echo '<a class="btn float-left" href="?page=' . ($page - 1) . '">Forrige side</a>';
|
echo '<a class="btn float-left" href="?page=' . ($page - 1) . '&filter=' . urlencode($filter) . '">Forrige side</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($counter == $pageLimit) and (($pageLimit * $page) < count($projects))){
|
if(($counter == $pageLimit) and (($pageLimit * $page) < count($projects))){
|
||||||
echo '<a class="btn float-right" href="?page=' . ($page + 1) . '">Neste side</a>';
|
echo '<a class="btn float-right" href="?page=' . ($page + 1) . '&filter=' . urlencode($filter) . '">Neste side</a>';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
@ -103,9 +98,9 @@ $projects = array_values(array_filter(
|
||||||
<h2>Verktøy</h2>
|
<h2>Verktøy</h2>
|
||||||
<a class="btn" href="edit.php?new=1">Lag prosjekt</a>
|
<a class="btn" href="edit.php?new=1">Lag prosjekt</a>
|
||||||
<h2>Filter</h2>
|
<h2>Filter</h2>
|
||||||
<form action="." method="post">
|
<form action="mine.php" method="get">
|
||||||
<p class="no-chin">Navn</p>
|
<p class="no-chin">Navn</p>
|
||||||
<?= '<input type="text" name="title" class="boxinput" value="' . $filterTitle . '">' ?><br>
|
<?= '<input type="text" name="filter" class="boxinput" value="' . $filter . '">' ?><br>
|
||||||
|
|
||||||
<div style="margin-top: 2em;">
|
<div style="margin-top: 2em;">
|
||||||
<input type="submit" class="btn" value="Filtrer"></input>
|
<input type="submit" class="btn" value="Filtrer"></input>
|
||||||
|
@ -113,4 +108,4 @@ $projects = array_values(array_filter(
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue