ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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().

69  {
70  $this->setClassName($class_name);
71  $this->setTableName($table_name);
72  $this->readStructure();
73  }
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 261 of file class.arConverter.php.

References $structure.

Referenced by readStructure().

262  {
263  if (!in_array($structure->field, $this->ids)) {
264  $this->structure[] = $structure;
265  $this->ids[] = $structure->field;
266  }
267  }
+ Here is the caller graph for this function:

◆ downloadClassFile()

arConverter::downloadClassFile ( )

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

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

87  {
88  $header = "<?php
89 require_once('./Services/ActiveRecord/class.ActiveRecord.php');
90 
97 class {CLASS_NAME} extends ActiveRecord {
98 
103  static function returnDbTableName() {
104  return '{TABLE_NAME}';
105  }
106 
110  public function getConnectorContainerName() {
111  return '{TABLE_NAME}';
112  }
113 ";
114  $txt = str_replace('{CLASS_NAME}', $this->getClassName(), $header);
115  $txt = str_replace('{TABLE_NAME}', $this->getTableName(), $txt);
116  $all_members = '';
117  foreach ($this->getStructure() as $str) {
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)
if($format !==null) $name
Definition: metadata.php:146
Add a drawing to the header
Definition: 04printing.php:69
$txt
Definition: error.php:11
+ Here is the call graph for this function:

◆ getClassName()

arConverter::getClassName ( )
Returns
string

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

References $class_name.

Referenced by downloadClassFile().

283  {
284  return $this->class_name;
285  }
+ Here is the caller graph for this function:

◆ getStructure()

arConverter::getStructure ( )
Returns
array

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

References $structure.

Referenced by downloadClassFile().

253  {
254  return $this->structure;
255  }
+ Here is the caller graph for this function:

◆ getTableName()

arConverter::getTableName ( )
Returns
string

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

References $table_name.

Referenced by downloadClassFile(), and readStructure().

235  {
236  return $this->table_name;
237  }
+ Here is the caller graph for this function:

◆ lookupFieldLength()

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

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

References $DIC, and $ilDB.

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

◆ lookupFieldType()

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

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

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

◆ readStructure()

arConverter::readStructure ( )

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

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

Referenced by __construct().

77  {
78  $sql = 'DESCRIBE ' . $this->getTableName();
79  $res = self::getDB()->query($sql);
80  while ($data = self::getDB()->fetchObject($res)) {
81  $this->addStructure($data);
82  }
83  }
foreach($_POST as $key=> $value) $res
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 $attributes, array, arFieldList\FIELDTYPE, arFieldList\HAS_FIELD, arFieldList\IS_NOTNULL, arFieldList\IS_PRIMARY, arFieldList\IS_UNIQUE, and arFieldList\LENGTH.

Referenced by downloadClassFile().

155  {
156  $attributes = array();
158  $attributes[arFieldList::FIELDTYPE] = self::lookupFieldType($field->type);
159  $attributes[arFieldList::LENGTH] = self::lookupFieldLength($field->type);
160 
161  if ($field->null == 'NO') {
163  }
164 
165  if ($field->key == 'PRI') {
168  }
169 
170  return $attributes;
171  }
$attributes
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 273 of file class.arConverter.php.

References $class_name.

Referenced by __construct().

274  {
275  $this->class_name = $class_name;
276  }
+ Here is the caller graph for this function:

◆ setStructure()

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

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

References $structure.

244  {
245  $this->structure = $structure;
246  }

◆ setTableName()

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

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

References $table_name.

Referenced by __construct().

226  {
227  $this->table_name = $table_name;
228  }
+ 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: