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) {
69 $this->setClassName($class_name);
70 $this->setTableName($table_name);
71 $this->readStructure();
75 public function readStructure() {
76 $sql =
'DESCRIBE ' . $this->getTableName();
77 $res = self::getDB()->query($sql);
78 while (
$data = self::getDB()->fetchObject(
$res)) {
79 $this->addStructure(
$data);
84 public function downloadClassFile() {
88require_once('./Services/ActiveRecord/class.ActiveRecord.php');
96class {CLASS_NAME} extends ActiveRecord {
102 static function returnDbTableName() {
103 return '{TABLE_NAME}';
109 public function getConnectorContainerName() {
110 return '{TABLE_NAME}';
113 $txt = str_replace(
'{CLASS_NAME}', $this->getClassName(),
$header);
114 $txt = str_replace(
'{TABLE_NAME}', $this->getTableName(),
$txt);
116 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) {
155 $attributes = array();
160 if ($field->null ==
'NO') {
164 if ($field->key ==
'PRI') {
178 protected static function lookupFieldType($string) {
179 preg_match(self::REGEX, $string, $matches);
181 return self::$field_map[$matches[1]];
190 protected static function lookupFieldLength($string) {
191 $field_type = self::lookupFieldType($string);
193 preg_match(self::REGEX, $string, $matches);
195 if (self::$length_map[$field_type][$matches[2]]) {
196 return self::$length_map[$field_type][$matches[2]];
206 public static function getDB() {
220 public function setTableName($table_name) {
221 $this->table_name = $table_name;
228 public function getTableName() {
229 return $this->table_name;
236 public function setStructure($structure) {
237 $this->structure = $structure;
244 public function getStructure() {
245 return $this->structure;
252 public function addStructure(stdClass $structure) {
253 if(!in_array($structure->field, $this->ids)) {
254 $this->structure[] = $structure;
255 $this->ids[] = $structure->field;
263 public function setClassName($class_name) {
264 $this->class_name = $class_name;
271 public function getClassName() {
272 return $this->class_name;
const FIELD_TYPE_TIMESTAMP