Source for file StorableString.abstract.php

Documentation is available at StorableString.abstract.php

  1. <?php
  2.  
  3. /**
  4. * This is the {@link StorablePrimitive} abstract for classes with string-type data values.
  5. *
  6. * @package harmoni.datamanager.storableprimitives
  7. *
  8. * @copyright Copyright &copy; 2005, Middlebury College
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  10. *
  11. * @version $Id: StorableString.abstract.php,v 1.12 2007/09/04 20:25:33 adamfranco Exp $
  12. */
  13. class StorableStringAbstract extends String /* implements StorablePrimitive */ {
  14.  
  15. /*******************************************************
  16. * Instance Methods
  17. *********************************************************/
  18.  
  19. var $_table;
  20. /**
  21. * Inserts a new row into the Database with the data contained in the object.
  22. * @param integer $dbID The {@link DBHandler} database ID to query.
  23. * @access public
  24. * @return integer Returns the new ID of the data stored.
  25. */
  26. function insert($dbID) {
  27. $idManager = Services::getService("Id");
  28. $newID =$idManager->createId();
  29. $query = new InsertQuery();
  30. $query->setTable($this->_table);
  31. $query->setColumns(array("id","data"));
  32. $query->addRowOfValues(array("'".addslashes($newID->getIdString())."'", "'".addslashes($this->asString())."'"));
  33. $dbHandler = Services::getService("DatabaseManager");
  34. $result =$dbHandler->query($query, $dbID);
  35. if (!$result || $result->getNumberOfRows() != 1) {
  36. throwError( new UnknownDBError("StorableString") );
  37. return false;
  38. }
  39. return $newID->getIdString();
  40. }
  41. /**
  42. * Uses the ID passed and updates the database row with
  43. * new data.
  44. * @param integer $dbID The {@link DBHandler} database ID to query.
  45. * @param integer $dataID The ID in the database of the data to be updated.
  46. * @access public
  47. * @return void
  48. */
  49. function update($dbID, $dataID) {
  50. if (!$dataID) return false;
  51. $query = new UpdateQuery();
  52. $query->setTable($this->_table);
  53. $query->setColumns(array("data"));
  54. $query->setWhere("id='".addslashes($dataID)."'");
  55. $query->setValues(array("'".addslashes($this->asString())."'"));
  56. $dbHandler = Services::getService("DatabaseManager");
  57. $result =$dbHandler->query($query, $dbID);
  58. if (!$result) {
  59. throwError( new UnknownDBError("StorableString") );
  60. return false;
  61. }
  62. return true;
  63. }
  64. /**
  65. * Deletes the data row from the appropriate table.
  66. * @param integer $dbID The {@link DBHandler} database ID to query.
  67. * @param integer $dataID The ID in the database of the data to be deleted.
  68. * @access public
  69. * @return void
  70. */
  71. function prune($dbID, $dataID) {
  72. if (!$dataID) return;
  73. // delete ourselves from our data table
  74. $table = $this->_table;
  75. $query = new DeleteQuery;
  76. $query->setTable($table);
  77. $query->setWhere("id='".addslashes($dataID)."'");
  78. $dbHandler = Services::getService("DatabaseManager");
  79. $res =$dbHandler->query($query, $dbID);
  80. if (!$res) throwError( new UnknownDBError("StorablePrimitive"));
  81. }
  82. /*******************************************************
  83. * Conversion Methods
  84. *********************************************************/
  85.  
  86. /**
  87. * Convert this object to a StorableBlob
  88. *
  89. * @return object
  90. * @access public
  91. * @since 6/9/06
  92. */
  93. function asABlob () {
  94. return Blob::fromString($this->asString());
  95. }
  96. /**
  97. * Convert this object to a StorableString
  98. *
  99. * @return object
  100. * @access public
  101. * @since 6/9/06
  102. */
  103. function asAString () {
  104. return String::fromString($this->asString());
  105. }
  106. /**
  107. * Convert this object to a StorableShortString
  108. *
  109. * @return object
  110. * @access public
  111. * @since 6/9/06
  112. */
  113. function asAShortString () {
  114. return String::fromString($this->asString());
  115. }
  116. /**
  117. * Convert this object to a StorableTime
  118. *
  119. * @return object
  120. * @access public
  121. * @since 6/9/06
  122. */
  123. function asADateTime () {
  124. return DateAndTime::fromString($this->asString());
  125. }
  126. /**
  127. * Convert this object to a OKIType
  128. *
  129. * @return object
  130. * @access public
  131. * @since 6/9/06
  132. */
  133. function asAnOKIType () {
  134. return Type::stringToType($this->asString());
  135. }
  136. /**
  137. * Convert this object to a Boolean
  138. *
  139. * @return object
  140. * @access public
  141. * @since 6/9/06
  142. */
  143. function asABoolean() {
  144. return Boolean::withValue((strlen($this->asString()) > 0)?true:false);
  145. }
  146. /**
  147. * Convert this object to a StorableInteger
  148. *
  149. * @return object
  150. * @access public
  151. * @since 6/9/06
  152. */
  153. function asAInteger() {
  154. return Integer::fromString($this->asString());
  155. }
  156. /**
  157. * Convert this object to a StorableFloat
  158. *
  159. * @return object
  160. * @access public
  161. * @since 6/9/06
  162. */
  163. function asAFloat () {
  164. return Float::fromString($this->asString());
  165. }
  166. }

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