authorqueue.module

Tracking 5.x-2.x branch
  1. drupal
    1. 5 contributions/nodequeue/authorqueue.module

Functions & methods

NameDescription
authorqueue_nodequeue_infoImplementation of hook_nodequeue_info()
smartqueue_author_nodequeue_formImplementation of hook_nodequeue()
smartqueue_author_nodequeue_form_validateImplementation of hook_nodequeue()
smartqueue_author_nodequeue_subqueuesImplementation of hook_nodequeue_subqueues()
smartqueue_author_nodequeue_subqueue_title

File

View source
  1. <?php
  2. /**
  3. * Implementation of hook_nodequeue_info()
  4. */
  5. function authorqueue_nodequeue_info() {
  6. return array('smartqueue_author' => array(
  7. 'title' => t('Author queue'),
  8. 'description' => t('Each user in the selected roles will be given a queue; nodequeue administrators can select nodes by that author for placement into that queue, allowing the site to easily hilight content by particular authors.'),
  9. ));
  10. }
  11. /**
  12. * Implementation of hook_nodequeue()
  13. */
  14. function smartqueue_author_nodequeue_form($queue, &$form) {
  15. $roles = user_roles(TRUE);
  16. $form['placeholder']['rids'] = array(
  17. '#type' => 'checkboxes',
  18. '#title' => t('Roles'),
  19. '#description' => t('Select which roles a user must have to create a queue. If none are checked, all node authors will get a queue.'),
  20. '#options' => $roles,
  21. );
  22. $form['subqueue_title'] = array(
  23. '#type' => 'textfield',
  24. '#title' => t('Subqueue title'),
  25. '#default_value' => $queue->subqueue_title,
  26. '#size' => 50,
  27. '#maxlength' => 64,
  28. '#description' => t('What to display for the subqueue title; use %subqueue to embed the actual subqueue title. This is used to distinguish multiple nodequeues with subqueues from each other, as internal subqueue title is filled automatically.'),
  29. );
  30. if ($queue->qid && !empty($queue->reference)) {
  31. $form['placeholder']['rids']['#default_value'] = explode('-', $queue->reference);
  32. }
  33. }
  34. /**
  35. * Implementation of hook_nodequeue()
  36. */
  37. function smartqueue_author_nodequeue_form_validate($queue, $form_values, &$form) {
  38. if (!isset($queue->qid)) {
  39. $rids = !empty($form_values['rids']) ? array_keys(array_filter($form_values['rids'])) : array();
  40. // Convert this to our reference.
  41. form_set_value($form['reference'], implode('-', $rids));
  42. }
  43. }
  44. /**
  45. * Implementation of hook_nodequeue_subqueues()
  46. */
  47. function smartqueue_author_nodequeue_subqueues(&$queue, $node) {
  48. // Sorry, no anonymous nodes allowed.
  49. if (empty($node->uid)) {
  50. return;
  51. }
  52. $rids = !empty($queue->reference) ? explode('-', $queue->reference) : array();
  53. $account = user_load(array('uid' => $node->uid));
  54. if (!empty($rids) && !array_intersect($rids, array_keys($account->roles))) {
  55. return;
  56. }
  57. if (!nodequeue_load_subqueues_by_reference(array($queue->qid => array($node->uid)))) {
  58. nodequeue_add_subqueue($queue, $account->name, $node->uid);
  59. }
  60. return array($node->uid);
  61. }
  62. function smartqueue_author_nodequeue_subqueue_title($queue, $reference) {
  63. $account = user_load(array('uid' => $reference));
  64. if ($account) {
  65. return $account->name;
  66. }
  67. }
  68. // TODO:
  69. // * Automatically delete subqueues when a user is deleted.