Example #1
0
 public function run($table, $class, $path, $overwriteModel = false)
 {
     $this->className .= $class;
     $this->tableName = $table;
     $this->path = $path;
     $query = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$this->tableName}' AND table_schema = '" . $this->databaseName . "'";
     $result = mysql_query($query);
     if (mysql_num_rows($result) == 0) {
         echo "<span style='color:red'>Table does not exist</span><br/><br/>";
         return;
     }
     $resultArray = array();
     while ($row = mysql_fetch_assoc($result)) {
         $this->tableShemaData[] = $row;
     }
     if (!$result) {
         throw new Core_Exceptions(mysql_error());
     }
     $queryRelations = "SELECT  kcg.`TABLE_NAME`,kcg.`COLUMN_NAME`,tb.CONSTRAINT_TYPE,kcg.CONSTRAINT_NAME \t,kcg.TABLE_CATALOG ,\tkcg.TABLE_SCHEMA ,\tkcg.TABLE_NAME ,\tkcg.COLUMN_NAME \t,kcg.ORDINAL_POSITION ,\tkcg.POSITION_IN_UNIQUE_CONSTRAINT \t,kcg.REFERENCED_TABLE_SCHEMA ,\tkcg.REFERENCED_TABLE_NAME \t,kcg.REFERENCED_COLUMN_NAME\n\t\t\t\t\t\t\tFROM  INFORMATION_SCHEMA.KEY_COLUMN_USAGE  kcg\n\t\t\t\t\t\t\tleft join INFORMATION_SCHEMA.TABLE_CONSTRAINTS as tb on  kcg.CONSTRAINT_NAME = tb.CONSTRAINT_NAME and  tb.`TABLE_NAME`=kcg.`TABLE_NAME` and tb.`TABLE_SCHEMA`=kcg.`TABLE_SCHEMA`\n\t\t\t\t\t\t\twhere kcg.`TABLE_NAME`='" . $this->tableName . "' and kcg.`TABLE_SCHEMA`='" . $this->databaseName . "'";
     $resultRelations = mysql_query($queryRelations);
     if (!$resultRelations) {
         throw new Core_Exceptions(mysql_error());
     }
     $rowRelations = array();
     while ($rowRelations = mysql_fetch_assoc($resultRelations)) {
         $this->tableRelationsShemaData[] = $rowRelations;
     }
     foreach ($this->tableRelationsShemaData as $tRSD) {
         if ($tRSD['CONSTRAINT_TYPE'] != "FOREIGN KEY") {
             $this->constraintType[$tRSD['CONSTRAINT_TYPE']][$tRSD['CONSTRAINT_NAME']][] = "'" . $tRSD['COLUMN_NAME'] . "'";
         } else {
             $this->constraintType[$tRSD['CONSTRAINT_TYPE']][$tRSD['CONSTRAINT_NAME']][] = "'" . $tRSD['REFERENCED_TABLE_NAME'] . "'=>'" . $tRSD['REFERENCED_COLUMN_NAME'] . "'";
         }
     }
     $applicationPath = Application::getApplicationPath();
     $modelBaseFolder = $applicationPath . DIRECTORY_SEPARATOR . $this->path . DIRECTORY_SEPARATOR . 'Base';
     $modelFolder = $applicationPath . DIRECTORY_SEPARATOR . $this->path;
     if (!is_dir($modelBaseFolder)) {
         mkdir($modelBaseFolder, 0777);
     }
     $this->getProperties();
     foreach ($this->classMetadata as $c) {
         $this->validators[$c["COLUMN_NAME"]] = $this->mysqlColumnValidators($c);
         $this->filters[$c["COLUMN_NAME"]] = $this->filterColumnValidators($c);
     }
     $baseModelClassName = $modelBaseFolder . DIRECTORY_SEPARATOR . $this->className . "Base.php";
     $modelClassName = $modelFolder . DIRECTORY_SEPARATOR . $this->className . ".php";
     $fh = fopen($baseModelClassName, 'w') or die("can't open file");
     fwrite($fh, $this->writeBaseModelClass());
     fclose($fh);
     if ($overwriteModel) {
         $fh = fopen($modelClassName, 'w') or die("can't open file");
         fwrite($fh, $this->writeModelClass());
         fclose($fh);
         chmod($baseModelClassName, 0777);
         chmod($modelClassName, 0777);
     }
 }
Example #2
0
 /**
  * Get the path of the view
  * 
  * @param string $view
  * @return string
  */
 protected static function getViewPath($view)
 {
     if (DS != '/') {
         $view = str_replace('/', DS, $view);
     }
     $pos = strpos($view, ':');
     if ($pos === false) {
         return Application::getApplicationPath() . 'views' . DS . str_replace('.', DS, $view) . '.phtml';
     } else {
         return Application::getApplicationPath() . 'modules' . DS . substr($view, 0, $pos) . DS . 'views' . DS . str_replace('.', DS, substr($view, $pos + 1)) . '.phtml';
     }
 }