Beispiel #1
0
 /**
  * Outputs the content of a table in NHibernate format
  *
  * @param   string      the database name
  * @param   string      the table name
  * @param   string      the end of line sequence
  * @param   string      the url to go back in case of error
  * @param   string      SQL query for obtaining data
  *
  * @return  bool        Whether it suceeded
  *
  * @access  public
  */
 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
 {
     global $CG_FORMATS, $CG_HANDLERS;
     $format = cgGetOption("format");
     $index = array_search($format, $CG_FORMATS);
     if ($index >= 0) {
         return PMA_exportOutputHandler($CG_HANDLERS[$index]($db, $table, $crlf));
     }
     return PMA_exportOutputHandler(sprintf("%s is not supported.", $format));
 }
 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);
 }
Beispiel #3
0
 /**
  * Outputs the content of a table in NHibernate format
  *
  * @param   string      the database name
  * @param   string      the table name
  * @param   string      the end of line sequence
  * @param   string      the url to go back in case of error
  * @param   string      SQL query for obtaining data
  *
  * @return  bool        Whether it suceeded
  *
  * @access  public
  */
 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
 {
     global $CG_FORMATS, $CG_HANDLERS;
     $format = cgGetOption("format");
     if (isset($CG_FORMATS[$format])) {
         return PMA_exportOutputHandler($CG_HANDLERS[$format]($db, $table, $crlf));
     }
     return PMA_exportOutputHandler(sprintf("%s is not supported.", $format));
 }