Source for file eventlist.php

Documentation is available at eventlist.php

  1. <?php
  2. /**
  3. * @package net.nemein.incidentdb
  4. * @author The Midgard Project, http://www.midgard-project.org
  5. * @version $Id: eventlist.php,v 1.2 2005/03/12 09:57:23 torben Exp $
  6. * @copyright The Midgard Project, http://www.midgard-project.org
  7. * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
  8. */
  9.  
  10. /**
  11. * IncidentDB Event management helper class
  12. *
  13. * @todo document
  14. *
  15. * @package net.nemein.incidentdb
  16. */
  17. class net_nemein_incidentdb_eventlist {
  18. // Configuration
  19. var $_topic;
  20. var $_config;
  21. var $_auth;
  22. var $_root_event;
  23. var $_incident_types;
  24. // Current Query Settings
  25. var $_type;
  26. var $_start;
  27. var $_end;
  28. // Datamanger Instance
  29. var $_datamanager;
  30. function net_nemein_incidentdb_eventlist ($topic, $config, $auth, $rootevent, $types) {
  31. $this->_topic = $topic;
  32. $this->_config = $config;
  33. $this->_auth = $auth;
  34. $this->_root_event = $rootevent;
  35. $this->_incident_types = $types;
  36. $this->_datamanager = new midcom_helper_datamanager ($this->_config->get("schemadb"));
  37. if ($this->_datamanager === false) {
  38. debug_add("INCIDENTDB::EVENTLIST Constructor: Could not create datamanager.");
  39. $this = false;
  40. return false;
  41. }
  42. $_type = null;
  43. $_start = null;
  44. $_end = null;
  45. }
  46. function set_type ($type) {
  47. /* Typecast this so that we have a guranteed integer here, seems that this
  48. * could make trouble.
  49. * I hate PHP.
  50. */
  51. if (array_key_exists((int)$type, $this->_incident_types)) {
  52. $this->_type = $type;
  53. return true;
  54. } else {
  55. $this->_type = null;
  56. debug_add("INCIDENTDB::EVENTLIST set_type: $type is unkown, setting type to NULL.");
  57. return false;
  58. }
  59. }
  60. function set_start ($start) { $this->_start = $start; }
  61. function set_end ($end) { $this->_end = $end; }
  62. function get_type () { return $this->_type; }
  63. function get_start () { return $this->_start; }
  64. function get_end () { return $this->_end; }
  65. function query () {
  66. debug_push("incidentdb::eventlist query");
  67. $start = is_null($this->_start) ? 0 : $this->_start;
  68. $end = is_null($this->_end) ? 2147483647 : $this->_end;
  69. debug_add("Will query all events from $start to $end for "
  70. . (is_null($this->_type) ? "all types" : "type $this->_type" ) );
  71. if (is_null($this->_type))
  72. $result = mgd_list_events_between ($this->_root_event->id, $start, $end, "start");
  73. else
  74. $result = mgd_list_events_between ($this->_root_event->id, $start, $end, "start",
  75. $this->_type);
  76. if (! $result) {
  77. debug_add("Did not found any events. mgd_errstr was " . mgd_errstr());
  78. debug_pop();
  79. return Array();
  80. }
  81. $res = Array();
  82. while ($result->fetch()) {
  83. $event = mgd_get_event ($result->id);
  84. /* check: person id
  85. * if we are manager, show all, else check wether the
  86. * event creator is the same as the current user.
  87. */
  88. $tmp = $this->_auth->get_person();
  89. $personid = $tmp->id;
  90. if ($this->_auth->is_manager() || $event->creator == $personid) {
  91. $res[$event->id] = $event;
  92. debug_print_r("Evend ID $event->id has been added as: ", $res[$event->id]);
  93. } else {
  94. debug_add("Skipping object, creator is $event->creator, we are $personid.");
  95. continue;
  96. }
  97. }
  98. debug_pop();
  99. return $res;
  100. }
  101. function create_new_incident ($type) {
  102. if (! $this->_auth->can_write()) {
  103. debug_add("INCIDENTDB::EVENTLIST create failed, we can't write.");
  104. return false;
  105. }
  106. $event = mgd_get_event();
  107. $event->owner = 0; // Inherit this
  108. $event->up = $this->_root_event->id;
  109. $event->type = $type;
  110. $id = $event->create();
  111. if (! $id) {
  112. debug_add("INCIDENTDB::EVENTLIST mgd_create faild: " . mgd_errstr());
  113. return false;
  114. } else {
  115. debug_add("INCIDETNDB::EVENTLIST created event id $id");
  116. }
  117. $event = mgd_get_event($id);
  118. $event->parameter("midcom.helper.datamanager", "layout", $type);
  119. return $event;
  120. }
  121. function & get_datamanager_for_incident (&$event) {
  122. if ($this->_datamanager->init($event)) {
  123. return $this->_datamanager;
  124. } else {
  125. return null;
  126. }
  127. }
  128. }
  129.  
  130.  
  131. ?>

Documentation generated on Mon, 21 Nov 2005 18:15:08 +0100 by phpDocumentor 1.3.0RC3