ILIAS  trunk Revision v11.0_alpha-1871-gde1fee8db3d
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
arConverter Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for arConverter:

Public Member Functions

 __construct (string $table_name, string $class_name)
 
 readStructure ()
 
 downloadClassFile ()
 
 setTableName (string $table_name)
 
 getTableName ()
 
 setStructure (array $structure)
 
 getStructure ()
 
 addStructure (stdClass $structure)
 
 setClassName (string $class_name)
 
 getClassName ()
 

Static Public Member Functions

static getDB ()
 

Data Fields

const REGEX = "/([a-z]*)\\((\\d*)\\)/u"
 

Protected Member Functions

 returnAttributesForField (stdClass $field)
 

Static Protected Member Functions

static lookupFieldType (string $field_name)
 
static lookupFieldLength (string $field_name)
 

Protected Attributes

string $table_name = ''
 
string $class_name = ''
 
array $structure = []
 
array $ids = []
 

Static Protected Attributes

static array $field_map
 
static array static array $length_map
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class arConverter

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
2.0.7 $arConverter = new arConverter('my_msql_table_name', 'arMyRecordClass'); $arConverter->readStructure(); $arConverter->downloadClassFile();

Definition at line 27 of file class.arConverter.php.

Constructor & Destructor Documentation

◆ __construct()

arConverter::__construct ( string  $table_name,
string  $class_name 
)

Definition at line 53 of file class.arConverter.php.

References readStructure(), setClassName(), and setTableName().

54  {
55  $this->setClassName($class_name);
56  $this->setTableName($table_name);
57  $this->readStructure();
58  }
setTableName(string $table_name)
setClassName(string $class_name)
+ Here is the call graph for this function:

Member Function Documentation

◆ addStructure()

arConverter::addStructure ( stdClass  $structure)

Definition at line 210 of file class.arConverter.php.

References $structure.

Referenced by readStructure().

210  : void
211  {
212  if (!in_array($structure->Field, $this->ids)) {
213  $this->structure[] = $structure;
214  $this->ids[] = $structure->Field;
215  }
216  }
+ Here is the caller graph for this function:

◆ downloadClassFile()

arConverter::downloadClassFile ( )

Definition at line 69 of file class.arConverter.php.

References $txt, exit, getClassName(), getStructure(), getTableName(), ILIAS\UI\examples\Symbol\Glyph\Header\header(), and returnAttributesForField().

69  : void
70  {
71  $header = "<?php
72 require_once('./components/ILIAS/ActiveRecord/class.ActiveRecord.php');
73 
80 class {CLASS_NAME} extends ActiveRecord {
81 
86  static function returnDbTableName() {
87  return '{TABLE_NAME}';
88  }
89 
93  public function getConnectorContainerName() {
94  return '{TABLE_NAME}';
95  }
96 ";
97  $txt = str_replace(
98  ['{CLASS_NAME}', '{TABLE_NAME}'],
99  [$this->getClassName(), $this->getTableName()],
100  $header
101  );
102  $all_members = '';
103  foreach ($this->getStructure() as $str) {
104  $member = "/**
105  * @var {DECLARATION}
106  *\n";
107  foreach ($this->returnAttributesForField($str) as $name => $value) {
108  $member .= ' * @con_' . $name . ' ' . $value . "\n";
109  }
110 
111  $member .= "*/
112  protected \${FIELD_NAME};
113 
114  ";
115 
116  $member = str_replace(['{FIELD_NAME}', '{DECLARATION}'], [$str->Field, ' '], $member);
117 
118  $all_members .= $member;
119  }
120  $txt = $txt . $all_members . '
121 }
122 
123 ?>';
124 
125  // echo '<pre>' . print_r(, 1) . '</pre>';
126 
127  header('Content-type: application/x-httpd-php');
128  header("Content-Disposition: attachment; filename=\"class." . $this->getClassName() . ".php\"");
129  echo $txt;
130  exit;
131  }
returnAttributesForField(stdClass $field)
$txt
Definition: error.php:31
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ getClassName()

arConverter::getClassName ( )

Definition at line 223 of file class.arConverter.php.

References $class_name.

Referenced by downloadClassFile().

223  : string
224  {
225  return $this->class_name;
226  }
+ Here is the caller graph for this function:

◆ getDB()

static arConverter::getDB ( )
static

Definition at line 177 of file class.arConverter.php.

References $DIC.

177  : ilDBInterface
178  {
179  global $DIC;
180 
181  return $DIC['ilDB'];
182  }
global $DIC
Definition: shib_login.php:22

◆ getStructure()

arConverter::getStructure ( )
Returns
mixed[]

Definition at line 205 of file class.arConverter.php.

References $structure.

Referenced by downloadClassFile().

205  : array
206  {
207  return $this->structure;
208  }
+ Here is the caller graph for this function:

◆ getTableName()

arConverter::getTableName ( )

Definition at line 189 of file class.arConverter.php.

References $table_name.

Referenced by downloadClassFile(), and readStructure().

189  : string
190  {
191  return $this->table_name;
192  }
+ Here is the caller graph for this function:

◆ lookupFieldLength()

static arConverter::lookupFieldLength ( string  $field_name)
staticprotected
Returns
mixed|void

Definition at line 164 of file class.arConverter.php.

165  {
166  $field_type = self::lookupFieldType($field_name);
167 
168  preg_match(self::REGEX, $field_name, $matches);
169 
170  if (self::$length_map[$field_type][$matches[2]]) {
171  return self::$length_map[$field_type][$matches[2]];
172  }
173 
174  return $matches[2];
175  }

◆ lookupFieldType()

static arConverter::lookupFieldType ( string  $field_name)
staticprotected

Definition at line 154 of file class.arConverter.php.

154  : string
155  {
156  preg_match(self::REGEX, $field_name, $matches);
157 
158  return self::$field_map[$matches[1]];
159  }

◆ readStructure()

arConverter::readStructure ( )

Definition at line 60 of file class.arConverter.php.

References $data, addStructure(), and getTableName().

Referenced by __construct().

60  : void
61  {
62  $sql = 'DESCRIBE ' . $this->getTableName();
63  $ilDBStatement = self::getDB()->query($sql);
64  while ($data = self::getDB()->fetchObject($ilDBStatement)) {
65  $this->addStructure($data);
66  }
67  }
addStructure(stdClass $structure)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ returnAttributesForField()

arConverter::returnAttributesForField ( stdClass  $field)
protected
Returns
array{has_field: string, fieldtype: string, length: mixed, is_notnull?: string, is_primary?: string}

Definition at line 136 of file class.arConverter.php.

References arFieldList\FIELDTYPE, arFieldList\HAS_FIELD, arFieldList\IS_NOTNULL, arFieldList\IS_PRIMARY, and arFieldList\LENGTH.

Referenced by downloadClassFile().

136  : array
137  {
138  $attributes = [];
139  $attributes[arFieldList::HAS_FIELD] = 'true';
140  $attributes[arFieldList::FIELDTYPE] = self::lookupFieldType($field->Type);
141  $attributes[arFieldList::LENGTH] = self::lookupFieldLength($field->Type);
142 
143  if ($field->Null === 'NO') {
144  $attributes[arFieldList::IS_NOTNULL] = 'true';
145  }
146 
147  if ($field->Key === 'PRI') {
148  $attributes[arFieldList::IS_PRIMARY] = 'true';
149  }
150 
151  return $attributes;
152  }
+ Here is the caller graph for this function:

◆ setClassName()

arConverter::setClassName ( string  $class_name)

Definition at line 218 of file class.arConverter.php.

References $class_name.

Referenced by __construct().

218  : void
219  {
220  $this->class_name = $class_name;
221  }
+ Here is the caller graph for this function:

◆ setStructure()

arConverter::setStructure ( array  $structure)
Parameters
mixed[]$structure

Definition at line 197 of file class.arConverter.php.

References $structure.

197  : void
198  {
199  $this->structure = $structure;
200  }

◆ setTableName()

arConverter::setTableName ( string  $table_name)

Definition at line 184 of file class.arConverter.php.

References $table_name.

Referenced by __construct().

184  : void
185  {
186  $this->table_name = $table_name;
187  }
+ Here is the caller graph for this function:

Field Documentation

◆ $class_name

string arConverter::$class_name = ''
protected

Definition at line 49 of file class.arConverter.php.

Referenced by getClassName(), and setClassName().

◆ $field_map

array arConverter::$field_map
staticprotected
Initial value:
= [

Definition at line 30 of file class.arConverter.php.

◆ $ids

array arConverter::$ids = []
protected

Definition at line 51 of file class.arConverter.php.

◆ $length_map

array static array arConverter::$length_map
staticprotected
Initial value:

Definition at line 39 of file class.arConverter.php.

◆ $structure

array arConverter::$structure = []
protected

Definition at line 50 of file class.arConverter.php.

Referenced by addStructure(), getStructure(), and setStructure().

◆ $table_name

string arConverter::$table_name = ''
protected

Definition at line 48 of file class.arConverter.php.

Referenced by getTableName(), and setTableName().

◆ REGEX

const arConverter::REGEX = "/([a-z]*)\\((\\d*)\\)/u"

Definition at line 29 of file class.arConverter.php.


The documentation for this class was generated from the following file: