Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class RecordField{
- private $_name = NULL;
- private $_type = NULL; //string|integer|float
- private $_value = NULL; //real DB NULL is 'NULL'
- private $_default = NULL;
- /**
- * Contains an associative array with the reference of the RecordField
- * object of this table as key and as its element an array of references
- * to the RecordField objets to which this Record item is constraint.
- *
- * @var array
- */
- private $_relationships = array();
- /**
- * Reference to the Record object instantiated
- * @var <type>
- */
- private $_record = NULL;
- //Constructor
- public function __construct(){
- $_args = func_get_args();
- if(is_array($_args[0])){
- $_args = array_values($_args[0]);
- }
- $_numargs = count($_args);
- if($_numargs === 0){
- $this->_name = NULL;
- $this->_type = NULL;
- $this->_value = NULL;
- $this->_default = NULL;
- }else{
- if($_numargs >= 1){$this->setName ($_args[0]);}
- if($_numargs >= 2){$this->setType ($_args[1]);}
- if($_numargs >= 3){$this->setValue ($_args[2]);}
- if($_numargs >= 4){$this->setDefault($_args[3]);}
- if($_numargs >= 5){$this->setRecord ($_args[4]);}
- }
- }
- //Accessors & Mutators
- public function getName(){
- return $this->_name;
- }
- public function getType(){
- return $this->_type;
- }
- public function getValue(){
- if(preg_match('/(text|TEXT|blob|BLOB)$/',$this->_type) == true){
- return stripslashes($this->_value);
- }return $this->_value;
- }
- public function getDefault(){
- return $this->_default;
- }
- protected function &getRelationships($fieldname = NULL){
- return ($fieldname)?
- ((array_key_exists($fieldname,$this->_relationships))?($this->_relationships[$fieldname]):(NULL))
- :
- ($this->_relationships);
- }
- public function &getRecord(){
- return $this->_record;
- }
- public function setName($n){
- $this->_name = (string)($n);
- return $this;
- }
- public function setType($t){
- $this->_type = (string)($t);
- return $this;
- }
- public function setValue($v){
- $this->_value = $this->cast($v);
- return $this;
- }
- public function setDefault($d){
- $this->_default = $this->cast($d);
- return $this;
- }
- public function setRelationship(RecordField $_record_field){
- if(!isset($this->_relationships[$_record_field->getName()])){
- $this->_relationships[$_record_field->getName()] = &$_record_field;
- }
- }
- public function setRecord(Record $_record){
- $this->_record = &$_record;
- return $this;
- }
- //Methods & Functions
- private function cast($v){
- return sql_data_cast($v, $this->_type);
- }
- public function buildXML(){
- $xml_node = new SimpleXMLElement('<RecordField/>');
- $xml_node->addAttribute('name', (string)($this->_name));
- $xml_node->addAttribute('type', (string)($this->_type));
- $xml_node->addAttribute('value', (string)($this->_value));
- $xml_node->addAttribute('default', (string)($this->_default));
- return $xml_node;
- }
- public function parseXML(SimpleXMLElement $xml_node){
- if($xml_node->getName() == 'RecordField'){
- $this->setName($xml_node['name']);
- $this->setType($xml_node['type']);
- $this->setValue($xml_node['value']);
- $this->setDefault($xml_node['default']);
- return true;
- }return false;
- }
- }
Add Comment
Please, Sign In to add comment