Permalink
Browse files

Merge pull request #25 from dog-ears/develop

remove has_many propaty from crud-d-scaffold.json
  • Loading branch information...
dog-ears committed Aug 28, 2017
2 parents 0c7be5b + df3f3eb commit d84f758055c794eb8150f12d70a330cf28137a8b
Showing with 40 additions and 18 deletions.
  1. +0 −3 crud-d-scaffold.json.sample
  2. +0 −2 readme.md
  3. +1 −2 src/Core/CrudDScaffold.php
  4. +39 −11 src/Core/CrudDScaffoldSetting.php
@@ -5,7 +5,6 @@
"name": "jointAuthor", /* [required] format[nameName] */
"display_name": "JOINT AUTHOR", /* [required] */
"use_soft_delete": "true", /* [default:false] ex( true, false ) */
"has_many": ["nicePost"], /* [default:[]] format[nameName] */
"schemas": [
{
"name": "realName", /* [required] */
@@ -46,7 +45,6 @@
"name": "nicePost",
"display_name": "NICE POST",
"use_soft_delete": "false",
"has_many": ["goodComment"],
"schemas": [
{
"name": "bigTitle",
@@ -87,7 +85,6 @@
"name": "goodComment",
"display_name": "GOOD COMMENT",
"use_soft_delete": "true",
"has_many": [],
"schemas": [
{
"name": "commenterName",
View
@@ -125,8 +125,6 @@ php artisan db:seed
{
"name": "jointAuthor", /* [required] format[nameName] */ <- Name of model
"display_name": "JOINT AUTHOR", /* [required] */ <- Display name of the model
"use_soft_delete": "true", /* [default:false] ex( true, false ) */ <- Whether to use software delete
"has_many": ["nicePost"], /* [default:[]] format[nameName] */ <- If there is a has_many relationship, describe the target model name as an array.
"schemas": [
{
"name": "realName", /* [required] */ <- Column name (In the case of relation, make it model name _id)
@@ -13,7 +13,6 @@
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use dogears\CrudDscaffold\Commands\CrudDscaffoldSetupCommand;
use dogears\CrudDscaffold\Core\CrudDscaffoldSetting ;
use dogears\CrudDscaffold\Core\StubCompiler ;
@@ -53,7 +52,7 @@ public function generate(){
$this->command->info('Now Generating...');
$this->setupMigration();
$this->setupSeeding(); //skip.
$this->setupSeeding();
$this->setupModel();
$this->setupController();
$this->setupViewLayout();
@@ -20,7 +20,6 @@ class CrudDscaffoldSetting
public $setting_array; /* array */
public $force;
public function __construct( Filesystem $files )
{
$this->files = $files;
@@ -30,17 +29,15 @@ public function __construct( Filesystem $files )
public function loadSettingFromCommand( CrudDscaffoldSetupCommand $command )
{
// set data
$this->command = $command;
//get force option
$this->force = $this->command->option('force');
//get setting file path
$file_path = $this->command->argument('filePath');
$this->command->info( 'reading setting file... ('. $file_path. ')' );
//setting.json - exist check
// setting.json - exist check
if( !$this->files->exists( $file_path ) ){
$this->command->error( 'setting file is not found ('. $file_path. ')' );
exit();
@@ -52,6 +49,8 @@ public function loadSettingFromCommand( CrudDscaffoldSetupCommand $command )
exit();
}
//delete comment
$data = $this->files->get( $file_path );
$data = preg_replace ( '#/\*[^\*]*\*/#' , '' , $data );
@@ -77,7 +76,6 @@ public function loadSettingFromCommand( CrudDscaffoldSetupCommand $command )
private function checkFormatOfSettingJson( $file_path ){
//format check
if( !array_key_exists('app_type',$this->setting_array) ){
$this->setting_array['app_type'] = 'web';
}
@@ -102,9 +100,6 @@ private function checkFormatOfSettingJson( $file_path ){
if( !array_key_exists('use_soft_delete', $model) ){
$model['use_soft_delete'] = 'false';
}
if( !array_key_exists('has_many', $model) ){
$model['has_many'] = [];
}
foreach( $model['schemas'] as &$schema){
@@ -135,6 +130,40 @@ private function checkFormatOfSettingJson( $file_path ){
}
if( !array_key_exists('belongsto', $schema) ){
$schema['belongsto'] = '';
}else{
if($schema['belongsto'] !== ""){ // case - $schema has belongsto
//target model exist check
$error = true;
foreach( $this-> setting_array["models"] as &$target_model ){
if( $target_model["name"] === $schema['belongsto'] ){
$error = false;
// belongsto_column exist check
if( !array_key_exists('belongsto_column', $schema) || $schema['belongsto_column'] == "" ){
$this->command->error( 'schema with belongsto needs belongsto_column propaty ('. $file_path. ')' );
return false;
}
// check target_model has column same as belongsto_column
$result_array = array_filter ( $target_model["schemas"], function($s) use($schema){
return $schema['belongsto_column'] === $s['name'];
});
if( !count($result_array) ){
$this->command->error( 'target_model('. $target_model["name"]. ') need column ('. $schema['belongsto_column']. ') ('. $file_path. ')' );
return false;
}
//add has_many data
$target_model["has_many"][] = $model["name"];
}
}unset($target_model);
if($error){
$this->command->error( 'belongsto target model ('. $schema['belongsto'] .') is not exitst! ('. $file_path. ')' );
return false;
}
}
}
if( !array_key_exists('belongsto_column', $schema) ){
$schema['belongsto_column'] = '';
@@ -144,5 +173,4 @@ private function checkFormatOfSettingJson( $file_path ){
}unset($model);
return true;
}
}

0 comments on commit d84f758

Please sign in to comment.