Source for file FieldValueSearch.class.php

Documentation is available at FieldValueSearch.class.php

  1. <?php
  2.  
  3. require_once HARMONI."dataManager/search/SearchCriteria.interface.php";
  4.  
  5. /**
  6. * Searches for only {@link Record}s that contain a certain field=value pair.
  7. *
  8. * @package harmoni.datamanager.search
  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: FieldValueSearch.class.php,v 1.13 2007/09/04 20:25:32 adamfranco Exp $
  14. */
  15. class FieldValueSearch extends SearchCriteria {
  16. var $_schemaID;
  17. var $_label;
  18. var $_value;
  19. var $_comparison;
  20. /**
  21. * The constructor.
  22. * @param string $schemaID The ID that references the {@link Schema} to apply this search to.
  23. * @param string $label The specific field within that {@link Schema} to check.
  24. * @param ref object $value An {@link SObject} object which holds the value to search for.
  25. * @param optional int $comparisonType The comparison type to use (equals, contains, less than, etc.) See the SEARCH_TYPE_* constants. Defaults to SEARCH_TYPE_EQUALS
  26. * @return void
  27. */
  28. function FieldValueSearch( $schemaID, $label, $value, $comparisonType=SEARCH_TYPE_EQUALS) {
  29. $this->_schemaID =$schemaID;
  30. $this->_label = $label;
  31. $this->_value =$value;
  32. $this->_comparison = $comparisonType;
  33. }
  34. function returnSearchString() {
  35. $mgr = Services::getService("SchemaManager");
  36. $typeMgr = Services::getService("DataTypeManager");
  37. $def =$mgr->getSchemaByID($this->_schemaID);
  38. $def->load();
  39. $fieldID = $def->getFieldIDFromLabel($this->_label);
  40. $field =$def->getField($fieldID);
  41. // first check if the $value we have is of the correct data type
  42. $extendsRule = ExtendsValidatorRule::getRule("HarmoniIterator");
  43. if (!$typeMgr->isObjectOfDataType($this->_value, $field->getType())
  44. && !$extendsRule->check($this->_value))
  45. {
  46. throwError( new Error("Cannot take a '".get_class($this->_value)."' object as search criteria
  47. for field '$this->_label'; a '".$field->getType()."' is required.","FieldValueSearch",true));
  48. }
  49. $class = $typeMgr->storablePrimitiveClassForType($field->getType());
  50. eval('$string = '.$class.'::makeSearchString($this->_value, $this->_comparison);');
  51. return "(dm_record_field.fk_schema_field='".addslashes($fieldID)."' AND ".$string." AND dm_record_field.active=1)";
  52. }
  53.  
  54. function postProcess($ids) { return $ids; }
  55. }
  56.  
  57. ?>

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