示例#1
0
 public function makeTableFiles($dbname, $targetTable)
 {
     $_ = $this;
     if (!($DB = $_->getDB($dbname))) {
         die("error: '{$dbname}' class file is not exists in ../model/db/\n");
     }
     $DbOperator = new DbOperatorContext($DB::$SYSTEM);
     $DbOperator->setDb($DB);
     $tables = $DbOperator->getTables();
     $template = $DbOperator->getTableClassTemplate();
     $columnTypes = $DbOperator->getColumnTypes();
     $dirPath = $_->APP_ROOT . "/model/_def/db/{$dbname}";
     if (!file_exists($dirPath)) {
         mkdir($dirPath, 0777, true);
     }
     $id_column = 'id';
     // default
     foreach ($tables as $table) {
         if (!empty($targetTable) && $table != $targetTable) {
             continue;
         }
         $filePath = $dirPath . "/{$table}.php";
         if (file_exists($filePath)) {
             echo "error: {$filePath} is exists. can not save file.\n\n";
             continue;
         }
         $columns = $DbOperator->getColumns($table);
         foreach ($columns as $key => $column) {
             if ($column['extra'] == 'auto_increment') {
                 $id_column = $column['name'];
             }
             foreach ($columnTypes as $mysqlType => $datatype) {
                 if (preg_match("/^{$mysqlType}/", $column['type'])) {
                     $columns[$key]['type'] = $datatype;
                     break;
                 }
             }
         }
         $_->view->assign('table', $table);
         $_->view->assign('id_column', $id_column);
         $_->view->assign('columns', $columns);
         $classCode = $_->view->fetch("string:{$template}");
         file_put_contents($filePath, $classCode);
         echo "------------------------------\n";
         echo "save class file {$table}.php\n";
         echo "\n";
         //echo $classCode;
         //echo "\n";
     }
 }
示例#2
0
 public function makeTableModels($dbname, $targetTable)
 {
     $_ = $this;
     if (!($DB = $_->getDB($dbname))) {
         die("error: '{$dbname}' class file is not exists in ../model/db/\n");
     }
     $DbOperator = new DbOperatorContext($DB::$SYSTEM);
     $DbOperator->setDb($DB);
     $tables = $DbOperator->getTables();
     foreach ($tables as $table) {
         if (!empty($targetTable) && $table != $targetTable) {
             continue;
         }
         $dirPath = $_->APP_ROOT . "/model/{$table}";
         if (!file_exists($dirPath)) {
             mkdir($dirPath, 0777, true);
         }
         $testDirPath = $_->APP_ROOT . "/test/model/{$table}";
         if (!file_exists($testDirPath)) {
             mkdir($testDirPath, 0777, true);
         }
         //
         // List Model
         $columns = $DbOperator->getColumns($table);
         $_->view->assign('db', $dbname);
         $_->view->assign('table', $table);
         $_->view->assign('columns', $columns);
         $className = ucfirst($table) . 'List';
         $_->view->assign('className', $className);
         $filePath = $dirPath . '/' . $className . ".php";
         if (file_exists($filePath)) {
             echo "error: {$filePath} is exists. can not save file.\n\n";
         } else {
             $templateFile = $_->APP_ROOT . '/etc/template/model/dataList.php';
             $classCode = $_->view->fetch($templateFile);
             file_put_contents($filePath, $classCode);
             echo "------------------------------\n";
             echo "save class file {$className}.php\n";
             echo "\n";
             //echo $classCode;
             //echo "\n";
         }
         // List Model Test
         $filePath = $testDirPath . '/' . $className . "Test.php";
         if (file_exists($filePath)) {
             echo "error: {$filePath} is exists. can not save file.\n\n";
         } else {
             $templateFile = $_->APP_ROOT . '/etc/template/test/model/dataListTest.php';
             $classCode = $_->view->fetch($templateFile);
             file_put_contents($filePath, $classCode);
             echo "------------------------------\n";
             echo "save class file {$className}" . "Test.php\n";
             echo "\n";
             //echo $classCode;
             //echo "\n";
         }
         // Record Model
         $className = ucfirst($table) . 'Record';
         $_->view->assign('className', $className);
         $filePath = $dirPath . '/' . $className . ".php";
         if (file_exists($filePath)) {
             echo "error: {$filePath} is exists. can not save file.\n\n";
         } else {
             $templateFile = $_->APP_ROOT . '/etc/template/model/dataRecord.php';
             $classCode = $_->view->fetch($templateFile);
             file_put_contents($filePath, $classCode);
             echo "------------------------------\n";
             echo "save class file {$className}.php\n";
             echo "\n";
             //echo $classCode;
             //echo "\n";
         }
         // Record Model Test
         $filePath = $testDirPath . '/' . $className . "Test.php";
         if (file_exists($filePath)) {
             echo "error: {$filePath} is exists. can not save file.\n\n";
         } else {
             $templateFile = $_->APP_ROOT . '/etc/template/test/model/dataRecordTest.php';
             $classCode = $_->view->fetch($templateFile);
             file_put_contents($filePath, $classCode);
             echo "------------------------------\n";
             echo "save class file {$className}" . "Test.php\n";
             echo "\n";
             //echo $classCode;
             //echo "\n";
         }
     }
 }
示例#3
0
 public function main()
 {
     $_ = $this;
     $_->APP_ROOT = CmdLibs::getAppRoot(1);
     $_->initView();
     $_->view->assign('localTestServer', $this->C['LOCAL_TEST_SERVER']);
     // パラメータからモデル名とページ名を決定。
     $modelName = cmdLibs::getParam('-m');
     $pageName = cmdLibs::getParam('-p');
     $overWrite = cmdLibs::getParam('-o');
     if (empty($modelName) && empty($pageName)) {
         die("usage: " . cmdLibs::scriptName() . " -m modelName -p pageName [-o yes]\n At least you should spec one parameter -m or -p.\n");
     }
     if ($modelName) {
         echo "use model name  {$modelName}.\n";
         // テーブル名を取得
         //$MODEL = $_->getModel($modelName);
         $MODEL = new $modelName();
         $tableName = $MODEL->TABLE->TABLE;
         if (empty($tableName)) {
             die("\nmodel {$modelName} is not correct.\n\n");
         }
         echo "table name is '{$tableName}'.\n";
         // テーブルのカラム一覧を取得
         $DB = $MODEL->DB;
         $DbOperator = new DbOperatorContext($DB::$SYSTEM);
         $DbOperator->setDb($DB);
         $columns = $DbOperator->getColumns($tableName);
         // モデル関連テンプレート変数の設定
         $_->view->assign('modelName', $modelName);
         $_->view->assign('tableName', $tableName);
         $_->view->assign('columns', $columns);
     }
     // ページ名を決定
     if (!$pageName) {
         if (preg_match("/(.*)List/", $modelName, $m)) {
             $pageName = lcfirst($m[1]);
         } elseif (preg_match("/(.*)Record/", $modelName, $m)) {
             $pageName = lcfirst($m[1]) . '/record';
         } else {
             $pageName = $tableName;
         }
     }
     echo "page name is '{$pageName}'.\n";
     // 上書きモードを設定
     if ($overWrite == 'yes') {
         $_->overWrite = true;
     } else {
         $_->overWrite = false;
     }
     // ページ名からクラス名を生成
     if (strpos($pageName, '/') !== false) {
         $pageNameAry = explode('/', $pageName);
         $pageNameAry = array_map("ucfirst", $pageNameAry);
         $className = implode('', $pageNameAry);
     } else {
         $className = ucfirst($pageName);
     }
     echo "class name is '{$className}'.\n\n";
     // ページ関係テンプレート変数の設定
     $_->view->assign('pageName', $pageName);
     $_->view->assign('className', $className);
     // 各ファイルの保存
     if (isset($MODEL)) {
         switch ($MODEL::MODEL_TYPE) {
             case 'List':
                 $_->genListCtl($pageName, $className);
                 $_->genListHtml($pageName);
                 $_->genAutoList($pageName);
                 $_->genScrollAndSearch($pageName, $className);
                 $_->genLangResource($pageName);
                 $_->genListTest($pageName, $className);
                 break;
             case 'Record':
                 $_->genRecordCtl($pageName, $className);
                 $_->genRecordHtml($pageName);
                 $_->genAddHtml($pageName);
                 $_->genEditHtml($pageName);
                 $_->genAutoRecord($pageName);
                 $_->genAutoAddForm($pageName);
                 $_->genAutoEditForm($pageName);
                 $_->genPost($pageName, $className);
                 $_->genLangResource($pageName);
                 $_->genRecordTest($pageName, $className);
                 break;
         }
     } else {
         $_->genBlankCtl($pageName, $className);
         $_->genBlankHtml($pageName);
         $_->genLangResource($pageName);
         $_->genBlankTest($pageName, $className);
     }
 }