* Read and parse.
*
* @param $schemaPath
- * @param string $buildVersion which version of the schema to build
+ * @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;
*
* @return array
*/
- function &getDatabase(&$dbXML) {
+ public function &getDatabase(&$dbXML) {
$database = array('name' => trim((string ) $dbXML->name));
$attributes = '';
*
* @return array
*/
- function getTables($dbXML, &$database) {
+ public function getTables($dbXML, &$database) {
$tables = array();
foreach ($dbXML->tables as $tablesXML) {
foreach ($tablesXML->table as $tableXML) {
* @param $tables
* @param string $classNames
*/
- function resolveForeignKeys(&$tables, &$classNames) {
+ public function resolveForeignKeys(&$tables, &$classNames) {
foreach (array_keys($tables) as $name) {
$this->resolveForeignKey($tables, $classNames, $name);
}
* @param string $classNames
* @param string $name
*/
- function resolveForeignKey(&$tables, &$classNames, $name) {
+ public function resolveForeignKey(&$tables, &$classNames, $name) {
if (!array_key_exists('foreignKey', $tables[$name])) {
return;
}
*
* @return array
*/
- function orderTables(&$tables) {
+ public function orderTables(&$tables) {
$ordered = array();
while (!empty($tables)) {
*
* @return bool
*/
- function validTable(&$tables, &$valid, $name) {
+ public function validTable(&$tables, &$valid, $name) {
if (!array_key_exists('foreignKey', $tables[$name])) {
return TRUE;
}
* @param $database
* @param $tables
*/
- function getTable($tableXML, &$database, &$tables) {
+ public function getTable($tableXML, &$database, &$tables) {
$name = trim((string ) $tableXML->name);
$klass = trim((string ) $tableXML->class);
$base = $this->value('base', $tableXML);
* @param $fieldXML
* @param $fields
*/
- function getField(&$fieldXML, &$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);
}
}
*
* @return string
*/
- function composeTitle($name) {
+ public function composeTitle($name) {
$names = explode('_', strtolower($name));
$title = '';
for ($i = 0; $i < count($names); $i++) {
* @param $fields
* @param $table
*/
- function getPrimaryKey(&$primaryXML, &$fields, &$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;
}
* @param $fields
* @param $indices
*/
- function getIndex(&$indexXML, &$fields, &$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)";
}
* @param $foreignKeys
* @param string $currentTableName
*/
- function getForeignKey(&$foreignXML, &$fields, &$foreignKeys, &$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;
}
* @param $foreignXML
* @param $dynamicForeignKeys
*/
- function getDynamicForeignKey(&$foreignXML, &$dynamicForeignKeys) {
+ public function getDynamicForeignKey(&$foreignXML, &$dynamicForeignKeys) {
$foreignKey = array(
'idColumn' => trim($foreignXML->idColumn),
'typeColumn' => trim($foreignXML->typeColumn),