aboutsummaryrefslogtreecommitdiff
path: root/muamba.module
blob: 3aa94bc8cc6349c684a2ca4a9b48a4e9022cf3e8 (plain)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php

/**
 * @file
 * Multiple-user Asset Manager and Borrowing Ambient.
 */

/**
 * Definitions.
 */
define('MUAMBA_NODE_TYPE', 'muamba');
define('MUAMBA_REQUESTED', 0);
define('MUAMBA_ACCEPTED',  1);
define('MUAMBA_REJECTED',  2);
define('MUAMBA_CANCELLED', 3);
define('MUAMBA_RETURNED',  4);
define('MUAMBA_RECOVERED', 5);
define('MUAMBA_LOST',      6);

// Load requirements.
include_once('muamba.business.inc');
include_once('muamba.misc.inc');
include_once('muamba.db.inc');

/**
 * Implements hook_permission()
 */
function muamba_permission() {
  return array(
    'request item' => array(
      'title'       => t('Request an item'),
      'description' => t('Request an item to be borrowed or donated.'),
    ),
  );
}

/**
 * Implements hook_menu()
 */
function muamba_menu() {
  $items['muamba'] = array(
    'title'            => 'My items',
    'page callback'    => 'muamba',
    'access arguments' => array('access content'),
    'type'             => MENU_SUGGESTED_ITEM,
    'file'             => 'muamba.business.inc',
  );

  $items['muamba/request'] = array(
    'title'            => 'Request an item',
    'page callback'    => 'muamba_request',
    'access arguments' => array('request item'),
    'type'             => MENU_SUGGESTED_ITEM,
    'file'             => 'muamba.business.inc',
  );

  $items['muamba/accept'] = array(
    'title'            => 'Accept an item request',
    'page callback'    => 'muamba_accept',
    'access arguments' => array('access content'),
    'type'             => MENU_SUGGESTED_ITEM,
    'file'             => 'muamba.business.inc',
  );

  $items['muamba/reject'] = array(
    'title'            => 'Reject an item request',
    'page callback'    => 'muamba_reject',
    'access arguments' => array('access content'),
    'type'             => MENU_SUGGESTED_ITEM,
    'file'             => 'muamba.business.inc',
  );

  $items['muamba/cancel'] = array(
    'title'            => 'Cancel a request',
    'page callback'    => 'muamba_cancel',
    'access arguments' => array('access content'),
    'type'             => MENU_SUGGESTED_ITEM,
    'file'             => 'muamba.business.inc',
  );

  $items['muamba/recover'] = array(
    'title'            => 'Recover an item',
    'page callback'    => 'muamba_recover',
    'access arguments' => array('access content'),
    'type'             => MENU_SUGGESTED_ITEM,
    'file'             => 'muamba.business.inc',
  );

  $items['muamba/return'] = array(
    'title'            => 'Return an item',
    'page callback'    => 'muamba_return',
    'access arguments' => array('access content'),
    'type'             => MENU_SUGGESTED_ITEM,
    'file'             => 'muamba.business.inc',
  );

  $items['muamba/lost'] = array(
    'title'            => 'Report a lost item',
    'page callback'    => 'muamba_lost',
    'access arguments' => array('access content'),
    'type'             => MENU_SUGGESTED_ITEM,
    'file'             => 'muamba.business.inc',
  );

  return $items;
}

/**
 * Implements hook_node_view()
 */
function muamba_node_view($node, $view_mode, $langcode) {
  if ($view_mode == 'full') {
    $node->content['muamba'] = array(
      '#markup' => muamba_widget($node, 'big'),
      '#weight' => 100,
    );

    return $node;
  }
}

/**
 * Implements hook_theme()
 */
function muamba_theme($existing, $type, $theme, $path) {
  return array(
    'muamba_widget' => array(
      'template'  => 'muamba-widget',
      'variables' => array(
        'node'         => NULL,
        'transactions' => NULL, 
        'available'    => NULL,
        'size'         => 'small',
      ),
    ),
    'muamba_widget_owner' => array(
      'variables' => array(
        'transaction' => NULL, 
        'size'        => 'small',
      ),
      'file' => 'muamba.theme.inc',
    ),
    'muamba_widget_requester' => array(
      'variables' => array(
        'transaction' => NULL, 
        'size'        => 'small',
      ),
      'file' => 'muamba.theme.inc',
    ),
    'muamba_powered' => array(
      'template' => 'muamba-powered',
    ),
    'muamba_transactions' => array(
      'variables' => array(
        'transactions' => NULL,
        'type'         => NULL,
      ),
      'file' => 'muamba.theme.inc',
    ),
    'muamba_colorbox_link' => array(
      'variables' => array(
        'path' => NULL,
        'text' => NULL,
      ),
      'file' => 'muamba.theme.inc',
    ),
    'muamba_request_message' => array(
      'variables' => array(
        'transaction' => NULL,
      ),
      'file' => 'muamba.theme.inc',
    ),
    'muamba_accept_message' => array(
      'variables' => array(
        'transaction' => NULL,
      ),
      'file' => 'muamba.theme.inc',
    ),
    'muamba_reject_message' => array(
      'variables' => array(
        'transaction' => NULL,
      ),
      'file' => 'muamba.theme.inc',
    ),
    'muamba_cancel_message' => array(
      'variables' => array(
        'transaction' => NULL,
      ),
      'file' => 'muamba.theme.inc',
    ),
    'muamba_return_message' => array(
      'variables' => array(
        'transaction' => NULL,
      ),
      'file' => 'muamba.theme.inc',
    ),
    'muamba_recover_message' => array(
      'variables' => array(
        'transaction' => NULL,
      ),
      'file' => 'muamba.theme.inc',
    ),
    'muamba_lost_message' => array(
      'variables' => array(
        'transaction' => NULL,
      ),
      'file' => 'muamba.theme.inc',
    ),
    'muamba_widget_icon' => array(
      'variables' => array(
        'status' => MUAMBA_REQUESTED,
        'id'     => NULL,
        'size'   => 'small',
      ),
      'file' => 'muamba.theme.inc',
    ),
  );
}

/**
 * Implements hook_block_info()
 */
function muamba_block_info() {
  $blocks['muamba_powered'] = array(
    'info'   => t('Muamba powered'),
    'cache'  => DRUPAL_NO_CACHE,
    'status' => TRUE,
    'region' => 'footer',
  );

  return $blocks;
}

/**
 * Implements hook_block_view()
 */
function muamba_block_view($delta = '') {
  $block = array();

  switch ($delta) {
    case 'muamba_powered':
      $block['subject'] = NULL;
      $block['content'] = theme('muamba_powered');
      break;
    
  }
  return $block;
}

/**
 * Implements hook_privatemsg_view_alter()
 *
 * @todo
 */
function muamba_privatemsg_view_alter(&$content) {
  $bar = 'TODO: Add here request management bar.';
  $content['participants']['#markup'] = $bar . $content['participants']['#markup'];
}

/**
 * Implements hook_node_delete()
 */
function muamba_node_delete($node) {
  db_delete('muamba')
    ->condition('nid', $node->nid)
    ->execute();
}

/**
 * Implements hook_user_delete()
 */
function muamba_user_delete($account) {
  db_delete('muamba')
    ->condition('uid', $account->uid)
    ->execute();

  db_delete('muamba')
    ->condition('owner', $account->uid)
    ->execute();
}

/**
 * Implementes hook_views_data()
 */
function muamba_views_api() {
  return array(
    'api' => 3,
  );
}

/**
 * Implements hook_node_update()
 */
function muamba_node_update($node) {
  if ($node->type == MUAMBA_NODE_TYPE) {
    db_update('muamba')
      ->fields(array('owner' => $node->uid))
      ->condition('nid', $node->nid, '=')
      ->execute();
  }
}

/**
 * Implements hook_form_alter()
 */
function muamba_form_alter(&$form, &$form_state, $form_id) {
  // Remove bookmark option.
  if ($form_id == 'muamba_node_form') {
    unset($form['flag']);
  }
}