29 public const REGEX =
"/([a-z]*)\\((\\d*)\\)/u";
30 protected static array $field_map = [
39 protected static array $length_map = [
48 protected string $table_name =
'';
49 protected string $class_name =
'';
51 protected array $ids = [];
53 public function __construct(
string $table_name,
string $class_name)
55 $this->setClassName($class_name);
56 $this->setTableName($table_name);
57 $this->readStructure();
60 public function readStructure(): void
62 $sql =
'DESCRIBE ' . $this->getTableName();
63 $ilDBStatement = self::getDB()->query($sql);
64 while (
$data = self::getDB()->fetchObject($ilDBStatement)) {
65 $this->addStructure(
$data);
69 public function downloadClassFile(): void
72require_once('./components/ILIAS/ActiveRecord/class.ActiveRecord.php');
80class {CLASS_NAME} extends ActiveRecord {
86 static function returnDbTableName() {
87 return '{TABLE_NAME}';
93 public function getConnectorContainerName() {
94 return '{TABLE_NAME}';
98 [
'{CLASS_NAME}',
'{TABLE_NAME}'],
99 [$this->getClassName(), $this->getTableName()],
103 foreach ($this->getStructure() as $str) {
107 foreach ($this->returnAttributesForField($str) as $name => $value) {
108 $member .=
' * @con_' . $name .
' ' . $value .
"\n";
112 protected \${FIELD_NAME};
116 $member = str_replace([
'{FIELD_NAME}',
'{DECLARATION}'], [$str->Field,
' '], $member);
118 $all_members .= $member;
127 header(
'Content-type: application/x-httpd-php');
128 header(
"Content-Disposition: attachment; filename=\"class." . $this->getClassName() .
".php\"");
136 protected function returnAttributesForField(stdClass $field): array
143 if ($field->Null ===
'NO') {
147 if ($field->Key ===
'PRI') {
154 protected static function lookupFieldType(
string $field_name): string
156 preg_match(self::REGEX, $field_name, $matches);
158 return self::$field_map[$matches[1]];
164 protected static function lookupFieldLength(
string $field_name)
166 $field_type = self::lookupFieldType($field_name);
168 preg_match(self::REGEX, $field_name, $matches);
170 if (self::$length_map[$field_type][$matches[2]]) {
171 return self::$length_map[$field_type][$matches[2]];
184 public function setTableName(
string $table_name): void
186 $this->table_name = $table_name;
189 public function getTableName(): string
191 return $this->table_name;
197 public function setStructure(array
$structure): void
205 public function getStructure(): array
210 public function addStructure(stdClass
$structure): void
212 if (!in_array(
$structure->Field, $this->ids)) {
218 public function setClassName(
string $class_name): void
220 $this->class_name = $class_name;
223 public function getClassName(): string
225 return $this->class_name;
$structure
TOTAL STRUCTURE.
const FIELD_TYPE_TIMESTAMP
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc