workflow.node.type_map.inc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @file
  4. * Node specific functions, remnants of nodeapi.
  5. */
  6. /**
  7. * Functions related to table workflow_type_map.
  8. */
  9. /**
  10. * Gets all workflow_type_map.
  11. */
  12. function workflow_get_workflow_type_map() {
  13. $results = db_query('SELECT type, wid FROM {workflow_type_map}');
  14. return $results->fetchAllKeyed();
  15. }
  16. /**
  17. * Getss workflow_type_map for a type. On no record, FALSE is returned.
  18. *
  19. * Currently this is a unique result but requests have been made to allow a node to have multiple
  20. * workflows. This is trickier than it sounds as a lot of our processing code will have to be
  21. * tweaked to account for multiple results.
  22. * ALERT: If a node type is *not* mapped to a workflow it will be listed as wid 0.
  23. * Hence, we filter out the non-mapped results.
  24. *
  25. * @see workflow_get_workflows_by_type()
  26. */
  27. function workflow_get_workflow_type_map_by_type($type) {
  28. static $map = array();
  29. if (!isset($map[$type])) {
  30. $results = db_query('SELECT type, wid FROM {workflow_type_map} WHERE type = :type AND wid <> 0',
  31. array(':type' => $type));
  32. $map[$type] = $results->fetchObject();
  33. }
  34. return $map[$type];
  35. }
  36. /**
  37. * Given a wid, finds all node types mapped to it.
  38. */
  39. function workflow_get_workflow_type_map_by_wid($wid) {
  40. static $map = array();
  41. if (!isset($map[$wid])) {
  42. $results = db_query('SELECT type, wid FROM {workflow_type_map} WHERE wid = :wid',
  43. array(':wid' => $wid));
  44. $map[$wid] = $results->fetchAll();
  45. }
  46. return $map[$wid];
  47. }
  48. /**
  49. * Deletes all type maps.
  50. *
  51. * @todo: why is this here instead of the admin_ui?
  52. */
  53. function workflow_delete_workflow_type_map_all() {
  54. return db_delete('workflow_type_map')->execute();
  55. }
  56. /**
  57. * Given a wid, deletes the map for that workflow.
  58. */
  59. function workflow_delete_workflow_type_map_by_wid($wid) {
  60. return db_delete('workflow_type_map')->condition('wid', $wid)->execute();
  61. }
  62. /**
  63. * Given a type, deletes the map for that workflow.
  64. */
  65. function workflow_delete_workflow_type_map_by_type($type) {
  66. return db_delete('workflow_type_map')->condition('type', $type)->execute();
  67. }
  68. /**
  69. * Given information, inserts a new workflow_type_map. Returns data by ref. (like node_save).
  70. *
  71. * @todo: why is this here instead of the admin_ui?
  72. */
  73. function workflow_insert_workflow_type_map($node_type, $wid) {
  74. $type_map = (object) array(
  75. 'type' => $node_type,
  76. 'wid' => $wid,
  77. );
  78. // Be sure we have a clean insert. There should never be more than one map for a type.
  79. workflow_delete_workflow_type_map_by_type($type_map->type);
  80. if ($type_map->wid) {
  81. drupal_write_record('workflow_type_map', $type_map);
  82. }
  83. }