Issues (69)

view/post/view-all.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Anax\View;
4
5
use Michelf\Markdown;
6
7
// Gather incoming variables and use default values if not set
8
$items = isset($items) ? $items : null;
9
10
// Create urls for navigation
11
$urlToCreate = url("post/create");
12
$totalPosts = count($items);
0 ignored issues
show
It seems like $items can also be of type null; however, parameter $value of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

12
$totalPosts = count(/** @scrutinizer ignore-type */ $items);
Loading history...
13
?>
14
<div class=posts>
15
<div class=leftbar><p class=allposts>All Posts</p></div>
16
<div class=rightbar>
17
    <p class=askquestion><a  href="<?= $urlToCreate ?>">Ask Question<p></a>
18
</div>
19
</div>
20
21
<div class=posts>
22
<div class=leftbar>
23
<p ><b><?= $totalPosts ?> Posts</b></p></div>
24
<div class=rightbar>
25
<ul class="sortby">
26
<li><a href='?orderby=created&order=desc'>Date:<i class="fas fa-arrow-alt-circle-down"></i></a><a href='?orderby=created&order=asc'><i class="fas fa-arrow-alt-circle-up"></i></a></li>
27
<li><a href='?orderby=votes&order=desc'>Votes:<i class="fas fa-arrow-alt-circle-down"></i></a><a href='?orderby=votes&order=asc'><i class="fas fa-arrow-alt-circle-up"></i></a></li>
28
</ul>
29
</div>
30
</div>
31
<?php if (!$items) : ?>
32
    <p>There are no items to show.</p>
33
<?php
34
    return;
35
endif;
36
?>
37
<?php foreach ($items as $item) :
38
    $db =  $this->di->get("db");
39
    $sql = "SELECT sum(score) as postscore from post_votes where post_id=?;";
40
    $score = $db->executeFetchAll($sql, [$item->id]);
41
    $sql = "select * from post2tag where post_id=?;";
42
    $posttags = $db->executeFetchAll($sql, [$item->id]);
43
    $sql = "SELECT sum(answer) as totalanswer from comments where post_id=?;";
44
    $answer = $db->executeFetchAll($sql, [$item->id]);
45
    ?>
46
47
    <div class=posts>
48
        <div class=leftpost>
49
            <div class=countvotes><?= $score[0]->postscore?:0?></div>
50
            <div class=countvotes>votes</div>
51
            <div class=countanswers><?= $answer[0]->totalanswer?: 0?></div>
52
            <div class=countvotes>answers</div>
53
        </div>
54
        <div class=rightpost>
55
            <div><b><a href="post/show/<?= $item->id ?>"><?= $item->title ?></a></b></div>
56
            <div><p class=postcontent><?= Markdown::defaultTransform($item->content) ?></p></div>
57
            <div>
58
                <?php foreach ($posttags as $tag) : ?>
59
                <a class=onetag href="tag/<?= $tag->tag_name ?>"><?= $tag->tag_name ?></a>
60
                <?php endforeach; ?>
61
            </div>
62
            <div>Asked <?= $item->created ?></div>
63
        </div>
64
    </div>
65
66
<?php endforeach; ?>
67