project_issue_extend.module 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. // $Id: project_issue_extend.module,v 1.2.2.1 2009-12-03 22:40:32 fgm Exp $
  3. /**
  4. * A small module to assign issues to users
  5. * Derived from Nedjo Rogers' module for 4.7
  6. * See http://drupal.org/node/4354 for the discussion
  7. *
  8. * @license GPL 2.0
  9. *
  10. */
  11. define('PROJECT_ISSUE_PERM_SETTER', 'assign project issues to others');
  12. define('PROJECT_ISSUE_PERM_GETTER', 'be assigned project issues');
  13. /**
  14. * Implementation of hook_help().
  15. */
  16. function project_issue_extend_help($path, $arg) {
  17. switch ($path) {
  18. case 'admin/help#project_issue_extend':
  19. return t('<p>This module allows users with the "assign" permission a right to assign issues to users with a "be assigned" permissions. Do not combine with the "assign and be assigned" permission in project_issue.module.</p>')
  20. . t('<p>Note that unlike usual permissions, these permissions are only checked for an explicit role: granting them to the anonymous account or to the "authenticated user" pseudo-role will not make them assignable.</p>');
  21. }
  22. }
  23. /**
  24. * Implementation of hook_perm().
  25. */
  26. function project_issue_extend_perm() {
  27. return array(
  28. PROJECT_ISSUE_PERM_SETTER,
  29. PROJECT_ISSUE_PERM_GETTER,
  30. );
  31. }
  32. /**
  33. * Implementation of hook_form_alter().
  34. *
  35. * Add all users to select for assigning issues.
  36. */
  37. function project_issue_extend_form_alter(&$form, $form_state, $form_id) {
  38. if (in_array($form_id, array('project_issue_node_form', 'comment_form', /* was 'project_comment_form' */))
  39. && user_access(PROJECT_ISSUE_PERM_SETTER)) {
  40. $options = array(0 => t('Unassigned'));
  41. $sq = "SELECT DISTINCT u.uid, u.name "
  42. . "FROM {users} u "
  43. . " INNER JOIN {users_roles} ur ON u.uid = ur.uid "
  44. . " INNER JOIN {role} r ON ur.rid = r.rid "
  45. . " INNER JOIN {permission} p ON p.rid = r.rid "
  46. . "WHERE u.status = 1 AND p.perm LIKE '%%%s%%' "
  47. . "ORDER BY u.name";
  48. $sq = db_rewrite_sql($sq, 'u', 'uid');
  49. $result = db_query($sq, PROJECT_ISSUE_PERM_GETTER);
  50. while ($user = db_fetch_object($result)) {
  51. $options[$user->uid] = $user->name;
  52. }
  53. switch ($form_id) {
  54. case 'project_issue_node_form':
  55. if ($form['issue_info']['assigned']) {
  56. $form['issue_info']['assigned']['#options'] = $options;
  57. }
  58. break;
  59. case 'comment_form': // project_comment_form
  60. if ($form['original_issue']['project_info']['assigned']) {
  61. $form['original_issue']['project_info']['assigned']['#options'] = $options;
  62. }
  63. break;
  64. }
  65. }
  66. }