ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
arConverter Class Reference

Class arConverter. 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]*)\\(([0-9]*)\\)/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()
 
array $ids = array()
 

Static Protected Attributes

static array $field_map
 
static array $length_map
 

Detailed Description

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 24 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 $name, $txt, exit, getClassName(), getStructure(), getTableName(), and returnAttributesForField().

69  : void
70  {
71  $header = "<?php
72 require_once('./Services/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  }
exit
Definition: login.php:28
returnAttributesForField(stdClass $field)
if($format !==null) $name
Definition: metadata.php:247
$txt
Definition: error.php:13
+ 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: feed.php:28

◆ 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, $res, addStructure(), and getTableName().

Referenced by __construct().

60  : void
61  {
62  $sql = 'DESCRIBE ' . $this->getTableName();
63  $res = self::getDB()->query($sql);
64  while ($data = self::getDB()->fetchObject($res)) {
65  $this->addStructure($data);
66  }
67  }
$res
Definition: ltiservices.php:69
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<string, string>

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

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

Referenced by downloadClassFile().

136  : array
137  {
138  $attributes = array();
140  $attributes[arFieldList::FIELDTYPE] = self::lookupFieldType($field->Type);
141  $attributes[arFieldList::LENGTH] = self::lookupFieldLength($field->Type);
142 
143  if ($field->Null === 'NO') {
145  }
146 
147  if ($field->Key === 'PRI') {
149  }
150 
151  return $attributes;
152  }
$attributes
Definition: metadata.php:248
+ 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 27 of file class.arConverter.php.

◆ $ids

array arConverter::$ids = array()
protected

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

◆ $length_map

array arConverter::$length_map
staticprotected
Initial value:

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

◆ $structure

array arConverter::$structure = array()
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]*)\\(([0-9]*)\\)/u"

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


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