1: <?php
2: /**
3: * Used by the QCubed Code Generator to describe a database Type Table
4: * "Type" tables must be defined with at least two columns, the first one being an integer-based primary key,
5: * and the second one being the name of the type.
6: * @package Codegen
7: *
8: * @property string $Name
9: * @property string $ClassName
10: * @property string[] $NameArray
11: * @property string[] $TokenArray
12: * @property array $ExtraPropertyArray
13: * @property string[] $ExtraFieldNamesArray
14: * @property-read QSqlColumn[] $PrimaryKeyColumnArray
15: * @property-write QSqlColumn $KeyColumn
16: * @property QManyToManyReference[] $ManyToManyReferenceArray
17: */
18: class QTypeTable extends QBaseClass {
19:
20: /////////////////////////////
21: // Protected Member Variables
22: /////////////////////////////
23:
24: /**
25: * Name of the table (as defined in the database)
26: * @var string Name
27: */
28: protected $strName;
29:
30: /**
31: * Name as a PHP Class
32: * @var string ClassName
33: */
34: protected $strClassName;
35:
36: /**
37: * Array of Type Names (as entered into the rows of this database table)
38: * This is indexed by integer which represents the ID in the database, starting with 1
39: * @var string[] NameArray
40: */
41: protected $strNameArray;
42:
43: /**
44: * Column names for extra properties (beyond the 2 basic columns), if any.
45: */
46: protected $strExtraFieldNamesArray;
47:
48: /**
49: * Array of extra properties. This is a double-array - array of arrays. Example:
50: * 1 => ['col1' => 'valueA', 'col2 => 'valueB'],
51: * 2 => ['col1' => 'valueC', 'col2 => 'valueD'],
52: * 3 => ['col1' => 'valueC', 'col2 => 'valueD']
53: */
54: protected $arrExtraPropertyArray;
55:
56: /**
57: * Array of Type Names converted into Tokens (can be used as PHP Constants)
58: * This is indexed by integer which represents the ID in the database, starting with 1
59: * @var string[] TokenArray
60: */
61: protected $strTokenArray;
62:
63: protected $objKeyColumn;
64: protected $objManyToManyReferenceArray;
65:
66: /////////////////////
67: // Public Constructor
68: /////////////////////
69:
70: /**
71: * Default Constructor. Simply sets up the TableName.
72: *
73: * @param string $strName Name of the Table
74: * @return QTypeTable
75: */
76: public function __construct($strName) {
77: $this->strName = $strName;
78: }
79:
80: /**
81: * Returns the string that will be used to represent the literal value given when codegenning a type table
82: * @param $mixColValue
83: * @return string
84: */
85: public static function Literal($mixColValue) {
86: if (is_null($mixColValue)) return 'null';
87: elseif (is_integer($mixColValue)) return $mixColValue;
88: elseif (is_bool($mixColValue)) return ($mixColValue ? 'true' : 'false');
89: elseif (is_float($mixColValue)) return "(float)$mixColValue";
90: elseif (is_object($mixColValue)) return "'" . $mixColValue->_toString() . "'"; // whatever is suitable for the constructor of the object
91: else return "'" . str_replace("'", "\\'", $mixColValue) . "'";
92: }
93:
94: ////////////////////
95: // Public Overriders
96: ////////////////////
97:
98: /**
99: * Override method to perform a property "Get"
100: * This will get the value of $strName
101: *
102: * @param string $strName Name of the property to get
103: * @throws Exception
104: * @throws QCallerException
105: * @return mixed
106: */
107: public function __get($strName) {
108: switch ($strName) {
109: case 'Name':
110: return $this->strName;
111: case 'ClassName':
112: return $this->strClassName;
113: case 'NameArray':
114: return $this->strNameArray;
115: case 'TokenArray':
116: return $this->strTokenArray;
117: case 'ExtraPropertyArray':
118: return $this->arrExtraPropertyArray;
119: case 'ExtraFieldNamesArray':
120: return $this->strExtraFieldNamesArray;
121: case 'PrimaryKeyColumnArray':
122: $a[] = $this->objKeyColumn;
123: return $a;
124: case 'ManyToManyReferenceArray':
125: return (array) $this->objManyToManyReferenceArray;
126:
127: default:
128: try {
129: return parent::__get($strName);
130: } catch (QCallerException $objExc) {
131: $objExc->IncrementOffset();
132: throw $objExc;
133: }
134: }
135: }
136:
137: /**
138: * Override method to perform a property "Set"
139: * This will set the property $strName to be $mixValue
140: *
141: * @param string $strName Name of the property to set
142: * @param string $mixValue New value of the property
143: * @throws Exception
144: * @throws QCallerException
145: * @return mixed
146: */
147: public function __set($strName, $mixValue) {
148: try {
149: switch ($strName) {
150: case 'Name':
151: return $this->strName = QType::Cast($mixValue, QType::String);
152: case 'ClassName':
153: return $this->strClassName= QType::Cast($mixValue, QType::String);
154: case 'NameArray':
155: return $this->strNameArray = QType::Cast($mixValue, QType::ArrayType);
156: case 'TokenArray':
157: return $this->strTokenArray = QType::Cast($mixValue, QType::ArrayType);
158: case 'ExtraPropertyArray':
159: return $this->arrExtraPropertyArray = QType::Cast($mixValue, QType::ArrayType);
160: case 'ExtraFieldNamesArray':
161: return $this->strExtraFieldNamesArray = QType::Cast($mixValue, QType::ArrayType);
162: case 'KeyColumn':
163: return $this->objKeyColumn = $mixValue;
164: case 'ManyToManyReferenceArray':
165: return $this->objManyToManyReferenceArray = QType::Cast($mixValue, QType::ArrayType);
166: default:
167: return parent::__set($strName, $mixValue);
168: }
169: } catch (QCallerException $objExc) {
170: $objExc->IncrementOffset();
171: throw $objExc;
172: }
173: }
174: }