Issues (404)

classes/GlossaryEditQueue.php (1 issue)

1
<?php
2
/**
3
 * GlossaryEditQueue Class
4
 *
5
 * @package TheyWorkForYou
6
 */
7
8
namespace MySociety\TheyWorkForYou;
9
10
/**
11
 * Glossary Edit Queue
12
 */
13
14
// Glossary overrides
15
class GlossaryEditQueue extends EditQueue {
16
    public function approve($data) {
17
        // Approve items for inclusion
18
        // Create new epobject and update the editqueue
19
20
        global $THEUSER;
21
22
        // We need a list of editqueue items to play with
23
        $this->get_pending();
24
        if (!isset($this->pending)) {
25
            return false;
26
        }
27
        $timestamp = date('Y-m-d H:i:s', time());
28
29
        foreach ($data['approvals'] as $approval_id) {
30
            // create a new epobject
31
            //      title VARCHAR(255),
32
            //      body TEXT,
33
            //      type INTEGER,
34
            //      created DATETIME,
35
            //      modified DATETIME,
36
            /*print "<pre>";
37
            print_r($data);
38
            print "</pre>";*/
39
            // Check to see that we actually have something to approve
40
            if (!isset($this->pending[$approval_id])) {
41
                break;
42
            }
43
            $q = $this->db->query("INSERT INTO glossary
44
                            (title, body, type, created, visible)
45
                            VALUES
46
                            ('" . addslashes($this->pending[$approval_id]['title']) . "',
47
                            '" . addslashes($this->pending[$approval_id]['body']) . "',
48
                            '" . $data['epobject_type'] . "',
49
                            '" . $timestamp . "',
50
                            1);");
51
52
            // If that didn't work we can't go any further...
53
            if (!$q->success()) {
54
                print "glossary trouble";
55
                return false;
56
            }
57
            $this->current_epobject_id = $q->insert_id();
0 ignored issues
show
Bug Best Practice introduced by
The property current_epobject_id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
58
59
            // Then finally update the editqueue with
60
            // the new epobject id and approval details.
61
            $q = $this->db->query("UPDATE editqueue
62
                            SET
63
                            glossary_id='" . $this->current_epobject_id . "',
64
                            editor_id='" . addslashes($THEUSER->user_id()) . "',
65
                            approved='1',
66
                            decided='" . $timestamp . "'
67
                            WHERE edit_id=" . $approval_id . ";");
68
            if (!$q->success()) {
69
                break;
70
            } else {
71
                // Scrub that one from the list of pending items
72
                unset($this->pending[$approval_id]);
73
            }
74
        }
75
76
        $this->update_pending_count();
77
78
        return true;
79
    }
80
81
}
82