Source for file StorableShortString.class.php

Documentation is available at StorableShortString.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_shortstring 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: StorableShortString.class.php,v 1.10 2007/09/04 20:25:33 adamfranco Exp $
  14. */
  15. class StorableShortString
  16. extends StorableStringAbstract
  17. /* implements StorablePrimitive */
  18. {
  19.  
  20. /*******************************************************
  21. * Class Methods
  22. *********************************************************/
  23.  
  24. /**
  25. * Inserts a new row into the Database with the data contained in the object.
  26. * @param integer $dbID The {@link DBHandler} database ID to query.
  27. * @access public
  28. * @return integer Returns the new ID of the data stored.
  29. */
  30. function insert($dbID) {
  31. $this->_table = "dm_shortstring";
  32. return parent::insert($dbID);
  33. }
  34. /**
  35. * Takes a single database row, which would contain the columns added by alterQuery()
  36. * and extracts the values to setup the object with the appropriate data.
  37. * @param array $dbRow
  38. * @access public
  39. * @return object StorableShortString
  40. * @static
  41. */
  42. function createAndPopulate( $dbRow ) {
  43. $string = new StorableShortString;
  44. $string->_setValue($dbRow["shortstring_data"]);
  45. return $string;
  46. }
  47. /**
  48. * Returns a string that could be inserted into an SQL query's WHERE clause, based on the
  49. * {@link Primitive} value that is passed. It is used when searching for datasets that contain a certain
  50. * field=value pair.
  51. * @param ref object $value The {@link Primitive} object to search for.
  52. * @param int $searchType One of the SEARCH_TYPE_* constants, defining what type of search this should be (ie, equals,
  53. * contains, greater than, less than, etc)
  54. * @return string or NULL if no searching is allowed.
  55. * @static
  56. */
  57. function makeSearchString($value, $searchType = SEARCH_TYPE_EQUALS) {
  58. switch ($searchType) {
  59. case SEARCH_TYPE_EQUALS:
  60. return "dm_shortstring.data='".addslashes($value->asString())."'";
  61. case SEARCH_TYPE_CONTAINS:
  62. return "dm_shortstring.data LIKE '%".addslashes($value->asString())."%'";
  63. case SEARCH_TYPE_IN_LIST:
  64. $string = "dm_shortstring.data IN (";
  65. while ($value->hasNext()) {
  66. $valueObj =$value->next();
  67. $string .= "'".addslashes($valueObj->asString())."'";
  68. if ($value->hasNext())
  69. $string .= ", ";
  70. }
  71. $string .= ")";
  72. return $string;
  73. case SEARCH_TYPE_NOT_IN_LIST:
  74. $string = "dm_shortstring.data NOT IN (";
  75. while ($value->hasNext()) {
  76. $valueObj =$value->next();
  77. $string .= "'".addslashes($valueObj->asString())."'";
  78. if ($value->hasNext())
  79. $string .= ", ";
  80. }
  81. $string .= ")";
  82. return $string;
  83. }
  84. return null;
  85. }
  86. /*******************************************************
  87. * Instance Methods
  88. *********************************************************/
  89.  
  90. /**
  91. * Set the value
  92. *
  93. * @param $value
  94. * @return void
  95. * @access private
  96. * @since 7/13/05
  97. */
  98. function _setValue ($value) {
  99. $this->_string = (string) $value;
  100. }
  101.  
  102. function StorableShortString() {
  103. $this->_table = "dm_shortstring";
  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_shortstring",LEFT_JOIN,"dm_shortstring.id = fk_data");
  115. $query->addColumn("data","shortstring_data","dm_shortstring");
  116. }
  117. }

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