ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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

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().

+ Here is the call graph for this function:

Member Function Documentation

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

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

References $structure.

Referenced by readStructure().

{
if(!in_array($structure->field, $this->ids)) {
$this->structure[] = $structure;
$this->ids[] = $structure->field;
}
}

+ Here is the caller graph for this function:

arConverter::downloadClassFile ( )

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

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

{
$header = "<?php
require_once('./Services/ActiveRecord/class.ActiveRecord.php');
class {CLASS_NAME} extends ActiveRecord {
static function returnDbTableName() {
return '{TABLE_NAME}';
}
public function getConnectorContainerName() {
return '{TABLE_NAME}';
}
";
$txt = str_replace('{CLASS_NAME}', $this->getClassName(), $header);
$txt = str_replace('{TABLE_NAME}', $this->getTableName(), $txt);
$all_members = '';
foreach ($this->getStructure() as $str) {
$member = "/**
* @var {DECLARATION}
*\n";
foreach ($this->returnAttributesForField($str) as $name => $value) {
$member .= ' * @con_' . $name . ' ' . $value . "\n";
}
$member .= "*/
protected \${FIELD_NAME};
";
$member = str_replace('{FIELD_NAME}', $str->field, $member);
$member = str_replace('{DECLARATION}', ' ', $member);
$all_members .= $member;
}
$txt = $txt . $all_members . '
}
?>';
// echo '<pre>' . print_r(, 1) . '</pre>';
header('Content-type: application/x-httpd-php');
header("Content-Disposition: attachment; filename=\"class." . $this->getClassName() . ".php\"");
echo $txt;
}

+ Here is the call graph for this function:

arConverter::getClassName ( )
Returns
string

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

References $class_name.

Referenced by downloadClassFile().

{
}

+ Here is the caller graph for this function:

arConverter::getStructure ( )
Returns
array

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

References $structure.

Referenced by downloadClassFile().

{
}

+ Here is the caller graph for this function:

arConverter::getTableName ( )
Returns
string

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

References $table_name.

Referenced by downloadClassFile(), and readStructure().

{
}

+ Here is the caller graph for this function:

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

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

References lookupFieldType().

Referenced by returnAttributesForField().

{
$field_type = self::lookupFieldType($string);
preg_match(self::REGEX, $string, $matches);
if (self::$length_map[$field_type][$matches[2]]) {
return self::$length_map[$field_type][$matches[2]];
} else {
return $matches[2];
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

Referenced by lookupFieldLength(), and returnAttributesForField().

{
preg_match(self::REGEX, $string, $matches);
return self::$field_map[$matches[1]];
}

+ Here is the caller graph for this function:

arConverter::readStructure ( )

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

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

Referenced by __construct().

{
$sql = 'DESCRIBE ' . $this->getTableName();
$res = self::getDB()->query($sql);
while ($data = self::getDB()->fetchObject($res)) {
$this->addStructure($data);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

arConverter::returnAttributesForField ( stdClass  $field)
protected
Parameters
stdClass$field
Returns
array

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

References arFieldList\FIELDTYPE, arFieldList\HAS_FIELD, arFieldList\IS_NOTNULL, arFieldList\IS_PRIMARY, arFieldList\IS_UNIQUE, arFieldList\LENGTH, lookupFieldLength(), and lookupFieldType().

Referenced by downloadClassFile().

{
$attributes = array();
$attributes[arFieldList::HAS_FIELD] = 'true';
$attributes[arFieldList::FIELDTYPE] = self::lookupFieldType($field->type);
$attributes[arFieldList::LENGTH] = self::lookupFieldLength($field->type);
if ($field->null == 'NO') {
$attributes[arFieldList::IS_NOTNULL] = 'true';
}
if ($field->key == 'PRI') {
$attributes[arFieldList::IS_PRIMARY] = 'true';
$attributes[arFieldList::IS_UNIQUE] = 'true';
}
return $attributes;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

References $class_name.

Referenced by __construct().

{
$this->class_name = $class_name;
}

+ Here is the caller graph for this function:

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

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

References $structure.

{
$this->structure = $structure;
}
arConverter::setTableName (   $table_name)
Parameters
string$table_name

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

References $table_name.

Referenced by __construct().

{
$this->table_name = $table_name;
}

+ Here is the caller graph for this function:

Field Documentation

arConverter::$class_name = ''
protected

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

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

arConverter::$field_map
staticprotected
Initial value:

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

arConverter::$ids = array()
protected

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

arConverter::$length_map
staticprotected
Initial value:

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

arConverter::$structure = array()
protected

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

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

arConverter::$table_name = ''
protected

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

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

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: