Failed Conditions
Branch master (215e8c)
by Johannes
04:26
created

topics.php ➔ update_frontpage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
1 ignored issue
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 66 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
include_once '../../includes/easyparliament/init.php';
4
5
$this_page = 'admin_topics';
6
7
$topics = new \MySociety\TheyWorkForYou\Topics();
8
$all_topics = $topics->getTopics();
9
$db = new ParlDB;
10
11
$PAGE->page_start();
12
$PAGE->stripe_start();
13
14
$action = get_http_var('action');
15
16
if ($action == 'frontpage') {
17
    print(update_frontpage($topics));
18
    $all_topics = $topics->getTopics();
19
}
20
21
?>
22
23
    <div id="adminbody">
24
        <form action="topics.php" method="post">
25
          <input type="hidden" name="action" value="frontpage">
26
          <table>
27
            <thead>
28
              <th>Name</th>
29
              <th>Description</th>
30
              <th>Front page</th>
31
              <th></th>
32
            </thead>
33
            <?php foreach ($all_topics as $name => $topic) { ?>
34
            <tr>
35
              <td><a href="<?= $topic->url() ?>"><?= _htmlspecialchars($topic->title()) ?></a></td>
36
              <td><?= _htmlspecialchars($topic->description()) ?></td>
37
              <td><input type="checkbox" name="frontpage[]" value="<?= $topic->slug() ?>" <?= $topic->onFrontPage() ? 'checked' : '' ?>></td>
38
              <td><a href="/admin/edittopic.php?id=<?= $topic->slug() ?>">edit</a></td>
39
            <?php } ?>
40
          </table>
41
          <p>
42
            <input type="submit" value="Update">
43
          </p>
44
        </form>
45
46
        <h3>Add new Topic</h3>
47
48
        <form action="edittopic.php" method="post">
49
          <input type="hidden" name="action" value="add">
50
          <p>
51
          <label for="title">Title:</label> <input id="title" name="title" value="">
52
          </p>
53
54
          <p>
55
          <label for="description">Description</label><br>
56
          <textarea id="description" rows="5" name="description"></textarea>
57
          </p>
58
59
          <p>
60
          <input type="submit" value="Add">
61
          </p>
62
        </form>
63
    </div>
64
<?php
65
66
function update_frontpage($topics) {
67
    $frontpage = get_http_var('frontpage');
68
69
    $is_success = $topics->updateFrontPageTopics($frontpage);
70
71
    if ($is_success) {
72
        $out = "<h4>update successful</h4>";
73
    } else {
74
        $out = "<h4>Failed to update Topics</h4>";
75
    }
76
77
    return $out;
78
}
79
80
$menu = $PAGE->admin_menu();
81
82
$PAGE->stripe_end(array(
83
    array(
84
        'type'    => 'html',
85
        'content' => $menu
86
    )
87
));
88
89
$PAGE->page_end();
90