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') {
178 protected static function lookupFieldType($string)
180 preg_match(self::REGEX, $string, $matches);
182 return self::$field_map[$matches[1]];
191 protected static function lookupFieldLength($string)
193 $field_type = self::lookupFieldType($string);
195 preg_match(self::REGEX, $string, $matches);
197 if (self::$length_map[$field_type][$matches[2]]) {
198 return self::$length_map[$field_type][$matches[2]];
208 public static function getDB()
224 public function setTableName($table_name)
226 $this->table_name = $table_name;
233 public function getTableName()
235 return $this->table_name;
242 public function setStructure($structure)
244 $this->structure = $structure;
251 public function getStructure()
253 return $this->structure;
260 public function addStructure(stdClass $structure)
262 if (!in_array($structure->Field, $this->ids)) {
263 $this->structure[] = $structure;
264 $this->ids[] = $structure->Field;
272 public function setClassName($class_name)
274 $this->class_name = $class_name;
281 public function getClassName()
283 return $this->class_name;
An exception for terminatinating execution or to throw for unit testing.
const FIELD_TYPE_TIMESTAMP
if(array_key_exists('yes', $_REQUEST)) $attributes
foreach($_POST as $key=> $value) $res