2require_once(dirname(__FILE__) .
'/../class.arFieldList.php');
18 const REGEX =
"/([a-z]*)\\(([0-9]*)\\)/us";
22 protected static $field_map = array(
34 protected static $length_map = array(
49 protected $table_name =
'';
53 protected $class_name =
'';
57 protected $structure = array();
61 protected $ids = array();
68 public function __construct($table_name, $class_name)
70 $this->setClassName($class_name);
71 $this->setTableName($table_name);
72 $this->readStructure();
76 public function readStructure()
78 $sql =
'DESCRIBE ' . $this->getTableName();
79 $res = self::getDB()->query($sql);
80 while (
$data = self::getDB()->fetchObject(
$res)) {
81 $this->addStructure(
$data);
86 public function downloadClassFile()
89require_once('./Services/ActiveRecord/class.ActiveRecord.php');
97class {CLASS_NAME} extends ActiveRecord {
103 static function returnDbTableName() {
104 return '{TABLE_NAME}';
110 public function getConnectorContainerName() {
111 return '{TABLE_NAME}';
114 $txt = str_replace(
'{CLASS_NAME}', $this->getClassName(),
$header);
115 $txt = str_replace(
'{TABLE_NAME}', $this->getTableName(),
$txt);
117 foreach ($this->getStructure() as $str) {
121 foreach ($this->returnAttributesForField($str) as
$name => $value) {
122 $member .=
' * @con_' .
$name .
' ' . $value .
"\n";
126 protected \${FIELD_NAME};
130 $member = str_replace(
'{FIELD_NAME}', $str->field, $member);
131 $member = str_replace(
'{DECLARATION}',
' ', $member);
133 $all_members .= $member;
142 header(
'Content-type: application/x-httpd-php');
143 header(
"Content-Disposition: attachment; filename=\"class." . $this->getClassName() .
".php\"");
154 protected function returnAttributesForField(stdClass $field)
161 if ($field->null ==
'NO') {
165 if ($field->key ==
'PRI') {
179 protected static function lookupFieldType($string)
181 preg_match(self::REGEX, $string, $matches);
183 return self::$field_map[$matches[1]];
192 protected static function lookupFieldLength($string)
194 $field_type = self::lookupFieldType($string);
196 preg_match(self::REGEX, $string, $matches);
198 if (self::$length_map[$field_type][$matches[2]]) {
199 return self::$length_map[$field_type][$matches[2]];
209 public static function getDB()
225 public function setTableName($table_name)
227 $this->table_name = $table_name;
234 public function getTableName()
236 return $this->table_name;
243 public function setStructure($structure)
245 $this->structure = $structure;
252 public function getStructure()
254 return $this->structure;
261 public function addStructure(stdClass $structure)
263 if (!in_array($structure->field, $this->ids)) {
264 $this->structure[] = $structure;
265 $this->ids[] = $structure->field;
273 public function setClassName($class_name)
275 $this->class_name = $class_name;
282 public function getClassName()
284 return $this->class_name;
An exception for terminatinating execution or to throw for unit testing.
const FIELD_TYPE_TIMESTAMP
foreach($_POST as $key=> $value) $res