ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
arConverter Class Reference

Class arConverter. More...

+ Collaboration diagram for arConverter:

Public Member Functions

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

Data Fields

const REGEX = "/([a-z]*)\\(([0-9]*)\\)/us"
 

Protected Member Functions

 returnAttributesForField (stdClass $field)
 

Static Protected Member Functions

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

Protected Attributes

 $table_name = ''
 
 $class_name = ''
 
 $structure = array()
 
 $ids = array()
 

Static Protected Attributes

static $field_map
 
static $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 16 of file class.arConverter.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

References $class_name, $table_name, readStructure(), setClassName(), and setTableName().

68  {
69  $this->setClassName($class_name);
70  $this->setTableName($table_name);
71  $this->readStructure();
72  }
setTableName($table_name)
setClassName($class_name)
+ Here is the call graph for this function:

Member Function Documentation

◆ addStructure()

arConverter::addStructure ( stdClass  $structure)
Parameters
stdClass$structure

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

References $structure.

Referenced by readStructure().

252  {
253  if(!in_array($structure->field, $this->ids)) {
254  $this->structure[] = $structure;
255  $this->ids[] = $structure->field;
256  }
257  }
+ Here is the caller graph for this function:

◆ downloadClassFile()

arConverter::downloadClassFile ( )

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

References $header, $txt, exit, getClassName(), getStructure(), getTableName(), header, and returnAttributesForField().

84  {
85 
86 
87  $header = "<?php
88 require_once('./Services/ActiveRecord/class.ActiveRecord.php');
89 
96 class {CLASS_NAME} extends ActiveRecord {
97 
102  static function returnDbTableName() {
103  return '{TABLE_NAME}';
104  }
105 
109  public function getConnectorContainerName() {
110  return '{TABLE_NAME}';
111  }
112 ";
113  $txt = str_replace('{CLASS_NAME}', $this->getClassName(), $header);
114  $txt = str_replace('{TABLE_NAME}', $this->getTableName(), $txt);
115  $all_members = '';
116  foreach ($this->getStructure() as $str) {
117 
118  $member = "/**
119  * @var {DECLARATION}
120  *\n";
121  foreach ($this->returnAttributesForField($str) as $name => $value) {
122  $member .= ' * @con_' . $name . ' ' . $value . "\n";
123  }
124 
125  $member .= "*/
126  protected \${FIELD_NAME};
127 
128  ";
129 
130  $member = str_replace('{FIELD_NAME}', $str->field, $member);
131  $member = str_replace('{DECLARATION}', ' ', $member);
132 
133  $all_members .= $member;
134  }
135  $txt = $txt . $all_members . '
136 }
137 
138 ?>';
139 
140  // echo '<pre>' . print_r(, 1) . '</pre>';
141 
142  header('Content-type: application/x-httpd-php');
143  header("Content-Disposition: attachment; filename=\"class." . $this->getClassName() . ".php\"");
144  echo $txt;
145  exit;
146  }
returnAttributesForField(stdClass $field)
$header
Add a drawing to the header
Definition: 04printing.php:69
$txt
Definition: error.php:12
+ Here is the call graph for this function:

◆ getClassName()

arConverter::getClassName ( )
Returns
string

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

References $class_name.

Referenced by downloadClassFile().

271  {
272  return $this->class_name;
273  }
+ Here is the caller graph for this function:

◆ getStructure()

arConverter::getStructure ( )
Returns
array

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

References $structure.

Referenced by downloadClassFile().

244  {
245  return $this->structure;
246  }
+ Here is the caller graph for this function:

◆ getTableName()

arConverter::getTableName ( )
Returns
string

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

References $table_name.

Referenced by downloadClassFile(), and readStructure().

228  {
229  return $this->table_name;
230  }
+ Here is the caller graph for this function:

◆ lookupFieldLength()

static arConverter::lookupFieldLength (   $string)
staticprotected
Parameters
$string
Returns
string

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

References $ilDB.

190  {
191  $field_type = self::lookupFieldType($string);
192 
193  preg_match(self::REGEX, $string, $matches);
194 
195  if (self::$length_map[$field_type][$matches[2]]) {
196  return self::$length_map[$field_type][$matches[2]];
197  } else {
198  return $matches[2];
199  }
200  }

◆ lookupFieldType()

static arConverter::lookupFieldType (   $string)
staticprotected
Parameters
$string
Returns
string

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

178  {
179  preg_match(self::REGEX, $string, $matches);
180 
181  return self::$field_map[$matches[1]];
182  }

◆ readStructure()

arConverter::readStructure ( )

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

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

Referenced by __construct().

75  {
76  $sql = 'DESCRIBE ' . $this->getTableName();
77  $res = self::getDB()->query($sql);
78  while ($data = self::getDB()->fetchObject($res)) {
79  $this->addStructure($data);
80  }
81  }
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
Parameters
stdClass$field
Returns
array

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

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

Referenced by downloadClassFile().

154  {
155  $attributes = array();
156  $attributes[arFieldList::HAS_FIELD] = 'true';
157  $attributes[arFieldList::FIELDTYPE] = self::lookupFieldType($field->type);
158  $attributes[arFieldList::LENGTH] = self::lookupFieldLength($field->type);
159 
160  if ($field->null == 'NO') {
161  $attributes[arFieldList::IS_NOTNULL] = 'true';
162  }
163 
164  if ($field->key == 'PRI') {
165  $attributes[arFieldList::IS_PRIMARY] = 'true';
166  $attributes[arFieldList::IS_UNIQUE] = 'true';
167  }
168 
169  return $attributes;
170  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ setClassName()

arConverter::setClassName (   $class_name)
Parameters
string$class_name

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

References $class_name.

Referenced by __construct().

263  {
264  $this->class_name = $class_name;
265  }
+ Here is the caller graph for this function:

◆ setStructure()

arConverter::setStructure (   $structure)
Parameters
array$structure

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

References $structure.

236  {
237  $this->structure = $structure;
238  }

◆ setTableName()

arConverter::setTableName (   $table_name)
Parameters
string$table_name

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

References $table_name.

Referenced by __construct().

220  {
221  $this->table_name = $table_name;
222  }
+ Here is the caller graph for this function:

Field Documentation

◆ $class_name

arConverter::$class_name = ''
protected

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

Referenced by __construct(), getClassName(), and setClassName().

◆ $field_map

arConverter::$field_map
staticprotected
Initial value:

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

◆ $ids

arConverter::$ids = array()
protected

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

◆ $length_map

arConverter::$length_map
staticprotected
Initial value:

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

◆ $structure

arConverter::$structure = array()
protected

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

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

◆ $table_name

arConverter::$table_name = ''
protected

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

Referenced by __construct(), getTableName(), and setTableName().

◆ REGEX

const arConverter::REGEX = "/([a-z]*)\\(([0-9]*)\\)/us"

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


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