|
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
|
|
|
|
|
17
|
|
|
public function approve($data) { |
|
18
|
|
|
// Approve items for inclusion |
|
19
|
|
|
// Create new epobject and update the editqueue |
|
20
|
|
|
|
|
21
|
|
|
global $THEUSER; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
// We need a list of editqueue items to play with |
|
24
|
|
|
$this->get_pending(); |
|
25
|
|
|
if (!isset($this->pending)) { |
|
26
|
|
|
return false; |
|
27
|
|
|
} |
|
28
|
|
|
$timestamp = date('Y-m-d H:i:s', time()); |
|
29
|
|
|
|
|
30
|
|
|
foreach ($data['approvals'] as $approval_id) { |
|
31
|
|
|
// create a new epobject |
|
32
|
|
|
// title VARCHAR(255), |
|
|
|
|
|
|
33
|
|
|
// body TEXT, |
|
34
|
|
|
// type INTEGER, |
|
35
|
|
|
// created DATETIME, |
|
36
|
|
|
// modified DATETIME, |
|
37
|
|
|
/*print "<pre>"; |
|
|
|
|
|
|
38
|
|
|
print_r($data); |
|
39
|
|
|
print "</pre>";*/ |
|
40
|
|
|
// Check to see that we actually have something to approve |
|
41
|
|
|
if (!isset($this->pending[$approval_id])) { |
|
42
|
|
|
break; |
|
43
|
|
|
} |
|
44
|
|
|
$q = $this->db->query("INSERT INTO glossary |
|
45
|
|
|
(title, body, type, created, visible) |
|
46
|
|
|
VALUES |
|
47
|
|
|
('" . addslashes($this->pending[$approval_id]['title']) . "', |
|
48
|
|
|
'" . addslashes($this->pending[$approval_id]['body']) . "', |
|
49
|
|
|
'" . $data['epobject_type'] . "', |
|
50
|
|
|
'" . $timestamp . "', |
|
51
|
|
|
1);"); |
|
52
|
|
|
|
|
53
|
|
|
// If that didn't work we can't go any further... |
|
54
|
|
|
if (!$q->success()) { |
|
55
|
|
|
print "glossary trouble"; |
|
56
|
|
|
return false; |
|
57
|
|
|
} |
|
58
|
|
|
$this->current_epobject_id = $q->insert_id(); |
|
59
|
|
|
|
|
60
|
|
|
// Then finally update the editqueue with |
|
61
|
|
|
// the new epobject id and approval details. |
|
62
|
|
|
$q = $this->db->query("UPDATE editqueue |
|
63
|
|
|
SET |
|
64
|
|
|
glossary_id='" . $this->current_epobject_id. "', |
|
65
|
|
|
editor_id='" . addslashes($THEUSER->user_id()) . "', |
|
66
|
|
|
approved='1', |
|
67
|
|
|
decided='" . $timestamp . "' |
|
68
|
|
|
WHERE edit_id=" . $approval_id . ";"); |
|
69
|
|
|
if (!$q->success()) { |
|
70
|
|
|
break; |
|
71
|
|
|
} |
|
72
|
|
|
else { |
|
73
|
|
|
// Scrub that one from the list of pending items |
|
74
|
|
|
unset ($this->pending[$approval_id]); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$this->update_pending_count(); |
|
79
|
|
|
|
|
80
|
|
|
return true; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state