/[drupal]/contributions/modules/collect_nodes/collect_nodes.module
ViewVC logotype

Contents of /contributions/modules/collect_nodes/collect_nodes.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Mon May 26 11:54:11 2008 UTC (18 months ago) by striky2
Branch: MAIN
CVS Tags: DRUPAL-5--2-1, HEAD
Changes since 1.2: +157 -157 lines
File MIME type: text/x-php
Full compliance against coder.module and README.txt
1 <?php
2 // $Id$
3
4 /**
5 * By default, if a user has the perm 'collect nodes service restricted', he can collect 200 items only.
6 */
7 define('COLLECT_NODES_DEFAULT_RESTRICTION', 200);
8 /**
9 * By default, if an oversized error is detected, the redirection is leading to HOME.
10 */
11 define('COLLECT_NODES_RESTRICTION_OVERSIZED_HANDLER', '<none>');
12 /**
13 * Define error codenames/values
14 */
15 define('BAD_PARAMETER_ERROR', 1);
16 define('NO_ACCESS_ERROR', 2);
17 define('NOT_COLLECTABLE_NODE', 3);
18 define('RESTRICTION_OVERSIZED_ERROR', 4);
19 define('INCORRECT_OPERATION_NAME_ERROR', 5);
20 define('INCORRECT_OPERATION_REQUEST_ERROR', 6);
21
22 /***************************/
23 /** Default hooks section **/
24 /***************************/
25
26 /**
27 * Implementation of hook_help().
28 */
29 function collect_nodes_help($section) {
30 switch ($section) {
31 case 'admin/help#collect_nodes':
32 case 'admin/modules#description':
33 return t('allows user to "put nodes in" / "remove nodes from" their collection.');
34 }
35 }
36
37 /**
38 * Implementation of hook_menu()
39 */
40 function collect_nodes_menu($may_cache) {
41 $items = array();
42
43 if ($may_cache) {
44 $items[] = array(
45 'path' => 'admin/settings/collect_nodes',
46 'title' => t("Collect nodes admin"),
47 'callback' => 'drupal_get_form',
48 'callback arguments' => array('collect_nodes_admin_settings'),
49 'type' => MENU_NORMAL_ITEM,
50 'access' => user_access('collect nodes admin'),
51 );
52 $items[] = array(
53 'path' => 'collect-nodes/collect',
54 'callback' => 'collect_nodes_collect_page',
55 'type' => MENU_CALLBACK,
56 'access' => user_access('collect nodes restricted') || user_access('collect nodes unlimited'),
57 );
58 $items[] = array(
59 'path' => 'collect-nodes/uncollect',
60 'callback' => 'collect_nodes_uncollect_page',
61 'type' => MENU_CALLBACK,
62 'access' => user_access('collect nodes restricted') || user_access('collect nodes unlimited'),
63 );
64 }
65 return $items;
66 }
67
68 /**
69 * Implementation of hook_perm()
70 */
71 function collect_nodes_perm() {
72 return array('collect nodes restricted', 'collect nodes unlimited', 'collect nodes admin', );
73 }
74
75 /**
76 * Implementation of hook_admin()
77 *
78 */
79 function collect_nodes_admin_settings() {
80 $form['collect_nodes_settings'] = array(
81 '#type' => 'fieldset',
82 '#title' => t('Configure collect_nodes settings'),
83 '#collapsible' => FALSE,
84 );
85 $form['collect_nodes_settings']['collect_nodes_node_types'] = array(
86 '#type' => 'fieldset',
87 '#title' => t('Collectable node types'),
88 '#description' => t('Set the node types which are collectable.'),
89 '#collapsible' => TRUE,
90 '#collapsed' => TRUE,
91 );
92 $form['collect_nodes_settings']['collect_nodes_node_types']['collect_nodes_on'] = array(
93 '#type' => 'checkboxes',
94 '#title' => t('Available node types'),
95 '#options' => node_get_types('names'),
96 '#description' => t('Choose the collection/nodes types you want to use with collect nodes'),
97 '#default_value' => variable_get('collect_nodes_on', array()),
98 );
99 $form['collect_nodes_settings']['collect_nodes_default_restriction'] = array(
100 '#type' => 'textfield',
101 '#title' => t('Maximum collected items allowed by person'),
102 '#description' => t('Associated with the "collect nodes restricted" perm only.
103 "collect nodes unlimited" perm is not constrained to this rule'),
104 '#default_value' => variable_get('collect_nodes_default_restriction', COLLECT_NODES_DEFAULT_RESTRICTION),
105 );
106 $form['collect_nodes_settings']['collect_nodes_restriction_oversized_handler'] = array(
107 '#type' => 'textfield',
108 '#title' => t('Handler URL once maximum is reached'),
109 '#description' => t('Enter the URL where you want the user to be redirected
110 if the user goes over the restriction (only for "collect nodes restricted perm")<br/>
111 If you select "&lt;none&gt;", there will be no redirection, an error message will be displayed "as is" instead.'),
112 '#default_value' => variable_get('collect_nodes_restriction_oversized_handler', COLLECT_NODES_RESTRICTION_OVERSIZED_HANDLER),
113 );
114
115 return system_settings_form($form);
116 }
117
118 /**
119 * Implementation de hook_node_api().
120 *
121 * Delete all lines in data base about a node if this one is deleted.
122 */
123 function collect_nodes_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
124 global $user;
125
126 switch ($op) {
127 case 'delete' :
128 //be responsible
129 db_query("DELETE FROM {collect_nodes} WHERE nid = %d", $node->nid);
130 break;
131 }
132 }
133
134 /************************/
135 /** Internal functions **/
136 /************************/
137
138 /**
139 * _collect_nodes_add
140 * Inserts the collect link into the database
141 * Don't call this function if not sanitized before
142 *
143 * @param $nid
144 * node nid
145 */
146 function _collect_nodes_add($nid) {
147 global $user;
148 //need to be secured before this call
149 //(cf. service collect_nodes_collect_service)
150
151 db_query("INSERT INTO {collect_nodes} (nid, uid, last) VALUES (%d, %d, %d)", $nid, $user->uid, time());
152 drupal_set_message(t("The item has been added to your Collection"));
153
154 if (module_exists('workflow_ng')) {
155 workflow_ng_invoke_event('collect_nodes_node_collected', node_load($nid), $user);
156 }
157
158 return TRUE;
159 }
160 /**
161 * _collect_nodes_throw
162 * Remove the collect link from the database
163 * Don't call this function if not sanitized before
164 *
165 * @param $nid
166 * node nid
167 */
168 function _collect_nodes_throw($nid) {
169 global $user;
170 //need to be secured before this call
171 //(cf. service collect_nodes_collect_service)
172 db_query("DELETE FROM {collect_nodes} WHERE nid = %d AND uid = %d", $nid, $user->uid);
173 drupal_set_message(t("The item has been removed from your Collection"));
174
175 if (module_exists('workflow_ng')) {
176 workflow_ng_invoke_event('collect_nodes_node_uncollected', node_load($nid), $user);
177 }
178
179 return TRUE;
180 }
181
182 /**
183 * _collect_nodes_check
184 * Look into the database to see if a user already owns the item or not
185 *
186 * @param $nid
187 * node nid
188 * @param $uid
189 * [optional], user uid
190 */
191 function _collect_nodes_check($nid, $uid = 0) {
192 global $user;
193
194 $uid = $uid ? $uid : $user->uid;
195
196 //batch mode (scalability)
197 if (is_array($nid)) {
198 $sql = "SELECT nid FROM {collect_nodes} WHERE nid IN (%s) AND uid = %d";
199 $query = db_query($sql, implode(', ', $nid), $uid);
200 $collected_items = array();
201
202 while ($result = db_fetch_array($query)) {
203 $collected_items[] = $result['nid'];
204 }
205
206 $not_collected_in_the_page = array_diff($nid, $collected_items);
207 $collected_in_the_page = array_intersect($nid, $collected_items);
208
209 $return_array = array();
210 foreach ($not_collected_in_the_page as $val) {
211 $return_array[] = array('nid' => $val, 'status' => 0);
212 }
213 foreach ($collected_in_the_page as $val) {
214 $return_array[] = array('nid' => $val, 'status' => 1);
215 }
216
217 return drupal_to_js($return_array);
218 }
219
220 //normal mode
221 else if (is_numeric($nid)) {
222 $sql = "SELECT * FROM {collect_nodes} WHERE nid = %d AND uid = %d";
223 $query = db_query($sql, $nid, $uid);
224
225 return db_result($query) ? 1 : 0;
226 }
227
228 return FALSE;
229 }
230
231 /**
232 * Check if a user is at the limit for collecting things
233 *
234 * @return boolean
235 * TRUE if user is on or over the restricted limit / FALSE
236 */
237 function _collect_nodes_restriction_oversized($uid = NULL, $restriction = NULL) {
238 global $user;
239 $uid = $uid ? $uid : $user->uid;
240
241 $restriction = isset($restriction) ? $restriction : variable_get('collect_nodes_default_restriction', COLLECT_NODES_DEFAULT_RESTRICTION);
242
243 if (user_access('collect nodes unlimited')) {
244 return FALSE;
245 }
246
247 $query = db_query("SELECT COUNT(*) as num FROM {collect_nodes} WHERE uid = %d", $user->uid);
248 $result = db_fetch_object($query);
249
250 return ($result->num >= $restriction) ? TRUE : FALSE;
251 }
252
253 /**
254 * public version of the function
255 */
256 function collect_nodes_restriction_oversized($uid, $restriction) {
257 return _collect_nodes_restriction_oversized($uid, $restriction);
258 }
259
260 /**
261 * Check if a node is collectable
262 *
263 * @param $type
264 * the node type being collected
265 */
266 function _collect_nodes_node_type_is_collectable($type) {
267 $types = variable_get('collect_nodes_on', array());
268 return $types[$type] ? TRUE : FALSE;
269 }
270
271 /**
272 * _collect_nodes_secure_operation
273 * Check all the elements to secure/sanitize the service.
274 *
275 * @param $nid
276 * node nid
277 * @param $op
278 * [optional] 'add' or 'throw' to be secured, if empty: autodetection mode
279 * @param $uid
280 * [optional] user uid
281 * @return
282 * return['error'] = TRUE if there is a security issue, with a return['error_name'] and return['error_code']
283 * return['error'] = FALSE otherwise
284 */
285 function _collect_nodes_secure_operation($nid, $op, $uid = 0) {
286 global $user;
287
288 $uid = $uid ? $uid : $user->uid;
289 $node = node_load($nid);
290 $error = array();
291
292 //checking user rights
293 if (!$node) {
294 $error = array('error' => TRUE, 'error_code' => BAD_PARAMETER_ERROR, 'error_name' => 'You tried to collect a content that doesn\'t exist');
295 }
296 //checking user rights
297 else if (!user_access('collect nodes restricted') && !user_access('collect nodes unlimited')) {
298 $error = array('error' => TRUE, 'error_code' => NO_ACCESS_ERROR, 'error_name' => 'You don\'t have the required permissions to have access to this service');
299 }
300 //check if the node type is ok to be collectable
301 else if (!_collect_nodes_node_type_is_collectable($node->type)) {
302 $error = array('error' => TRUE, 'error_code' => NOT_COLLECTABLE_NODE, 'error_name' => 'You tried to collect a content whose type is not collectable');
303 }
304 //checking user rights & business restriction
305
306 else if (!user_access('collect nodes unlimited') && user_access('collect nodes restricted') && _collect_nodes_restriction_oversized()) {
307 $error = array('error' => TRUE, 'error_code' => RESTRICTION_OVERSIZED_ERROR, 'error_name' => 'Your account doesn\'t allow you to collect more items. Please upgrade your account');
308 }
309 //Lorenzo : check the operation stereotype
310 else if ($op != 'uncollect' && $op != 'collect' && $op != '') {
311 $error = array('error' => TRUE, 'error_code' => INCORRECT_OPERATION_NAME_ERROR, 'error_name' => 'You requested this service with an operation that doesn\'t exist');
312 }
313 else {
314 //mode auto-detect completion
315 if ($op == '' and _collect_nodes_check($nid, $uid)) {
316 //item already exists
317 $op == 'uncollect';
318 }
319 if ($op == '' and (!_collect_nodes_check($nid, $uid))) {
320 //item doesn't exist yet
321 $op == 'collect';
322 }
323 if (_collect_nodes_check($nid, $uid) && $op == 'collect') {
324 //check if possible to collect the item in this case
325 //if the item is already collect-ed, then it should not be possible
326 $error = array('error' => TRUE, 'error_code' => INCORRECT_OPERATION_REQUEST_ERROR, 'error_name' => 'You tried to collect a content you already have');
327 }
328 else if ((!_collect_nodes_check($nid, $uid)) && $op == 'uncollect') {
329 //check if possible to uncollect the item in this case
330 //if the item is not collect-ed yet, then it shoud not be possible
331 $error = array('error' => TRUE, 'error_code' => INCORRECT_OPERATION_REQUEST_ERROR, 'error_name' => 'You tried to remove a content you don\t have yet');
332 }
333 }
334
335 if ($error['error']) {
336 drupal_set_message(t($error['error_name']), 'error');
337 return $error;
338 }
339 else{
340 if (module_exists('workflow_ng')) {
341 workflow_ng_invoke_event('collect_nodes_attempt_authorized', node_load($nid), $user);
342 }
343 return array('error' => FALSE);
344 }
345 }
346
347 /********************************/
348 /** Old Fashioned Drupal Pages **/
349 /********************************/
350
351 /**
352 * Render the collect (add) page.
353 * @deprecated
354 */
355 function collect_nodes_collect_page($nid, $check = FALSE) {
356 global $user;
357
358 //Do a security checking if not done before^M
359 if (!$check) {
360 $security = _collect_nodes_secure_operation($nid, 'collect', $user->uid);
361 if ($security['error'] && $security['error_code'] == 4) {
362 drupal_goto(variable_get('collect_nodes_restriction_oversized_handler', COLLECT_NODES_RESTRICTION_OVERSIZED_HANDLER));
363 }
364 else if ($security['error']) {
365 drupal_set_message(t($security['error_name']), 'error');
366 drupal_goto('node/'. $nid);
367 }
368 }
369
370 if (is_numeric($nid)) {
371 if ($result = _collect_nodes_add($nid)) {
372 drupal_set_message(t('The item is in your collection'));
373 drupal_goto('node/'. $nid);
374 }
375
376 }
377 drupal_not_found();
378 }
379 /**
380 * Render the uncollect (throw) page.
381 * @deprecated
382 */
383 function collect_nodes_uncollect_page($nid, $check = FALSE) {
384 global $user;
385
386 //Do a security checking if not done before
387 if (!$check) {
388 $security = _collect_nodes_secure_operation($nid, 'uncollect', $user->uid);
389 if ($security['error'] && $security['error_code'] == 4) {
390 drupal_goto(variable_get('collect_nodes_restriction_oversized_handler', COLLECT_NODES_RESTRICTION_OVERSIZED_HANDLER));
391 }
392 if ($security['error']) {
393 drupal_set_message(t($security['error_name']), 'error');
394 drupal_goto('node/'. $nid);
395 return FALSE;
396 }
397 }
398
399 if (is_numeric($nid)) {
400 if ($result = _collect_nodes_throw($nid)) {
401 drupal_set_message(t('The item is not in your collection anymore'), 'warning');
402 }
403 else {
404 drupal_goto('node/'. $nid);
405 }
406 }
407 }
408
409 /*******************************/
410 /** Workflow-ng hooks section **/
411 /*******************************/
412
413 /**
414 * Implementation of hook_event_info()
415 */
416 function collect_nodes_event_info() {
417 return array(
418 'collect_nodes_attempt_authorized' => array(
419 '#label' => t('User\'s operation attempt authorized'),
420 '#arguments' => array(
421 'node' => array('#entity' => 'node', '#label' => t('Node being collected')),
422 'user' => array('#entity' => 'user', '#label' => t('User, whose collect attempt is on')),
423 ),
424 '#redirect' => TRUE,
425 '#module' => t('Collect nodes'),
426 ),
427 'collect_nodes_node_collected' => array(
428 '#label' => t('Node collected'),
429 '#arguments' => array(
430 'node' => array('#entity' => 'node', '#label' => t('Node collected')),
431 'user' => array('#entity' => 'user', '#label' => t('User')),
432 ),
433 '#redirect' => TRUE,
434 '#module' => t('Collect nodes'),
435 ),
436 'collect_nodes_node_uncollected' => array(
437 '#label' => t('Node uncollected'),
438 '#arguments' => array(
439 'node' => array('#entity' => 'node', '#label' => t('Node uncollected')),
440 'user' => array('#entity' => 'user', '#label' => t('User')),
441 ),
442 '#redirect' => TRUE,
443 '#module' => t('Collect nodes'),
444 ),
445 );
446 }
447 /**
448 * Implementation of hook_action_info()
449 */
450 function collect_nodes_action_info() {
451 return array(
452 'collect_nodes_action_node_collect' => array(
453 '#label' => t('Collect a content'),
454 '#arguments' => array(
455 'node' => array('#entity' => 'node', '#label' => t('Content')),
456 'user' => array('#entity' => 'user', '#label' => t('User who is collecting the content')),
457 ),
458 '#module' => t('Collect nodes'),
459 ),
460 'collect_nodes_action_node_uncollect' => array(
461 '#label' => t('Uncollect a content'),
462 '#arguments' => array(
463 'node' => array('#entity' => 'node', '#label' => t('Content')),
464 'collector' => array('#entity' => 'user', '#label' => t('User who is uncollecting the content')),
465 ),
466 '#module' => t('Collect nodes'),
467 ),
468 );
469 }
470 /**
471 * Implementation of hook_condition_info()
472 */
473 function collect_nodes_condition_info() {
474 return array(
475 'collect_nodes_condition_user_has_access' => array(
476 '#label' => t('Evaluate if the user can access the collect_nodes service'),
477 '#arguments' => array(
478 'user' => array('#entity' => 'user', '#label' => t('User to check')),
479 ),
480 '#description' => t('Evaluates to TRUE, if the user can access the service.'),
481 '#module' => t('Collect nodes'),
482 ),
483 'collect_nodes_condition_node_collectable' => array(
484 '#label' => t('Evaluate if the node type is collectable'),
485 '#arguments' => array(
486 'node' => array('#entity' => 'node', '#label' => t('Node to check')),
487 ),
488 '#description' => t('Evaluates to TRUE, if the node type is collectable.'),
489 '#module' => t('Collect nodes'),
490 ),
491 'collect_nodes_condition_collect_authorized_operation' => array(
492 '#label' => t('Evaluate if the user can launch the collect operation on this node'),
493 '#arguments' => array(
494 'node' => array('#entity' => 'node', '#label' => t('Node to check')),
495 'user' => array('#entity' => 'user', '#label' => t('User to check')),
496 ),
497 '#description' => t('Evaluates to TRUE, if the user can run the collect operation.'),
498 '#module' => t('Collect nodes'),
499 ),
500 'collect_nodes_condition_uncollect_authorized_operation' => array(
501 '#label' => t('Evaluate if the user can launch the uncollect operation on this node'),
502 '#arguments' => array(
503 'node' => array('#entity' => 'node', '#label' => t('Node to check')),
504 'user' => array('#entity' => 'user', '#label' => t('User to check')),
505 ),
506 '#description' => t('Evaluates to TRUE, if the user can run the uncollect operation.'),
507 '#module' => t('Collect nodes'),
508 ),
509 'collect_nodes_condition_restriction_oversized' => array(
510 '#label' => t('Evaluate if user\'s collection doesn\'t exceed authorized size'),
511 '#arguments' => array(
512 'user' => array('#entity' => 'user', '#label' => t('User to check')),
513 ),
514 '#description' => t('Evaluates to TRUE, if the user\'s collection doesn\'t exceed authorised size.'),
515 '#module' => t('Collect nodes'),
516 ),
517 );
518 }
519
520 /**
521 * Action to collect a node
522 */
523 function collect_nodes_action_node_collect($node, $user) {
524 $nid = $node->nid;
525
526 $security = _collect_nodes_secure_operation($nid, 'collect', $user->uid);
527 if ($security['error'] && $security['error_code'] == 4) {
528 drupal_goto(variable_get('collect_nodes_restriction_oversized_handler', COLLECT_NODES_RESTRICTION_OVERSIZED_HANDLER));
529 }
530 else if ($security['error']) {
531 drupal_set_message(t($security['error_name']), 'error');
532 drupal_goto('node/'. $nid);
533 }
534
535 if (is_numeric($nid)) {
536 if ($result = _collect_nodes_add($nid)) {
537 drupal_set_message(t('The item is in your collection'));
538 drupal_goto('node/'. $nid);
539 }
540 }
541 drupal_not_found();
542 return array();
543 }
544
545 /**
546 * Action to uncollect a node
547 */
548 function collect_nodes_action_node_uncollect($node, $user) {
549 $nid = $node->nid;
550
551 $security = _collect_nodes_secure_operation($nid, 'uncollect', $user->uid);
552 if ($security['error'] && $security['error_code'] == 4) {
553 drupal_goto(variable_get('collect_nodes_restriction_oversized_handler', COLLECT_NODES_RESTRICTION_OVERSIZED_HANDLER));
554 }
555 if ($security['error']) {
556 drupal_set_message(t($security['error_name']), 'error');
557 drupal_goto('node/'. $nid);
558 return FALSE;
559 }
560
561 if (is_numeric($nid)) {
562 if ($result = _collect_nodes_throw($nid)) {
563 drupal_set_message(t('The item is not in your collection anymore'), 'warning');
564 }
565 else {
566 drupal_goto('node/'. $nid);
567 }
568 }
569 }
570
571 /**
572 * Condition to show if the user can have access to the service
573 */
574 function collect_nodes_condition_user_has_access($user) {
575 //check if the user can have access to the service
576 if (user_access('collect nodes restricted') || user_access('collect nodes unlimited')) {
577 return TRUE;
578 }
579 else {
580 drupal_set_message(t('You don\'t have the required authorizations to have access to this service'));
581 return FALSE;
582 }
583 }
584
585 /**
586 * Condition to show if the node_type is collectable
587 */
588 function collect_nodes_condition_node_collectable($node) {
589 //check if the node type is ok to be collectable
590 return _collect_nodes_node_type_is_collectable($node->type) ? TRUE : FALSE;
591 }
592
593 /**
594 * Condition to show if user can collect a node (ie: node status uncollect)
595 */
596 function collect_nodes_condition_collect_authorized_operation($node, $user) {
597 if (_collect_nodes_check($nid, $uid) && $op == 'collect') {
598 drupal_set_message(t('You have already collected this content, you can\'t do it again'));
599 return FALSE;
600 }
601 else {
602 return TRUE;
603 }
604 }
605
606 /**
607 * Condition to show if user can uncollect a node (ie: node status collect)
608 */
609 function collect_nodes_condition_uncollect_authorized_operation($node, $user) {
610 if (!_collect_nodes_check($nid, $uid) && $op == 'uncollect') {
611 drupal_set_message(t('This content is not in you collection, you can\'t remove it'));
612 return FALSE;
613 }
614 else {
615 return TRUE;
616 }
617 }
618
619 /**
620 * Condition to show "collection limit oversized"
621 */
622 function collect_nodes_condition_restriction_oversized($user) {
623 if (!user_access('collect nodes unlimited') && user_access('collect nodes restricted') && _collect_nodes_restriction_oversized()) {
624 drupal_set_message(t('Your account type doesn\'t allow you to collect more content for now'));
625 return FALSE;
626 }
627 return TRUE;
628 }
629
630 /*************************/
631 /** Views hooks section **/
632 /*************************/
633
634 /**
635 * Implementation of hook_views_tables().
636 */
637 function collect_nodes_views_tables() {
638 $tables = array();
639
640 $tables['collect_nodes'] = array(
641 'name' => 'collect_nodes',
642 'join' => array(
643 'left' => array(
644 'table' => 'node',
645 'field' => 'nid'
646 ),
647 'right' => array(
648 'field' => 'nid'
649 ),
650 ),
651 'fields' => array(
652 'last' => array(
653 'name' => t('Collect nodes: Time Added'),
654 'sortable' => true,
655 'handler' => views_handler_field_dates(),
656 'option' => 'string',
657 'help' => t('Display the date/time the node was added.')
658 ),
659 'count' => array(
660 'name' => t('Collect nodes: Count'),
661 'handler' => 'collect_nodes_handler_user_count',
662 'help' => t('Number of times this node was collected by any user.'),
663 'sortable' => FALSE,
664 'notafield' => TRUE,
665 ),
666 'collect_link' => array(
667 'name' => t('Collect nodes: Link'),
668 'sortable' => false,
669 'help' => t('display the collect nodes link'),
670 'handler' => 'collect_nodes_views_handler_field_lnk',
671 'notafield' => true,
672 ),
673 ),
674 'sorts' => array(
675 'last' => array(
676 'name' => t('Collect nodes: last collected'),
677 'help' => t('This allows you to sort chronologically your collection.'),
678 )
679 ),
680 'filters' => array(
681 'last' => array(
682 'name' => t('Collect nodes: Time Added'),
683 'operator' => 'views_handler_operator_gtlt',
684 'value' => views_handler_filter_date_value_form(),
685 'handler' => 'views_handler_filter_timestamp',
686 'option' => 'string',
687 'help' => t('This filter allows collected nodes to be filtered by the date and time the user added them. Enter dates in the format: CCYY-MM-DD HH:MM:SS. Enter \'now\' to use the current time. You may enter a delta (in seconds) to the option that will be added to the time; this is most useful when combined with now.'),
688 ),
689 ),
690 );
691
692 return $tables;
693 }
694
695 /**
696 * Implementation of hook_handler_user_count().
697 */
698 function collect_nodes_handler_user_count($fieldinfo, $fielddata, $value, $data) {
699 return db_result(db_query("SELECT COUNT(*) FROM {collect_nodes} WHERE nid = %d", $data->nid));
700 }
701
702 /**
703 * Implementation of view's hook_views_arguments().
704 */
705 function collect_nodes_views_arguments() {
706 $arguments['collect_nodes_user'] = array(
707 'name' => t('collect nodes: select user'),
708 'help' => t('collect nodes: select only the user\'s collected elements'),
709 'handler' => 'collect_nodes_views_handler_argument'
710 );
711 return $arguments;
712 }
713
714 /**
715 * Implementation of view's hook_views_handler_argument().
716 */
717 function collect_nodes_views_handler_argument($op, &$query, $a1, $a2=null) {
718 if ($a2 == null) {
719 global $user;
720 $a2 = $user->uid;
721 }
722 switch ($op) {
723 case 'filter' :
724 if (is_numeric($a2)) {
725 $query->ensure_table('collect_nodes');
726 $query->add_where("collect_nodes.uid = $a2");
727 }
728 break;
729 }
730 }
731
732 /**
733 * Implementation of view's hook_views_handler_field_lnk().
734 */
735 function collect_nodes_views_handler_field_lnk($fieldinfo, $fielddata, $value, $data) {
736 return theme('collect_nodes_client_js', $data);
737 }

  ViewVC Help
Powered by ViewVC 1.1.2