/** * @inheritdoc */ public function generate() { $files = parent::generate(); $db = $this->getDbConnection(); foreach ($this->getTableNames() as $tableName) { $className = $this->generateClassName($tableName); $params = ['tableName' => $tableName, 'className' => $className]; $files[] = new CodeFile(Yii::getAlias('@' . str_replace('\\', '/', $this->getChildNs())) . '/' . $className . '.php', $this->render('child_model.php', $params)); } return $files; }
public function testModelGenerator() { $generator = new ModelGenerator(); $generator->template = 'default'; $generator->tableName = 'profile'; $generator->modelClass = 'Profile'; $valid = $generator->validate(); $this->assertTrue($valid, 'Validation failed: ' . print_r($generator->getErrors(), true)); $files = $generator->generate(); $modelCode = $files[0]->content; $this->assertTrue(strpos($modelCode, "'id' => 'ID'") !== false, "ID label should be there:\n" . $modelCode); $this->assertTrue(strpos($modelCode, "'description' => 'Description',") !== false, "Description label should be there:\n" . $modelCode); }
/** * @inheritdoc */ public function generate() { if (self::TMPL_NAME !== $this->template) { return parent::generate(); } $files = []; $relations = $this->generateRelations(); //$relations = []; $db = $this->getDbConnection(); foreach ($this->getTableNames() as $tableName) { // model : $modelClassName = $this->generateClassName($tableName); $queryClassName = $this->generateQuery ? $this->generateQueryClassName($modelClassName) : false; $tableSchema = $db->getTableSchema($tableName); $params = ['tableName' => $tableName, 'className' => $modelClassName, 'queryClassName' => $queryClassName, 'tableSchema' => $tableSchema, 'labels' => $this->generateLabels($tableSchema), 'rules' => $this->generateRules($tableSchema), 'relations' => isset($relations[$tableName]) ? $relations[$tableName] : []]; foreach ($this->modelFilesMap as $tmpl => $ns) { $path = '@' . str_replace('\\', '/', str_replace('{ns}', $this->getNs($modelClassName), $ns)); $files[] = new CodeFile(Yii::getAlias($path) . '/' . $modelClassName . '.php', $this->render(sprintf('%s.php', $tmpl), $params)); } // query : if ($queryClassName) { $params = ['className' => $queryClassName, 'modelClassName' => $modelClassName]; foreach ($this->queryFilesMap as $tmpl => $ns) { $path = '@' . str_replace('\\', '/', str_replace('{ns}', $this->getNs($queryClassName), $ns)); $files[] = new CodeFile(Yii::getAlias($path) . '/' . $queryClassName . '.php', $this->render(sprintf('%s.php', $tmpl), $params)); } } } return $files; }
/** * @inheritdoc */ public function generate() { if (self::ID_CURRENT_TMPL !== $this->template) { return parent::generate(); } $files = []; //$relations = $this->generateRelations(); $tableSchema = $this->getTableSchema(); // Generate MODEL classes $this->helperModel->generateModels($tableSchema, $files); // Generate MODEL query classes $this->helperModel->generateQueries($tableSchema, $files); if (!$this->isDbView()) { // Generate MODEL search classes $this->helperModel->generateSearches($tableSchema, $files); // Generate CRUD controller $this->helperCrud->generateControllers($tableSchema, $files); // Generate CRUD views $this->helperCrud->generateViews($tableSchema, $files); // Generate COMPONENTS $this->helperComponent->generateComponents($tableSchema, $files); } return $files; }
/** * @inheritdoc */ public function generate() { $this->commonBaseClass = $this->baseClass; $this->commonQueryBaseClass = $this->queryBaseClass; $this->relationsDone = false; $this->classNames = []; $files = parent::generate(); $this->baseClass = $this->commonBaseClass; $this->queryBaseClass = $this->commonQueryBaseClass; return $files; }