Source for file AgentNodeEntryItem.class.php

Documentation is available at AgentNodeEntryItem.class.php

  1. <?php
  2. /**
  3. * @since 3/2/06
  4. * @package harmoni.osid_v2.logging
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: AgentNodeEntryItem.class.php,v 1.8 2007/09/05 19:55:21 adamfranco Exp $
  10. */
  11.  
  12. /**
  13. * The AgentNodeEntryItem encapsulates data about a log entry
  14. *
  15. * @since 3/2/06
  16. * @package harmoni.osid_v2.logging
  17. *
  18. * @copyright Copyright &copy; 2005, Middlebury College
  19. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  20. *
  21. * @version $Id: AgentNodeEntryItem.class.php,v 1.8 2007/09/05 19:55:21 adamfranco Exp $
  22. */
  23. class AgentNodeEntryItem {
  24. /**
  25. * Constructor
  26. *
  27. * @param string $category
  28. * @param string $description
  29. * @param optional array $nodeIds
  30. * @return object
  31. * @access public
  32. * @since 3/2/06
  33. */
  34. function AgentNodeEntryItem ( $category, $description, $nodeIds = array() ) {
  35. ArgumentValidator::validate($category, StringValidatorRule::getRule());
  36. ArgumentValidator::validate($description, StringValidatorRule::getRule());
  37. ArgumentValidator::validate($nodeIds, ArrayValidatorRule::getRule());
  38. $this->_category = $category;
  39. $this->_description = $description;
  40. $this->_nodeIds = $nodeIds;
  41. $this->_agentIds = array();
  42. $this->_backtrace = '';
  43. $this->_additionalBactraceText = '';
  44. }
  45. /**
  46. * Answer the category
  47. *
  48. * @return string
  49. * @access public
  50. * @since 3/2/06
  51. */
  52. function getCategory () {
  53. return $this->_category;
  54. }
  55. /**
  56. * Answer the description
  57. *
  58. * @return string
  59. * @access public
  60. * @since 3/2/06
  61. */
  62. function getDescription () {
  63. return $this->_description;
  64. }
  65. /**
  66. * Answer the backtrace HTML if available
  67. *
  68. * @return string
  69. * @access public
  70. * @since 3/6/06
  71. */
  72. function getBacktrace () {
  73. return "<div>".$this->_backtrace."</div>\n<div>"
  74. .$this->_additionalBactraceText."</div>";
  75. }
  76. /**
  77. * Set the backtrace HTML
  78. *
  79. * @param string $backtrace
  80. * @return void
  81. * @access public
  82. * @since 3/6/06
  83. */
  84. function setBacktrace ( $backtrace ) {
  85. if (is_array($backtrace)) {
  86. ob_start();
  87. printDebugBacktrace($backtrace);
  88. $this->_backtrace = ob_get_clean();
  89. } else
  90. $this->_backtrace = $backtrace;
  91. }
  92. /**
  93. * Add HTML text to the bactrace, usefull for storing source URLs, etc
  94. *
  95. * @param string $additionalText
  96. * @return void
  97. * @access public
  98. * @since 8/1/06
  99. */
  100. function addTextToBactrace ($additionalText) {
  101. $this->_additionalBactraceText .= $additionalText;
  102. }
  103. /**
  104. * Add an node Id to this item
  105. *
  106. * @param object Id $nodeId
  107. * @return void
  108. * @access public
  109. * @since 3/2/06
  110. */
  111. function addNodeId ( $nodeId ) {
  112. $this->_nodeIds[] =$nodeId;
  113. }
  114. /**
  115. * Answer the nodes for this item
  116. *
  117. * @return object IdIterator
  118. * @access public
  119. * @since 3/2/06
  120. */
  121. function getNodeIds () {
  122. $iterator = new HarmoniIterator($this->_nodeIds);
  123. return $iterator;
  124. }
  125. /**
  126. * Add an agent Id to this item
  127. *
  128. * @param object Id $agentId
  129. * @return void
  130. * @access public
  131. * @since 3/2/06
  132. */
  133. function addAgentId ( $agentId ) {
  134. foreach ($this->_agentIds as $id) {
  135. if ($id->isEqual($agentId))
  136. return;
  137. }
  138. $this->_agentIds[] =$agentId;
  139. }
  140. /**
  141. * Add the current user ids to this item
  142. *
  143. * @return void
  144. * @access public
  145. * @since 3/2/06
  146. */
  147. function addUserIds () {
  148. $authN = Services::getService("AuthN");
  149. $authNTypes =$authN->getAuthenticationTypes();
  150. while ($authNTypes->hasNext())
  151. $this->addAgentId($authN->getUserId($authNTypes->next()));
  152. // Add the Admin Users if they are acting as another user
  153. if (isset($_SESSION['__ADMIN_IDS_ACTING_AS_OTHER'])) {
  154. foreach ($_SESSION['__ADMIN_IDS_ACTING_AS_OTHER'] as $adminId)
  155. $this->addAgentId($adminId);
  156. $this->_description .= "<div>"
  157. .implode(", ", $_SESSION['__ADMIN_NAMES_ACTING_AS_OTHER'])
  158. ." ".((count($_SESSION['__ADMIN_NAMES_ACTING_AS_OTHER']) > 1)?"are":"is")
  159. ." acting as the current user.</div>";
  160. }
  161. }
  162. /**
  163. * Answer the agents for this item. Anonymous will not be included unless
  164. * there are no other agents.
  165. *
  166. * @return object IdIterator
  167. * @access public
  168. * @since 3/2/06
  169. */
  170. function getAgentIds ( $includeAnonymous = FALSE ) {
  171. $idManager = Services::getService("Id");
  172. $idsToReturn = array();
  173. $anonymousId = $idManager->getId("edu.middlebury.agents.anonymous");
  174. foreach (array_keys($this->_agentIds) as $key) {
  175. if (!$anonymousId->isEqual($this->_agentIds[$key]))
  176. $idsToReturn[] =$this->_agentIds[$key];
  177. }
  178. if ($includeAnonymous && !count($idsToReturn))
  179. $idsToReturn[] =$anonymousId;
  180. $iterator = new HarmoniIterator($idsToReturn);
  181. return $iterator;
  182. }
  183. }
  184.  
  185. ?>

Documentation generated on Wed, 19 Sep 2007 10:21:24 -0400 by phpDocumentor 1.3.0RC3