Fortune.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /** @package HelloWorld::Model */
  3. /** import supporting libraries */
  4. require_once("DAO/FortuneDAO.php");
  5. require_once("FortuneCriteria.php");
  6. /**
  7. * The Fortune class extends FortuneDAO which provides the access
  8. * to the datastore.
  9. *
  10. * @package HelloWorld::Model
  11. * @author ClassBuilder
  12. * @version 1.0
  13. */
  14. class Fortune extends FortuneDAO
  15. {
  16. /**
  17. * Override default validation
  18. * @see Phreezable::Validate()
  19. */
  20. public function Validate()
  21. {
  22. // example of custom validation
  23. // $this->ResetValidationErrors();
  24. // $errors = $this->GetValidationErrors();
  25. // if ($error == true) $this->AddValidationError('FieldName', 'Error Information');
  26. // return !$this->HasValidationErrors();
  27. return parent::Validate();
  28. }
  29. /**
  30. * @see Phreezable::OnSave()
  31. */
  32. public function OnSave($insert)
  33. {
  34. // the controller create/update methods validate before saving. this will be a
  35. // redundant validation check, however it will ensure data integrity at the model
  36. // level based on validation rules. comment this line out if this is not desired
  37. if (!$this->Validate()) throw new Exception('Unable to Save Fortune: ' . implode(', ', $this->GetValidationErrors()));
  38. // OnSave must return true or eles Phreeze will cancel the save operation
  39. return true;
  40. }
  41. /**
  42. * Override ToString for sorting purposes
  43. */
  44. public function ToString()
  45. {
  46. return $this->Message;
  47. }
  48. }
  49. ?>