function handleDoctrine2PHPBody($db, $table, $crlf) { global $YAML_dataTypes; $lines = array(); /* * Doctrine offers the ability to specify schema in an abbreviated syntax. * * If verbose is set to false, a lot of the schema parameters have values they default to, * this allows us to abbreviate the syntax and let Doctrine just use its defaults. * * If verbose is set to true ALL schema parameters will be included. This is recomended! */ $useVerboseSyntax = cgGetOption('verbose'); /* * Show Table relations in header */ $showIndexes = cgGetOption('index'); // create schema $YAML_dataTypes = createYAML_dataTypeSchema(); // get table info $sqlQuery = "SELECT * FROM information_schema.columns WHERE TABLE_SCHEMA = '{$db}' AND TABLE_NAME = '{$table}'"; $result = PMA_DBI_query($sqlQuery); // get table relations $sqlQuery = "SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = '{$db}' AND TABLE_NAME = '{$table}'"; $result_rel = PMA_DBI_query($sqlQuery); $tableRelations = array(); while ($row = PMA_DBI_fetch_assoc($result_rel)) { $tableRelations[] = $row; $referencedTable = $row["REFERENCED_TABLE_NAME"]; $referencedTableClass = toCamelCase($referencedTable, true); } // build header if (!$useVerboseSyntax) { // $lines[] = "detect_relations: true\n"; } // build body if ($result) { $tableProperties = array(); while ($row = PMA_DBI_fetch_assoc($result)) { $tableProperties[] = new TableProperty($row); //$lines[] = print_r($row); } // insert table Class Headers $lines[] = "<?php\n"; $lines[] = "namespace models;"; $str = "\n/**\n * @Entity\n * @Table(name=\"" . $table . "\""; // insert table indexes if ($showIndexes) { $tableIndexes = new TableIndexes($db, $table); $indexes = $tableIndexes->getIndexes(true); if (count($indexes) > 0) { $indexCount = 0; $indexDeliminator = ''; $str .= ", indexes={"; foreach ($indexes as $index) { $columnsCount = 0; $columnDeliminator = ''; if ($indexCount > 0) { $indexDeliminator = ', '; } $str .= $indexDeliminator . "@index(name=\"" . $index->name->schemaVal . "\", columns={"; foreach ($index->columns->schemaVal as $col) { if ($columnsCount > 0) { $columnDeliminator = ', '; } $str .= $columnDeliminator . "\"" . $col . "\""; $columnsCount++; } $str .= "})"; $indexCount++; } $str .= "}"; } } $str .= ")\n */\n"; $lines[] = $str; // insert class name $lines[] = "class " . toCamelCase($table, true) . " {\n\n\n"; foreach ($tableProperties as $tablePropertie) { //insert metadata $lines[] = " " . $tablePropertie->insertMetadata($useVerboseSyntax); //insert property $propName = toCamelCase($tablePropertie->fields->name->schemaVal); $lines[] = "\tprivate \$" . $propName . ";\n"; } // insert relations $sqlQuery = "SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = '{$db}' AND TABLE_NAME = '{$table}'"; $result2 = PMA_DBI_query($sqlQuery); while ($row = PMA_DBI_fetch_assoc($result2)) { $referencedTable = $row["REFERENCED_TABLE_NAME"]; $referencedTableClass = toCamelCase($referencedTable, true); if ($referencedTable) { $lines[] = "\t/**"; $lines[] = "\t * @OneToOne(targetEntity=\"" . $referencedTableClass . "\")"; $lines[] = "\t */"; $lines[] = "\tprivate \$" . $referencedTable . ";\n"; } } // insert getters / setters $lines[] = "\n"; foreach ($tableProperties as $tablePropertie) { $functname = toCamelCase($tablePropertie->fields->name->schemaVal, true); $propName = toCamelCase($tablePropertie->fields->name->schemaVal); $lines[] = "\tpublic function get" . $functname . "() \n\t{\n\t\treturn \$this->" . $propName . ";\n\t} \n"; $lines[] = "\tpublic function set" . $functname . "(\$" . $propName . ") \n\t{\n\t\t\$this->" . $propName . " = \$" . $propName . ";\n\t} \n"; } $lines[] = "}\n?>\n\n"; PMA_DBI_free_result($result); } return implode("\n", $lines); }
function handleDoctrineBody($db, $table, $crlf) { global $YAML_dataTypes; $lines = array(); /* * Doctrine offers the ability to specify schema in an abbreviated syntax. * * If verbose is set to false, a lot of the schema parameters have values they default to, * this allows us to abbreviate the syntax and let Doctrine just use its defaults. * * If verbose is set to true ALL schema parameters will be included. This is recomended! */ $useVerboseSyntax = true; // create schema $YAML_dataTypes = createYAML_dataTypeSchema(); // build header if (!$useVerboseSyntax) { // $lines[] = "detect_relations: true\n"; } // build body $sqlQuery = "SELECT * FROM information_schema.columns WHERE TABLE_SCHEMA = '{$db}' AND TABLE_NAME = '{$table}'"; $result = PMA_DBI_query($sqlQuery); if ($result) { $tableProperties = array(); while ($rowObj = PMA_DBI_fetch_assoc($result)) { $tableProperties[] = new TableProperty($rowObj); // $lines[] = print_r($rowObj); } // insert table Class name $tableClass = toCamelCase($table, true); $lines[] = $tableClass . ":"; // insert table name $lines[] = " tableName: " . $table; //insert columns $lines[] = " options:\n type: INNODB\n"; // insert columns $lines[] = " columns:"; foreach ($tableProperties as $tablePropertie) { // $lines[] = print_r($tablePropertie); $lines[] = " " . $tablePropertie->insertColumn($useVerboseSyntax); } $lines[] = "\n"; if ($useVerboseSyntax) { // DO relations here } PMA_DBI_free_result($result); } return implode("\n", $lines); }