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

Language PHP Lines 145
MD5 Hash 08fa70dd1ef34d7381bbf96d0c326dca Estimated Cost $1,755 (why?)
Repository https://bitbucket.org/ekkl/tanora View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
 * File: framework/system/field.php
 *
 * Defines the base class for all Field objects in an ORM.
 */

abstract class Field {
	
	protected $db;
	
	protected $column;
	protected $input;
	
	protected $name;
	protected $value;
	protected $primary;
	protected $unique;
	
	/**
	 * Sets the database member variable and the column definition.
	 */
	function __construct(&$db) {
		$this->db = $db;
	}
	
	/**
	 * Sets the name member variable.
	 */
	public function set_name($value) {
		$this->name = $value;
		$this->input->set_name($this->name);
	}
	
	/**
	 * Gets the name member variable.
	 */
	public function get_name() {
		return $this->name;
	}
	
	/**
	 * Returns a boolean of whether or not the value has been set.
	 */
	public function has_value() {
		return isset($this->value);
	}
	
	/**
	 * Returns the value.
	 */
	public function get_value() {
		return $this->value;
	}
	
	/**
	 * Returns the column.
	 */
	public function get_column() {
		return $this->column;
	}
	
	/**
	 * Sets the value.
	 */
	public function set_value($value) {
		$this->value = $value;
	}
	
	/**
	 * Sets the primary member variable.
	 */
	public function set_primary() {
		$this->primary = TRUE;
	}
	
	/**
	 * Returns true if set_primary member variable is TRUE.
	 */
	public function is_primary() {
		return $this->primary === TRUE;
	}
	
	/**
	 * Sets the unique member variable.
	 */
	public function set_unique() {
		$this->unique = TRUE;
	}
	
	/**
	 * Returns true if set_unique member variable is TRUE.
	 */
	public function is_unique() {
		return $this->unique === TRUE;
	}
	
	/**
	 * Returns a reference the input member variable.
	 */
	public function get_input() {
		return $this->input;
	}
	
	/**
	 * Sets the input value and returns the reference.
	 */
	protected function _input($type) {
		// array of files in order of priority they should be checked
		$paths = array(INPUT_PATH, FRAMEWORK_PATH.'inputs/');
		require_once(FRAMEWORK_PATH.'system/input.php');
		foreach($paths as $dir) {
			$file = $dir.strtolower($type).'input.php';
			if(file_exists($file)) {
				require_once($file);
				$class = $type.'Input';
				$this->input = new $class();
				return $this->input;
			}
		}
		Framework::error('Cannot load input: '.$type);
	}
	
	/**
	 * Sets the column member variable.
	 */
	protected function _column($type) {
		// array of files in order of priority they should be checked
		$paths = array(COLUMN_PATH, FRAMEWORK_PATH.'columns/');
		require_once(FRAMEWORK_PATH.'system/column.php');
		foreach($paths as $dir) {
			$file = $dir.strtolower($type).'column.php';
			if(file_exists($file)) {
				require_once($file);
				$class = $type.'Column';
				$this->column = new $class($this->db, $this);
				return $this->column;
			}
		}
		Framework::error('Cannot load column: '.$type);
	}
}

?>
Back to Top