Source for file StorableString.class.php

Documentation is available at StorableString.class.php

  1. <?php
  2.  
  3. require_once(HARMONI."dataManager/storablePrimitives/StorableString.abstract.php");
  4.  
  5. /**
  6. * This is the {@link StorablePrimitive} equivalent of {@link String} for the dm_string table.
  7. *
  8. * @package harmoni.datamanager.storableprimitives
  9. *
  10. * @copyright Copyright &copy; 2005, Middlebury College
  11. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  12. *
  13. * @version $Id: StorableString.class.php,v 1.9 2007/09/04 20:25:33 adamfranco Exp $
  14. */
  15. class StorableString
  16. extends StorableStringAbstract
  17. /* implements StorablePrimitive */
  18. {
  19.  
  20. /*******************************************************
  21. * Class Methods
  22. *********************************************************/
  23.  
  24.  
  25. /**
  26. * Inserts a new row into the Database with the data contained in the object.
  27. * @param integer $dbID The {@link DBHandler} database ID to query.
  28. * @access public
  29. * @return integer Returns the new ID of the data stored.
  30. */
  31. function insert($dbID) {
  32. $this->_table = "dm_string";
  33. return parent::insert($dbID);
  34. }
  35. /**
  36. * Takes a single database row, which would contain the columns added by alterQuery()
  37. * and extracts the values to setup the object with the appropriate data.
  38. * @param array $dbRow
  39. * @access public
  40. * @return object StorableString
  41. * @static
  42. */
  43. function createAndPopulate( $dbRow ) {
  44. $string = new StorableString;
  45. $string->_setValue($dbRow["string_data"]);
  46. return $string;
  47. }
  48. /**
  49. * Returns a string that could be inserted into an SQL query's WHERE clause, based on the
  50. * {@link Primitive} value that is passed. It is used when searching for datasets that contain a certain
  51. * field=value pair.
  52. * @param ref object $value The {@link Primitive} object to search for.
  53. * @param int $searchType One of the SEARCH_TYPE_* constants, defining what type of search this should be (ie, equals,
  54. * contains, greater than, less than, etc)
  55. * @return string or NULL if no searching is allowed.
  56. * @static
  57. */
  58. function makeSearchString($value, $searchType = SEARCH_TYPE_EQUALS) {
  59. switch ($searchType) {
  60. case SEARCH_TYPE_EQUALS:
  61. return "dm_string.data='".addslashes($value->asString())."'";
  62. case SEARCH_TYPE_CONTAINS:
  63. return "dm_string.data LIKE '%".addslashes($value->asString())."%'";
  64. case SEARCH_TYPE_IN_LIST:
  65. $string = "dm_string.data IN (";
  66. while ($value->hasNext()) {
  67. $valueObj =$value->next();
  68. $string .= "'".addslashes($valueObj->asString())."'";
  69. if ($value->hasNext())
  70. $string .= ", ";
  71. }
  72. $string .= ")";
  73. return $string;
  74. case SEARCH_TYPE_NOT_IN_LIST:
  75. $string = "dm_string.data NOT IN (";
  76. while ($value->hasNext()) {
  77. $valueObj =$value->next();
  78. $string .= "'".addslashes($valueObj->asString())."'";
  79. if ($value->hasNext())
  80. $string .= ", ";
  81. }
  82. $string .= ")";
  83. return $string;
  84. }
  85. return null;
  86. }
  87. /*******************************************************
  88. * Instance Methods
  89. *********************************************************/
  90.  
  91. /**
  92. * Set the value
  93. *
  94. * @param $value
  95. * @return void
  96. * @access private
  97. * @since 7/13/05
  98. */
  99. function _setValue ($value) {
  100. $this->_string = (string) $value;
  101. }
  102. function StorableString() {
  103. $this->_table = "dm_string";
  104. }
  105. /**
  106. * Takes an existing {@link SelectQuery} and adds a table join and some columns so that
  107. * when it is executed the actual data can be retrieved from the row. The join condition must
  108. * be "fk_data = data_id_field", since the field "fk_data" is already part of the DataManager's
  109. * table structure.
  110. * @access public
  111. * @return void
  112. */
  113. function alterQuery( $query ) {
  114. $query->addTable("dm_string",LEFT_JOIN,"dm_string.id = fk_data");
  115. $query->addColumn("data","string_data","dm_string");
  116. }
  117. }

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