Source for file HarmoniWritableLog.class.php

Documentation is available at HarmoniWritableLog.class.php

  1. <?php
  2. /**
  3. * @since 3/1/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: HarmoniWritableLog.class.php,v 1.5 2007/09/13 16:04:20 adamfranco Exp $
  10. */
  11.  
  12. require_once(OKI2."/osid/logging/WritableLog.php");
  13. require_once(dirname(__FILE__)."/HarmoniReadableLog.class.php");
  14.  
  15. /**
  16. * Interface WritableLog allows writing of entry items, format types, priority
  17. * types to a log. Two methods are used to write the entryItems:
  18. *
  19. * <p>
  20. * <code>appendLog(java.io.Serializable entryItem)</code> which writes the
  21. * entry to the Log,
  22. * </p>
  23. *
  24. * <p>
  25. * <code>appendLog(java.io.Serializable entryItem, org.osid.shared.Type
  26. * formatType, org.osid.shared.Type priorityType)</code> which writes the
  27. * entryItem to the Log as well as formatType and priorityType.
  28. * </p>
  29. *
  30. * <p>
  31. * The implementation sets the timestamp for the for when the entryItem was
  32. * appended to the log. The format type and the priority type can be set as
  33. * defaults for subsequent appends.
  34. * </p>
  35. *
  36. * <p>
  37. * OSID Version: 2.0
  38. * </p>
  39. *
  40. * <p>
  41. * Licensed under the {@link org.osid.SidImplementationLicenseMIT MIT}
  42. * O.K.I&#46; OSID Definition License}.
  43. * </p>
  44. *
  45. * @package harmoni.osid_v2.logging
  46. */
  47. class HarmoniWritableLog
  48. extends HarmoniReadableLog
  49. // extends WritableLog // implements writable log
  50.  
  51. {
  52.  
  53. /**
  54. * Write the entryItem to the Log. The entryItem is written to the Log
  55. * using the format type and priority type explicitly set by the
  56. * application or the implementation default.
  57. *
  58. * @param object mixed $entryItem (original type: java.io.Serializable)
  59. *
  60. * @throws object LoggingException An exception with one of the
  61. * following messages defined in org.osid.logging.LoggingException
  62. * may be thrown: {@link }
  63. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  64. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  65. * OPERATION_FAILED}, {@link }
  66. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  67. * CONFIGURATION_ERROR}, {@link }
  68. * org.osid.logging.LoggingException#PERMISSION_DENIED
  69. * PERMISSION_DENIED}, {@link }
  70. * org.osid.logging.LoggingException#PRIORITY_TYPE_NOT_SET
  71. * PRIORITY_TYPE_NOT_SET}, {@link }
  72. * org.osid.logging.LoggingException#FORMAT_TYPE_NOT_SET
  73. * FORMAT_TYPE_NOT_SET}, {@link }
  74. * org.osid.logging.LoggingException#NULL_ARGUMENT NULL_ARGUMENT}
  75. *
  76. * @access public
  77. */
  78. function appendLog ( $entryItem ) {
  79. if (!$entryItem)
  80. throwError(new Error(LoggingException::NULL_ARGUMENT(), "HarmoniWritableLog"));
  81. if (!isset($this->_formatType))
  82. throwError(new Error(LoggingException::FORMAT_TYPE_NOT_SET(), "HarmoniWritableLog"));
  83. if (!isset($this->_priorityType))
  84. throwError(new Error(LoggingException::PRIORITY_TYPE_NOT_SET(), "HarmoniWritableLog"));
  85. $this->appendLogWithTypes($entryItem, $this->_formatType, $this->_priorityType);
  86. }
  87.  
  88. /**
  89. * Write the entry, the priorityType and formatType to the Log.
  90. *
  91. * @param object mixed $entryItem (original type: java.io.Serializable)
  92. * @param object Type $formatType
  93. * @param object Type $priorityType
  94. *
  95. * @throws object LoggingException An exception with one of the
  96. * following messages defined in org.osid.logging.LoggingException
  97. * may be thrown: {@link }
  98. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  99. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  100. * OPERATION_FAILED}, {@link }
  101. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  102. * CONFIGURATION_ERROR}, {@link }
  103. * org.osid.logging.LoggingException#PERMISSION_DENIED
  104. * PERMISSION_DENIED}, {@link }
  105. * org.osid.logging.LoggingException#UNKNOWN_TYPE UNKNOWN_TYPE},
  106. * {@link org.osid.logging.LoggingException#NULL_ARGUMENT}
  107. * NULL_ARGUMENT}
  108. *
  109. * @access public
  110. */
  111. function appendLogWithTypes ( $entryItem, $formatType, $priorityType ) {
  112. ArgumentValidator::validate($entryItem, ExtendsValidatorRule::getRule("AgentNodeEntryItem"));
  113. ArgumentValidator::validate($formatType, ExtendsValidatorRule::getRule("Type"));
  114. ArgumentValidator::validate($priorityType, ExtendsValidatorRule::getRule("Type"));
  115. $formatTypeId = $this->_getTypeId($formatType);
  116. $priorityTypeId = $this->_getTypeId($priorityType);
  117. $dbc = Services::getService("DatabaseManager");
  118. // Insert the entry
  119. $query = new InsertQuery;
  120. $query->setTable("log_entry");
  121. $query->setAutoIncrementColumn("id", "log_entry_id_seq");
  122. $query->setColumns(array( "log_name",
  123. "fk_format_type",
  124. "fk_priority_type",
  125. "category",
  126. "description",
  127. "backtrace"));
  128. $query->addRowOfValues(array("'".addslashes($this->_name)."'",
  129. "'".addslashes($formatTypeId)."'",
  130. "'".addslashes($priorityTypeId)."'",
  131. "'".addslashes($entryItem->getCategory())."'",
  132. "'".addslashes($entryItem->getDescription())."'",
  133. "'".addslashes($entryItem->getBacktrace())."'"));
  134. $results =$dbc->query($query, $this->_dbIndex);
  135. $entryId = $results->getLastAutoIncrementValue();
  136. // Add the agents
  137. $agentIds =$entryItem->getAgentIds();
  138. if (!$agentIds->hasNext())
  139. $entryItem->addUserIds();
  140. $agentIds =$entryItem->getAgentIds();
  141. if ($agentIds->hasNext()) {
  142. $query = new InsertQuery;
  143. $query->setTable("log_agent");
  144. $query->setColumns(array( "fk_entry",
  145. "fk_agent"));
  146. while ($agentIds->hasNext()) {
  147. $agentId =$agentIds->next();
  148. $query->addRowOfValues(array("'".addslashes($entryId)."'",
  149. "'".addslashes($agentId->getIdString())."'"));
  150. }
  151. $dbc->query($query, $this->_dbIndex);
  152. }
  153. // Add the nodes
  154. $nodeIds =$entryItem->getNodeIds();
  155. if ($nodeIds->hasNext()) {
  156. $query = new InsertQuery;
  157. $query->setTable("log_node");
  158. $query->setColumns(array( "fk_entry",
  159. "fk_node"));
  160. while ($nodeIds->hasNext()) {
  161. $nodeId =$nodeIds->next();
  162. $query->addRowOfValues(array("'".addslashes($entryId)."'",
  163. "'".addslashes($nodeId->getIdString())."'"));
  164. }
  165. $dbc->query($query, $this->_dbIndex);
  166. }
  167. }
  168.  
  169. /**
  170. * Assign the priorityType for all subsequent writes during the lifetime of
  171. * this instance. PriorityType has meaning to the caller of this method.
  172. *
  173. * @param object Type $priorityType
  174. *
  175. * @throws object LoggingException An exception with one of the
  176. * following messages defined in org.osid.logging.LoggingException
  177. * may be thrown: {@link }
  178. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  179. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  180. * OPERATION_FAILED}, {@link }
  181. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  182. * CONFIGURATION_ERROR}, {@link }
  183. * org.osid.logging.LoggingException#PERMISSION_DENIED
  184. * PERMISSION_DENIED}, {@link }
  185. * org.osid.logging.LoggingException#UNKNOWN_TYPE UNKNOWN_TYPE},
  186. * {@link org.osid.logging.LoggingException#NULL_ARGUMENT}
  187. * NULL_ARGUMENT}
  188. *
  189. * @access public
  190. */
  191. function assignPriorityType ( $priorityType ) {
  192. ArgumentValidator::validate($priorityType, ExtendsValidatorRule::getRule("Type"));
  193. $this->_priorityType =$priorityType;
  194. }
  195.  
  196. /**
  197. * Assign the formatType for all subsequent writes during the lifetime of
  198. * this instance. FormatType has meaning to the caller of this method.
  199. *
  200. * @param object Type $formatType
  201. *
  202. * @throws object LoggingException An exception with one of the
  203. * following messages defined in org.osid.logging.LoggingException
  204. * may be thrown: {@link }
  205. * org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  206. * {@link org.osid.logging.LoggingException#OPERATION_FAILED}
  207. * OPERATION_FAILED}, {@link }
  208. * org.osid.logging.LoggingException#CONFIGURATION_ERROR
  209. * CONFIGURATION_ERROR}, {@link }
  210. * org.osid.logging.LoggingException#PERMISSION_DENIED
  211. * PERMISSION_DENIED}, {@link }
  212. * org.osid.logging.LoggingException#UNKNOWN_TYPE UNKNOWN_TYPE},
  213. * {@link org.osid.logging.LoggingException#NULL_ARGUMENT}
  214. * NULL_ARGUMENT}
  215. *
  216. * @access public
  217. */
  218. function assignFormatType ( $formatType ) {
  219. ArgumentValidator::validate($formatType, ExtendsValidatorRule::getRule("Type"));
  220. $this->_formatType =$formatType;
  221. }
  222. /**
  223. * Answer the database id for the type passed.
  224. *
  225. * @param object Type $type
  226. * @return string
  227. * @access public
  228. * @since 3/1/06
  229. */
  230. function _getTypeId ( $type ) {
  231. if (!isset($this->_typeIds))
  232. $this->_typeIds = array();
  233. if (!isset($this->_typeIds[Type::typeToString($type)])) {
  234. $dbc = Services::getService("DatabaseManager");
  235. $query = new SelectQuery;
  236. $query->addColumn("id");
  237. $query->addTable("log_type");
  238. $query->addWhere("domain = '".addslashes($type->getDomain())."'");
  239. $query->addWhere("authority = '".addslashes($type->getAuthority())."'");
  240. $query->addWhere("keyword = '".addslashes($type->getKeyword())."'");
  241. $results =$dbc->query($query, $this->_dbIndex);
  242. if ($results->getNumberOfRows()) {
  243. $this->_typeIds[Type::typeToString($type)] = $results->field("id");
  244. $results->free();
  245. } else {
  246. $results->free();
  247. $query = new InsertQuery;
  248. $query->setTable("log_type");
  249. $query->setAutoIncrementColumn("id", "log_type_id_seq");
  250. $query->setColumns(array( "domain",
  251. "authority",
  252. "keyword",
  253. "description"));
  254. $query->addRowOfValues(array("'".addslashes($type->getDomain())."'",
  255. "'".addslashes($type->getAuthority())."'",
  256. "'".addslashes($type->getKeyword())."'",
  257. "'".addslashes($type->getDescription())."'"));
  258. $results =$dbc->query($query, $this->_dbIndex);
  259. $this->_typeIds[Type::typeToString($type)] = $results->getLastAutoIncrementValue();
  260. }
  261. }
  262. return $this->_typeIds[Type::typeToString($type)];
  263. }
  264. }
  265.  
  266. ?>

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