/**
* Read and parse.
*
- * @param string $buildVersion which version of the schema to build
+ * @param $schemaPath
+ * @param string $buildVersion
+ * Which version of the schema to build.
*/
- function parse($schemaPath, $buildVersion) {
+ public function parse($schemaPath, $buildVersion) {
$this->buildVersion = $buildVersion;
- echo "Parsing schema description ".$schemaPath."\n";
+ echo "Parsing schema description " . $schemaPath . "\n";
$dbXML = CRM_Core_CodeGen_Util_Xml::parse($schemaPath);
// print_r( $dbXML );
$this->tables = $this->orderTables($this->tables);
// add archive tables here
- $archiveTables = array( );
- foreach ($this->tables as $name => $table ) {
- if ( $table['archive'] == 'true' ) {
+ $archiveTables = array();
+ foreach ($this->tables as $name => $table) {
+ if ($table['archive'] == 'true') {
$name = 'archive_' . $table['name'];
$table['name'] = $name;
$table['archive'] = 'false';
- if ( isset($table['foreignKey']) ) {
+ if (isset($table['foreignKey'])) {
foreach ($table['foreignKey'] as $fkName => $fkValue) {
if ($this->tables[$fkValue['table']]['archive'] == 'true') {
$table['foreignKey'][$fkName]['table'] = 'archive_' . $table['foreignKey'][$fkName]['table'];
$table['foreignKey'][$fkName]['uniqName'] =
- str_replace( 'FK_', 'FK_archive_', $table['foreignKey'][$fkName]['uniqName'] );
+ str_replace('FK_', 'FK_archive_', $table['foreignKey'][$fkName]['uniqName']);
}
}
$archiveTables[$name] = $table;
}
}
- function &getDatabase(&$dbXML) {
+ /**
+ * @param $dbXML
+ *
+ * @return array
+ */
+ public function &getDatabase(&$dbXML) {
$database = array('name' => trim((string ) $dbXML->name));
$attributes = '';
return $database;
}
- function getTables($dbXML, &$database) {
+ /**
+ * @param $dbXML
+ * @param $database
+ *
+ * @return array
+ */
+ public function getTables($dbXML, &$database) {
$tables = array();
foreach ($dbXML->tables as $tablesXML) {
foreach ($tablesXML->table as $tableXML) {
return $tables;
}
- function resolveForeignKeys(&$tables, &$classNames) {
+ /**
+ * @param $tables
+ * @param string $classNames
+ */
+ public function resolveForeignKeys(&$tables, &$classNames) {
foreach (array_keys($tables) as $name) {
$this->resolveForeignKey($tables, $classNames, $name);
}
}
- function resolveForeignKey(&$tables, &$classNames, $name) {
+ /**
+ * @param $tables
+ * @param string $classNames
+ * @param string $name
+ */
+ public function resolveForeignKey(&$tables, &$classNames, $name) {
if (!array_key_exists('foreignKey', $tables[$name])) {
return;
}
}
}
- function orderTables(&$tables) {
+ /**
+ * @param $tables
+ *
+ * @return array
+ */
+ public function orderTables(&$tables) {
$ordered = array();
while (!empty($tables)) {
return $ordered;
}
- function validTable(&$tables, &$valid, $name) {
+ /**
+ * @param $tables
+ * @param int $valid
+ * @param string $name
+ *
+ * @return bool
+ */
+ public function validTable(&$tables, &$valid, $name) {
if (!array_key_exists('foreignKey', $tables[$name])) {
return TRUE;
}
return TRUE;
}
- function getTable($tableXML, &$database, &$tables) {
+ /**
+ * @param $tableXML
+ * @param $database
+ * @param $tables
+ */
+ public function getTable($tableXML, &$database, &$tables) {
$name = trim((string ) $tableXML->name);
$klass = trim((string ) $tableXML->class);
$base = $this->value('base', $tableXML);
return;
}
- function getField(&$fieldXML, &$fields) {
+ /**
+ * @param $fieldXML
+ * @param $fields
+ */
+ public function getField(&$fieldXML, &$fields) {
$name = trim((string ) $fieldXML->name);
$field = array('name' => $name, 'localizable' => $fieldXML->localizable);
$type = (string ) $fieldXML->type;
$field['rows'] = isset($fieldXML->html) ? $this->value('rows', $fieldXML->html) : NULL;
$field['cols'] = isset($fieldXML->html) ? $this->value('cols', $fieldXML->html) : NULL;
break;
- break;
+
+ break;
case 'datetime':
$field['sqlType'] = $field['phpType'] = $type;
);
$field['html'] = array();
foreach ($validOptions as $htmlOption) {
- if(!empty($fieldXML->html->$htmlOption)){
+ if (!empty($fieldXML->html->$htmlOption)) {
$field['html'][$htmlOption] = $this->value($htmlOption, $fieldXML->html);
}
}
}
$field['pseudoconstant'] = $this->value('pseudoconstant', $fieldXML);
- if(!empty($field['pseudoconstant'])){
+ if (!empty($field['pseudoconstant'])) {
//ok this is a bit long-winded but it gets there & is consistent with above approach
$field['pseudoconstant'] = array();
$validOptions = array(
'callback',
);
foreach ($validOptions as $pseudoOption) {
- if(!empty($fieldXML->pseudoconstant->$pseudoOption)){
+ if (!empty($fieldXML->pseudoconstant->$pseudoOption)) {
$field['pseudoconstant'][$pseudoOption] = $this->value($pseudoOption, $fieldXML->pseudoconstant);
}
}
$fields[$name] = &$field;
}
- function composeTitle($name) {
+ /**
+ * @param string $name
+ *
+ * @return string
+ */
+ public function composeTitle($name) {
$names = explode('_', strtolower($name));
$title = '';
for ($i = 0; $i < count($names); $i++) {
return trim($title);
}
- function getPrimaryKey(&$primaryXML, &$fields, &$table) {
+ /**
+ * @param $primaryXML
+ * @param $fields
+ * @param $table
+ */
+ public function getPrimaryKey(&$primaryXML, &$fields, &$table) {
$name = trim((string ) $primaryXML->name);
/** need to make sure there is a field of type name */
if (!array_key_exists($name, $fields)) {
- echo "primary key $name in $table->name does not have a field definition, ignoring\n";
+ echo "primary key $name in $table->name does not have a field definition, ignoring\n";
return;
}
$table['primaryKey'] = &$primaryKey;
}
- function getIndex(&$indexXML, &$fields, &$indices) {
+ /**
+ * @param $indexXML
+ * @param $fields
+ * @param $indices
+ */
+ public function getIndex(&$indexXML, &$fields, &$indices) {
//echo "\n\n*******************************************************\n";
//echo "entering getIndex\n";
$index = array();
// empty index name is fine
- $indexName = trim((string)$indexXML->name);
+ $indexName = trim((string) $indexXML->name);
$index['name'] = $indexName;
$index['field'] = array();
// populate fields
foreach ($indexXML->fieldName as $v) {
- $fieldName = (string)($v);
- $length = (string)($v['length']);
+ $fieldName = (string) ($v);
+ $length = (string) ($v['length']);
if (strlen($length) > 0) {
$fieldName = "$fieldName($length)";
}
$indices[$indexName] = &$index;
}
- function getForeignKey(&$foreignXML, &$fields, &$foreignKeys, &$currentTableName) {
+ /**
+ * @param $foreignXML
+ * @param $fields
+ * @param $foreignKeys
+ * @param string $currentTableName
+ */
+ public function getForeignKey(&$foreignXML, &$fields, &$foreignKeys, &$currentTableName) {
$name = trim((string ) $foreignXML->name);
/** need to make sure there is a field of type name */
if (!array_key_exists($name, $fields)) {
- echo "foreign $name in $currentTableName does not have a field definition, ignoring\n";
+ echo "foreign $name in $currentTableName does not have a field definition, ignoring\n";
return;
}
$foreignKeys[$name] = &$foreignKey;
}
- function getDynamicForeignKey(&$foreignXML, &$dynamicForeignKeys) {
+ /**
+ * @param $foreignXML
+ * @param $dynamicForeignKeys
+ */
+ public function getDynamicForeignKey(&$foreignXML, &$dynamicForeignKeys) {
$foreignKey = array(
'idColumn' => trim($foreignXML->idColumn),
'typeColumn' => trim($foreignXML->typeColumn),
$dynamicForeignKeys[] = $foreignKey;
}
+ /**
+ * @param $key
+ * @param $object
+ * @param null $default
+ *
+ * @return null|string
+ */
protected function value($key, &$object, $default = NULL) {
if (isset($object->$key)) {
return (string ) $object->$key;
return $default;
}
+ /**
+ * @param $attributes
+ * @param $object
+ * @param string $name
+ * @param null $pre
+ * @param null $post
+ */
protected function checkAndAppend(&$attributes, &$object, $name, $pre = NULL, $post = NULL) {
if (!isset($object->$name)) {
return;
$this->append($attributes, ' ', trim($value));
}
+ /**
+ * @param $str
+ * @param $delim
+ * @param $name
+ */
protected function append(&$str, $delim, $name) {
if (empty($name)) {
return;