-
Notifications
You must be signed in to change notification settings - Fork 6
/
bpi.delete.inc
155 lines (133 loc) · 3 KB
/
bpi.delete.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* @file
* Delete from bpi logic here.
*/
/**
* Entry point for delete action.
*
* @param string $type
* Request type, ajax or not.
* @param object $node
* Node object.
* @return array
* A set of ajax commands or form structure.
*/
function bpi_delete_action($type = 'ajax', $node) {
$ajax = ($type == 'ajax');
// Only author can delete his node.
if (!bpi_ability($node->nid, 'delete')) {
drupal_access_denied();
drupal_exit();
}
$delete_form = drupal_get_form('bpi_delete_form', $node);
if ($ajax) {
$commands = array();
$commands[] = ajax_command_ding_popup(
'bpi-delete',
t('Delete from BPI'),
drupal_render($delete_form),
array('refresh' => TRUE)
);
return array('#type' => 'ajax', '#commands' => $commands);
}
else {
return $delete_form;
}
}
/**
* Delete from structure.
*
* @param array $form
* Form structure.
* @param array $form_state
* Form state values.
* @param object $node
* Node object.
* @return array
* Form structure.
*
* @ingroup forms
*/
function bpi_delete_form($form, $form_state, $node) {
$form['bpi_delete_bpi_id'] = array(
'#type' => 'value',
'#value' => isset($node->bpi_id) ? $node->bpi_id : 0,
);
return confirm_form(
$form,
t('Are you sure u want to delete %title from bpi well?', array('%title' => $node->title)),
'admin/content'
);
}
/**
* Submit handler for delete form.
*
* @see bpi_delete_form()
*
* @param array $form
* Form structure.
* @param array $form_state
* Form state values.
*
* @ingroup forms
*/
function bpi_delete_form_submit($form, &$form_state) {
$bpi_id = $form_state['values']['bpi_delete_bpi_id'];
if (empty($bpi_id)) {
drupal_set_message(t('Selected content could not be deleted from the BPI well.'), 'error');
return;
}
$status = bpi_well_delete($bpi_id);
if ($status) {
drupal_set_message(t('Selected content deleted from BPI well.'));
}
else {
drupal_set_message(t('Failed to delete selected content from BPI well.'), 'error');
}
}
/**
* Form ajax callback for delete action.
*
* @param array $form
* Form structure.
* @param array $form_state
* Form state values.
* @return array
* A set of AJAX commands.
*/
function bpi_delete_action_ajax_callback($form, &$form_state) {
$response = array(
'#type' => 'ajax',
'#commands' => array()
);
$html = theme('status_messages');
$response['#commands'][] = ajax_command_ding_popup(
'bpi-delete',
t('Delete from BPI'),
$html
);
return $response;
}
/**
* Deleted the content from BPI well.
*
* @param string $bpi_id
* BPI content id to be deleted.
* @return boolean
* Status, success or failure.
*/
function bpi_well_delete($bpi_id) {
try {
$bpi = bpi_client_instance();
db_delete('bpi_syndicated')
->condition('bid', $bpi_id, '=')
->execute();
$bpi->deleteNode($bpi_id);
return TRUE;
}
catch (Exception $e) {
watchdog_exception('bpi', $e);
return FALSE;
}
}