]> _ Git - cubist_cms-back.git/commitdiff
wait #4830 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 21 Oct 2021 16:02:53 +0000 (18:02 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 21 Oct 2021 16:02:53 +0000 (18:02 +0200)
src/app/Http/Controllers/CubistCrudController.php
src/app/Http/Controllers/Operations/ListOperation.php [deleted file]
src/app/Magic/Controllers/CubistMagicController.php
src/app/Magic/Fields/Field.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/app/Magic/Operations/CreateOperation.php
src/app/Magic/Operations/ListOperation.php [new file with mode: 0644]
src/app/Magic/Operations/UpdateOperation.php

index d81b35a0c26b3f7cdd012f5f43115fd5253038c4..ca0b4ac075663add526d6fcd10de5fcb0ba9c651 100644 (file)
@@ -6,8 +6,8 @@ namespace Cubist\Backpack\Http\Controllers;
 
 use Backpack\CRUD\app\Http\Controllers\CrudController;
 
-use Cubist\Backpack\Http\Controllers\Operations\ListOperation;
 use Cubist\Backpack\Http\Controllers\Operations\MediaOperation;
+use Cubist\Backpack\Magic\Operations\ListOperation;
 use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
 
 class CubistCrudController extends CrudController
diff --git a/src/app/Http/Controllers/Operations/ListOperation.php b/src/app/Http/Controllers/Operations/ListOperation.php
deleted file mode 100644 (file)
index d146fed..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-
-namespace Cubist\Backpack\Http\Controllers\Operations;
-
-
-trait ListOperation
-{
-    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation {
-        index as baseIndex;
-    }
-
-    protected function index()
-    {
-        $this->getModelInstance()->addWidgets();
-        return $this->baseIndex();
-    }
-}
index 50c1305cbb9410faa4357df7233d806f4aa82c64..7d6eea97ca1338b62e47014a93ed6ef3df28ce50 100644 (file)
@@ -281,29 +281,6 @@ class CubistMagicController extends CubistCrudController
         }
     }
 
-    public function index()
-    {
-        if ($this->_oneInstance) {
-            return Redirect::to(backpack_url($this->_routeURL . '/1/edit'));
-        }
-        return parent::index();
-    }
-
-    public function edit($id)
-    {
-        if ($this->_oneInstance) {
-            $id = 1;
-        }
-        $this->getModelInstance()->onBeforeEdit($this, $id);
-        return parent::edit($id);
-    }
-
-    public function create()
-    {
-        $this->getModelInstance()->onBeforeCreate($this);
-        return parent::create();
-    }
-
     protected function _bulkChangeOnlineStatus($status)
     {
         $this->crud->hasAccessOrFail('update');
index 12a9f4b1d23074268933e36b9e663d86a89b9521..148ab5666ad57197019802e45fb1afe113417ca5 100644 (file)
@@ -40,6 +40,7 @@ class Field implements \ArrayAccess
     protected $_databaseType = 'text';
     protected $_databaseUnique = false;
     protected $_databaseIndex = false;
+    protected $_databaseDefault = null;
 
     /** @var bool|string|array */
     protected $_cast = false;
@@ -113,7 +114,7 @@ class Field implements \ArrayAccess
                 return 'text';
             }
         }
-        return $this->_databaseType;
+        return $this->getAttribute('database_type');
     }
 
 
@@ -142,7 +143,7 @@ class Field implements \ArrayAccess
             'default' => '', 'cast' => $this->_cast, 'column_view_namespace' => $this->_columnViewNamespace, 'searchLogic' => $this->_searchLogic,
             'allow_null' => true,
             'can' => $this->_can, 'can_write' => $this->_canWrite, 'auth' => $this->_auth,
-            'database_unique' => $this->_databaseUnique, 'database_index' => $this->_databaseIndex,
+            'database_type' => $this->_databaseType, 'database_unique' => $this->_databaseUnique, 'database_index' => $this->_databaseIndex, 'database_default' => $this->_databaseDefault,
             'fake' => false, 'store_in' => 'extras', 'attributes' => []];
     }
 
@@ -289,15 +290,21 @@ class Field implements \ArrayAccess
             return;
         }
 
+
         $attributes = array_merge(
             ['notnull' => !$this->getAttribute('allow_null', true)],
             $this->_databaseAttributes
         );
 
+        if ($this->getAttribute('database_default') !== null) {
+            $attributes['default'] = $this->getAttribute('database_default');
+        }
+
         $table->addColumn($name,
             CubistMagicAbstractModel::toDoctrineType($this->getDatabaseType()),
             $attributes
         );
+
         if ($this->getAttribute('database_unique', false)) {
             $table->addUniqueIndex([$name]);
         }
index 881ff268bbf81d36212ddc39ce1348eb063148e5..847e086c7f52a8c710c587f4ec7fbd22bb65c15c 100644 (file)
@@ -110,11 +110,22 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     public static function boot()
     {
         parent::boot();
+
         static::addGlobalScope('ownerclause', function (Builder $builder) {
             static::addOwnerClause($builder);
         });
     }
 
+
+    /*
+     * @param  \Illuminate\Database\Eloquent\Builder  $query
+     * @return void
+     */
+    public function scopeCreatedok($query)
+    {
+        $query->where('created_ok', 1);
+    }
+
     public static function addOwnerClause(Builder $builder)
     {
     }
@@ -190,6 +201,17 @@ class CubistMagicAbstractModel extends Model implements HasMedia
                 'hidden' => true,
                 'fillable' => false]);
         }
+        $this->addField(
+            ['name' => 'created_ok',
+                'type' => 'Hidden',
+                'default' => '1',
+                'database_default' => '1',
+                'database_type' => 'boolean',
+                'translatable' => false,
+                'value' => '1',
+                'hidden' => true,
+                'fillable' => false]
+        );
 
         $this->fakeColumns = array_unique($this->fakeColumns);
         if (get_class($this) !== config("auth.providers.users.model")) {
@@ -848,10 +870,10 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     }
 
 
-        /**
-         * @param $user CubistMagicAuthenticatable
-         * @return bool
-         */
+    /**
+     * @param $user CubistMagicAuthenticatable
+     * @return bool
+     */
     public function canView($user)
     {
         return $this->canList($user);
index 2d66e2426e2ed5a67b7ebd4e8771837e65bc3cb3..d31b5e7e488ba2079c879d99300d5734b41d0649 100644 (file)
@@ -1,19 +1,38 @@
 <?php
 
 namespace Cubist\Backpack\Magic\Operations;
+
 use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
 
 trait CreateOperation
 {
     use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation {
         store as _store;
+        create as _create;
         setupCreateDefaults as _setupCreateDefaults;
     }
 
+    /**
+     * Show the form for creating inserting a new row.
+     *
+     * @return \Illuminate\Contracts\View\View
+     */
+    public function create()
+    {
+        $instance = $this->crud->model;
+        if ($instance instanceof CubistMagicAbstractModel) {
+            $instance->setAttribute('created_ok', '0');
+            $instance->saveQuietly();
+            $id = $instance->getIdValue();
+            return redirect(backpack_url($instance->getOption('name') . '/' . $id . '/edit'));
+        }
+        return $this->_create();
+    }
+
     public function store()
     {
         $res = $this->_store();
-        if($this->crud->entry instanceof CubistMagicAbstractModel) {
+        if ($this->crud->entry instanceof CubistMagicAbstractModel) {
             $this->crud->entry->onAfterSave();
         }
         return $res;
diff --git a/src/app/Magic/Operations/ListOperation.php b/src/app/Magic/Operations/ListOperation.php
new file mode 100644 (file)
index 0000000..8be5e9e
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+namespace Cubist\Backpack\Magic\Operations;
+
+use Cubist\Backpack\Magic\Models\CubistMagicAbstractModel;
+
+trait ListOperation
+{
+    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation {
+        search as _search;
+        index as _index;
+    }
+
+    public function index()
+    {
+        $this->getModelInstance()->addWidgets();
+        $this->crud->addClause('createdok');
+        return $this->_index();
+    }
+
+    public function search()
+    {
+        $this->crud->addClause('createdok');
+        return $this->_search();
+    }
+
+
+}
index 1b07d96fb0cf9e42dfe23b197a5af2623f45886e..47cc283e341deeaac8330e890064a38142658e34 100644 (file)
@@ -10,7 +10,6 @@ trait UpdateOperation
         setupUpdateDefaults as _setupUpdateDefaults;
     }
 
-
     /**
      * Update the specified resource in the database.
      *