PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tanora.org/www/framework/system/field.php

https://bitbucket.org/ekkl/tanora
PHP | 144 lines | 76 code | 19 blank | 49 comment | 2 complexity | 08fa70dd1ef34d7381bbf96d0c326dca MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * File: framework/system/field.php
  4. *
  5. * Defines the base class for all Field objects in an ORM.
  6. */
  7. abstract class Field {
  8. protected $db;
  9. protected $column;
  10. protected $input;
  11. protected $name;
  12. protected $value;
  13. protected $primary;
  14. protected $unique;
  15. /**
  16. * Sets the database member variable and the column definition.
  17. */
  18. function __construct(&$db) {
  19. $this->db = $db;
  20. }
  21. /**
  22. * Sets the name member variable.
  23. */
  24. public function set_name($value) {
  25. $this->name = $value;
  26. $this->input->set_name($this->name);
  27. }
  28. /**
  29. * Gets the name member variable.
  30. */
  31. public function get_name() {
  32. return $this->name;
  33. }
  34. /**
  35. * Returns a boolean of whether or not the value has been set.
  36. */
  37. public function has_value() {
  38. return isset($this->value);
  39. }
  40. /**
  41. * Returns the value.
  42. */
  43. public function get_value() {
  44. return $this->value;
  45. }
  46. /**
  47. * Returns the column.
  48. */
  49. public function get_column() {
  50. return $this->column;
  51. }
  52. /**
  53. * Sets the value.
  54. */
  55. public function set_value($value) {
  56. $this->value = $value;
  57. }
  58. /**
  59. * Sets the primary member variable.
  60. */
  61. public function set_primary() {
  62. $this->primary = TRUE;
  63. }
  64. /**
  65. * Returns true if set_primary member variable is TRUE.
  66. */
  67. public function is_primary() {
  68. return $this->primary === TRUE;
  69. }
  70. /**
  71. * Sets the unique member variable.
  72. */
  73. public function set_unique() {
  74. $this->unique = TRUE;
  75. }
  76. /**
  77. * Returns true if set_unique member variable is TRUE.
  78. */
  79. public function is_unique() {
  80. return $this->unique === TRUE;
  81. }
  82. /**
  83. * Returns a reference the input member variable.
  84. */
  85. public function get_input() {
  86. return $this->input;
  87. }
  88. /**
  89. * Sets the input value and returns the reference.
  90. */
  91. protected function _input($type) {
  92. // array of files in order of priority they should be checked
  93. $paths = array(INPUT_PATH, FRAMEWORK_PATH.'inputs/');
  94. require_once(FRAMEWORK_PATH.'system/input.php');
  95. foreach($paths as $dir) {
  96. $file = $dir.strtolower($type).'input.php';
  97. if(file_exists($file)) {
  98. require_once($file);
  99. $class = $type.'Input';
  100. $this->input = new $class();
  101. return $this->input;
  102. }
  103. }
  104. Framework::error('Cannot load input: '.$type);
  105. }
  106. /**
  107. * Sets the column member variable.
  108. */
  109. protected function _column($type) {
  110. // array of files in order of priority they should be checked
  111. $paths = array(COLUMN_PATH, FRAMEWORK_PATH.'columns/');
  112. require_once(FRAMEWORK_PATH.'system/column.php');
  113. foreach($paths as $dir) {
  114. $file = $dir.strtolower($type).'column.php';
  115. if(file_exists($file)) {
  116. require_once($file);
  117. $class = $type.'Column';
  118. $this->column = new $class($this->db, $this);
  119. return $this->column;
  120. }
  121. }
  122. Framework::error('Cannot load column: '.$type);
  123. }
  124. }
  125. ?>