]> _ Git - cubist_cms-back.git/commitdiff
#2783
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 29 May 2019 13:02:35 +0000 (15:02 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 29 May 2019 13:02:35 +0000 (15:02 +0200)
src/app/Console/Commands/CubistCommand.php
src/app/Console/Commands/GenerateCommand.php
src/app/Console/Commands/MigrateCommand.php
src/app/Magic/Controllers/CubistMagicControllerTrait.php
src/app/Magic/Fields/Field.php
src/app/Magic/Models/CubistMagicAbstractModel.php [new file with mode: 0644]
src/app/Magic/Models/CubistMagicModel.php [new file with mode: 0644]
src/app/Magic/Models/CubistMagicModelAbstract.php [deleted file]
src/app/Magic/Models/CubistMagicNestedModel.php

index af8c97f7d1d7341a6172015dc61fe3c135012d60..455b40c3c36670e7786c7b4312ab6432c9569d0e 100644 (file)
@@ -4,7 +4,7 @@
 namespace Cubist\Backpack\app\Console\Commands;
 
 
-use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
+use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
 use Cubist\Util\Files\Files;
 use Cubist\Util\PHP;
 use Illuminate\Console\Command;
@@ -71,7 +71,7 @@ class CubistCommand extends Command
             if ($item->isFile() && $item->getExtension() == 'php') {
                 try {
                     $class = PHP::instanciateClassInFile($item);
-                    if ($class instanceof CubistMagicModelAbstract) {
+                    if ($class instanceof CubistMagicAbstractModel) {
                         if (is_callable($callback)) {
                             call_user_func($callback, $class);
                         }
index 45a9cb81e22bfbadc3aa1f6abba2b2cc7b6bdf88..b4d1449ee409e12321a81c2f85e29bb59c284bed 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace Cubist\Backpack\app\Console\Commands;
 
-use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
+use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
 use Cubist\Backpack\app\Magic\Util;
 
 class GenerateCommand extends CubistCommand
@@ -51,7 +51,7 @@ class GenerateCommand extends CubistCommand
     }
 
     /**
-     * @param $model CubistMagicModelAbstract
+     * @param $model CubistMagicAbstractModel
      */
     public function _generate($model)
     {
index ffdcb20559bfdb90447e824780a09fe521ed5b38..735cab9a3540c0d0f9b46b1c9497ce8a53dcf3dd 100644 (file)
@@ -4,7 +4,6 @@
 namespace Cubist\Backpack\app\Console\Command;
 
 use Cubist\Backpack\app\Console\Commands\CubistCommand;
-use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
 use Doctrine\DBAL\DriverManager;
 use Doctrine\DBAL\Schema\Comparator;
 use Doctrine\DBAL\Schema\Schema;
index d44f4142a0c8c32f707711c30b5467d0b7f4b914..fb5f8a01f79bae187e5edb314a70a7d7e1f78fbb 100644 (file)
@@ -3,7 +3,7 @@
 namespace Cubist\Backpack\app\Magic\Controllers;
 
 use Cubist\Backpack\app\Magic\Fields\Field;
-use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
+use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
 use Cubist\Backpack\app\Magic\Requests\CubistMagicStoreRequest;
 use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
 
@@ -53,7 +53,7 @@ trait CubistMagicControllerTrait
     }
 
     /**
-     * @return CubistMagicModelAbstract
+     * @return CubistMagicAbstractModel
      */
     public function getModelInstance()
     {
index 6466d3bc5d68584d0768e2f75522765139d80de3..25eb624f05c7b0d9f45bb1230da3d7409819be30 100644 (file)
@@ -7,7 +7,7 @@ use Cubist\Backpack\app\Magic\CubistMagicAttribute;
 use Doctrine\DBAL\Schema\Table;
 use Exception;
 use Illuminate\Support\Str;
-use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
+use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
 
 class Field
 {
@@ -106,7 +106,7 @@ class Field
     public function defineDbColumn($table)
     {
         $name = $this->getAttribute('name');
-        $table->addColumn($name, CubistMagicModelAbstract::toDoctrineType($this->_databaseType), $this->_databaseAttributes);
+        $table->addColumn($name, CubistMagicAbstractModel::toDoctrineType($this->_databaseType), $this->_databaseAttributes);
         if ($this->_databaseUnique) {
             $table->addUniqueIndex([$name]);
         }
diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php
new file mode 100644 (file)
index 0000000..ee9daca
--- /dev/null
@@ -0,0 +1,212 @@
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Models;
+
+use Backpack\CRUD\CrudTrait;
+use Cubist\Backpack\app\Magic\Fields\Field;
+use Cubist\Backpack\app\Magic\Util;
+use Cviebrock\EloquentSluggable\Sluggable;
+use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
+use Doctrine\DBAL\Schema\Schema;
+use Illuminate\Database\Eloquent\Model;
+use Cubist\Backpack\app\Magic\CubistMagicAttribute;
+use Illuminate\Support\Str;
+
+class CubistMagicAbstractModel extends Model
+{
+    use CubistMagicAttribute;
+    use SluggableScopeHelpers;
+    use CrudTrait;
+    use Sluggable {
+        replicate as protected replicateSluggable;
+    }
+
+    protected static $_doctrineTypesMapping = ['int' => 'integer'];
+
+    protected $nested = false;
+    protected $primaryKey = 'id';
+    public $timestamps = true;
+
+    /**
+     * @var Field[]
+     */
+    protected $_fields = [];
+
+    /**
+     * @var array
+     */
+    protected $_options = [];
+
+    /**
+     * @var array
+     */
+    protected $_slugFields = ['slug', 'title', 'name'];
+
+    public function __construct(array $attributes = [])
+    {
+        $this->setFields();
+        $this->bootIfNotBooted();
+        $this->initializeTraits();
+        $this->syncOriginal();
+        $this->fill($attributes);
+    }
+
+    public function setFields()
+    {
+
+    }
+
+    public function getFields()
+    {
+        return $this->_fields;
+    }
+
+    /**
+     * Return the sluggable configuration array for this model.
+     *
+     * @return array
+     */
+    public function sluggable()
+    {
+        return [
+            'slug' => [
+                'source' => 'slug_or_title',
+            ],
+        ];
+    }
+
+    // The slug is created automatically from the "title" field if no slug exists.
+    public function getSlugOrTitleAttribute()
+    {
+
+        foreach ($this->_slugFields as $item) {
+            if (isset($this->$item) && $this->item != '') {
+                return $this->$item;
+            }
+        }
+    }
+
+    public function getOption($key, $default = null)
+    {
+        if (isset($this->_options[$key])) {
+            return $this->_options[$key];
+        }
+        return $default;
+    }
+
+    /**
+     * @param $attributes
+     */
+    public function addField($attributes)
+    {
+        /** @var Field $field */
+        $field = Field::getInstance($attributes);
+        $name = $field->getAttribute('name');
+        $this->_fields[$name] = $field;
+
+        if ($field->getAttribute('fillable')) {
+            $this->fillable[] = $name;
+        }
+        if ($field->getAttribute('guarded')) {
+            $this->guarded[] = $name;
+        }
+        if ($field->getAttribute('hidden')) {
+            $this->hidden[] = $name;
+        }
+    }
+
+    public function generateCode()
+    {
+        $this->_generateControllerCode();
+    }
+
+    protected function _generateControllerCode()
+    {
+        $this->_replaceInCode(Util::getStubPath() . 'Controller.stub',
+            app_path() . '/Http/Controllers/Admin/' . $this->getControllerClass() . '.php');
+    }
+
+    public function getControllerClass()
+    {
+        return $this->getStudlyName() . 'CrudController';
+    }
+
+    protected function _replaceInCode($stub, $dest)
+    {
+        $vars = ['CONTROLLERCLASS' => $this->getControllerClass(),
+            'ROUTEURL' => $this->getOption('name'),
+            'SINGULAR' => $this->getOption('singular', $this->getOption('name')),
+            'PLURAL' => $this->getOption('plural', ''),
+            'MODELNAMESPACE' => get_class($this),
+            'EXTENDS' => $this->nested ? 'CubistNestedMagicController' : 'CubistMagicController',
+        ];
+
+        $res = file_get_contents($stub);
+        foreach ($vars as $name => $value) {
+            $res = str_replace('_' . $name . '_', $value, $res);
+        }
+
+        if (!file_exists(dirname($dest))) {
+            mkdir(dirname($dest), 0777, true);
+        }
+
+        file_put_contents($dest, $res);
+    }
+
+    public function getStudlyName()
+    {
+        return Str::studly($this->getOption('name'));
+    }
+
+    /**
+     * @param $schema Schema
+     */
+    public function setSchema($schema)
+    {
+        $table = $schema->createTable($this->table);
+        try {
+            $table->addColumn($this->primaryKey, self::toDoctrineType($this->keyType), ['autoincrement' => $this->incrementing, 'unsigned' => true]);
+        } catch (\Exception $e) {
+            return $e->getMessage();
+        }
+
+        $table->setPrimaryKey([$this->primaryKey], 'pk_' . $this->table);
+
+        foreach ($this->_fields as $field) {
+            $field->defineDbColumn($table);
+        }
+
+        if ($this->nested) {
+            $table->addColumn('parent_id', 'integer', ['unsigned' => true, 'notnull' => false]);
+            $table->addIndex(['parent_id']);
+            $table->addColumn('lft', 'integer', ['unsigned' => true, 'default' => 0]);
+            $table->addIndex(['lft']);
+            $table->addColumn('rgt', 'integer', ['unsigned' => true, 'default' => 0]);
+            $table->addIndex(['rgt']);
+            $table->addColumn('depth', 'integer', ['unsigned' => true, 'default' => 0]);
+        }
+
+        if ($this->timestamps) {
+            $options = ['notnull' => false];
+            $table->addColumn(static::CREATED_AT, 'date', $options);
+            $table->addColumn(static::UPDATED_AT, 'date', $options);
+            $table->addColumn('deleted_at', 'date', $options);
+        }
+    }
+
+    public function replicate(array $except = null)
+    {
+        $this->replicateSluggable($except);
+    }
+
+    public static function toDoctrineType($type)
+    {
+        if (isset(self::$_doctrineTypesMapping[$type])) {
+            return self::$_doctrineTypesMapping[$type];
+        }
+        return $type;
+    }
+
+
+}
diff --git a/src/app/Magic/Models/CubistMagicModel.php b/src/app/Magic/Models/CubistMagicModel.php
new file mode 100644 (file)
index 0000000..8fdb583
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+
+namespace Cubist\Backpack\app\Magic\Models;
+
+class CubistMagicModel extends CubistMagicAbstractModel
+{
+
+}
diff --git a/src/app/Magic/Models/CubistMagicModelAbstract.php b/src/app/Magic/Models/CubistMagicModelAbstract.php
deleted file mode 100644 (file)
index 04ab127..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-<?php
-
-
-namespace Cubist\Backpack\app\Magic\Models;
-
-use Backpack\CRUD\CrudTrait;
-use Cubist\Backpack\app\Magic\Fields\Field;
-use Cubist\Backpack\app\Magic\Util;
-use Cviebrock\EloquentSluggable\Sluggable;
-use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
-use Doctrine\DBAL\Schema\Schema;
-use Illuminate\Database\Eloquent\Model;
-use Cubist\Backpack\app\Magic\CubistMagicAttribute;
-use Illuminate\Support\Str;
-
-class CubistMagicModelAbstract extends Model
-{
-    use CubistMagicAttribute;
-    use SluggableScopeHelpers;
-    use CrudTrait;
-    use Sluggable {
-        replicate as protected replicateSluggable;
-    }
-
-    protected static $_doctrineTypesMapping = ['int' => 'integer'];
-
-    protected $nested = false;
-    protected $primaryKey = 'id';
-    public $timestamps = true;
-
-    /**
-     * @var Field[]
-     */
-    protected $_fields = [];
-
-    /**
-     * @var array
-     */
-    protected $_options = [];
-
-    /**
-     * @var array
-     */
-    protected $_slugFields = ['slug', 'title', 'name'];
-
-    public function __construct(array $attributes = [])
-    {
-        $this->setFields();
-        $this->bootIfNotBooted();
-        $this->initializeTraits();
-        $this->syncOriginal();
-        $this->fill($attributes);
-    }
-
-    public function setFields()
-    {
-
-    }
-
-    public function getFields()
-    {
-        return $this->_fields;
-    }
-
-    /**
-     * Return the sluggable configuration array for this model.
-     *
-     * @return array
-     */
-    public function sluggable()
-    {
-        return [
-            'slug' => [
-                'source' => 'slug_or_title',
-            ],
-        ];
-    }
-
-    // The slug is created automatically from the "title" field if no slug exists.
-    public function getSlugOrTitleAttribute()
-    {
-
-        foreach ($this->_slugFields as $item) {
-            if (isset($this->$item) && $this->item != '') {
-                return $this->$item;
-            }
-        }
-    }
-
-    public function getOption($key, $default = null)
-    {
-        if (isset($this->_options[$key])) {
-            return $this->_options[$key];
-        }
-        return $default;
-    }
-
-    /**
-     * @param $attributes
-     */
-    public function addField($attributes)
-    {
-        /** @var Field $field */
-        $field = Field::getInstance($attributes);
-        $name = $field->getAttribute('name');
-        $this->_fields[$name] = $field;
-
-        if ($field->getAttribute('fillable')) {
-            $this->fillable[] = $name;
-        }
-        if ($field->getAttribute('guarded')) {
-            $this->guarded[] = $name;
-        }
-        if ($field->getAttribute('hidden')) {
-            $this->hidden[] = $name;
-        }
-    }
-
-    public function generateCode()
-    {
-        $this->_generateControllerCode();
-    }
-
-    protected function _generateControllerCode()
-    {
-        $this->_replaceInCode(Util::getStubPath() . 'Controller.stub',
-            app_path() . '/Http/Controllers/Admin/' . $this->getControllerClass() . '.php');
-    }
-
-    public function getControllerClass()
-    {
-        return $this->getStudlyName() . 'CrudController';
-    }
-
-    protected function _replaceInCode($stub, $dest)
-    {
-        $vars = ['CONTROLLERCLASS' => $this->getControllerClass(),
-            'ROUTEURL' => $this->getOption('name'),
-            'SINGULAR' => $this->getOption('singular', $this->getOption('name')),
-            'PLURAL' => $this->getOption('plural', ''),
-            'MODELNAMESPACE' => get_class($this),
-            'EXTENDS' => $this->nested ? 'CubistNestedMagicController' : 'CubistMagicController',
-        ];
-
-        $res = file_get_contents($stub);
-        foreach ($vars as $name => $value) {
-            $res = str_replace('_' . $name . '_', $value, $res);
-        }
-
-        if (!file_exists(dirname($dest))) {
-            mkdir(dirname($dest), 0777, true);
-        }
-
-        file_put_contents($dest, $res);
-    }
-
-    public function getStudlyName()
-    {
-        return Str::studly($this->getOption('name'));
-    }
-
-    /**
-     * @param $schema Schema
-     */
-    public function setSchema($schema)
-    {
-        $table = $schema->createTable($this->table);
-        try {
-            $table->addColumn($this->primaryKey, self::toDoctrineType($this->keyType), ['autoincrement' => $this->incrementing, 'unsigned' => true]);
-        } catch (\Exception $e) {
-            return $e->getMessage();
-        }
-
-        $table->setPrimaryKey([$this->primaryKey], 'pk_' . $this->table);
-
-        foreach ($this->_fields as $field) {
-            $field->defineDbColumn($table);
-        }
-
-        if ($this->nested) {
-            $table->addColumn('parent_id', 'integer', ['unsigned' => true, 'notnull' => false]);
-            $table->addIndex(['parent_id']);
-            $table->addColumn('lft', 'integer', ['unsigned' => true, 'default' => 0]);
-            $table->addIndex(['lft']);
-            $table->addColumn('rgt', 'integer', ['unsigned' => true, 'default' => 0]);
-            $table->addIndex(['rgt']);
-            $table->addColumn('depth', 'integer', ['unsigned' => true, 'default' => 0]);
-        }
-
-        if ($this->timestamps) {
-            $options = ['notnull' => false];
-            $table->addColumn(static::CREATED_AT, 'date', $options);
-            $table->addColumn(static::UPDATED_AT, 'date', $options);
-            $table->addColumn('deleted_at', 'date', $options);
-        }
-    }
-
-    public function replicate(array $except = null)
-    {
-        $this->replicateSluggable($except);
-    }
-
-    public static function toDoctrineType($type)
-    {
-        if (isset(self::$_doctrineTypesMapping[$type])) {
-            return self::$_doctrineTypesMapping[$type];
-        }
-        return $type;
-    }
-
-
-}
index 8081be49df23318b7eebdb9cebb9263c451a13ff..0f6902b152fd6be5e671536b61981e827f6e802b 100644 (file)
@@ -6,7 +6,7 @@ namespace Cubist\Backpack\app\Magic\Models;
 
 use Webfactor\Laravel\Backpack\NestedModels\Traits\NestedModelTrait;
 
-class CubistMagicNestedModel extends CubistMagicModelAbstract
+class CubistMagicNestedModel extends CubistMagicModel
 {
     use NestedModelTrait {
         replicate as private replicateNodeTrait;