PageRenderTime 34ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/core/db/DbRelationshipOptions.php

http://zoop.googlecode.com/
PHP | 67 lines | 57 code | 10 blank | 0 comment | 8 complexity | 587803b3aab6a90a56dd6a2790f200cf MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. class DbRelationshipOptions extends DbRelationship
  3. {
  4. protected $options;
  5. protected $localField;
  6. protected $remoteTable;
  7. protected $remoteKeyField;
  8. protected $remoteValueField;
  9. function __construct($name, $params, $dbObject)
  10. {
  11. parent::__construct($name, $params, $dbObject);
  12. if(isset($params['options']))
  13. {
  14. if(isset($params['localField']))
  15. $this->localFieldName = $params['localField'];
  16. else
  17. $this->localFieldName = $name . '_id';
  18. $this->options = $params['options'];
  19. }
  20. else
  21. {
  22. if(isset($params['local_field']))
  23. $this->localFieldName = $params['local_field'];
  24. else
  25. $this->localFieldName = $name . '_id';
  26. if(isset($params['option_table']))
  27. $this->remoteTable = $params['option_table'];
  28. else
  29. $this->remoteTable = $name;
  30. if(isset($params['option_key_field']))
  31. $this->remoteKeyField = $params['option_key_field'];
  32. else
  33. $this->remoteKeyField = 'id';
  34. if(isset($params['option_value_field']))
  35. $this->remoteValueField = $params['option_value_field'];
  36. else
  37. $this->remoteValueField = 'name';
  38. }
  39. }
  40. public function isTiedToField($fieldName)
  41. {
  42. return $this->localFieldName == $fieldName;
  43. }
  44. public function getOptions()
  45. {
  46. if($this->options)
  47. return $this->options;
  48. else
  49. return SqlFetchSimpleMap("select {$this->remoteKeyField}, {$this->remoteValueField} from {$this->remoteTable}", $this->remoteKeyField, $this->remoteValueField, array());
  50. }
  51. public function getInfo()
  52. {
  53. $options = $this->getOptions();
  54. $field = $this->localFieldName;
  55. return $options[$this->dbObject->$field];
  56. }
  57. }