From bcf7bc6ae1586a2186147214918a00951cffc5a2 Mon Sep 17 00:00:00 2001 From: Marco Hermo Date: Sat, 8 Jun 2019 18:59:33 +1200 Subject: [PATCH] Model: Elevation and Items --- composer.json | 3 ++- src/Admins/SearchAdmin.php | 27 ++++++++++++++++++++++++++- src/Models/ElevatedItem.php | 26 ++++++++++++++++++++++++++ src/Models/Elevation.php | 20 ++++++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/Models/ElevatedItem.php create mode 100644 src/Models/Elevation.php diff --git a/composer.json b/composer.json index 86c12b48..754f7373 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "silverstripe/queuedjobs": "^4", "solarium/solarium": "^4.2", "minimalcode/search": "^1.0", - "guzzlehttp/guzzle": "^6.3" + "guzzlehttp/guzzle": "^6.3", + "symbiote/silverstripe-gridfieldextensions": "^3" }, "require-dev": { "phpunit/phpunit": "^5.7", diff --git a/src/Admins/SearchAdmin.php b/src/Admins/SearchAdmin.php index 03d6c01c..ba1e0afc 100644 --- a/src/Admins/SearchAdmin.php +++ b/src/Admins/SearchAdmin.php @@ -2,8 +2,12 @@ namespace Firesphere\SolrSearch\Admins; +use Firesphere\SolrSearch\Forms\GridFieldOrderableSearch; use Firesphere\SolrSearch\Models\SearchClass; +use Firesphere\SolrSearch\Models\Elevation; +use Firesphere\SolrSearch\Models\ElevatedItem; use SilverStripe\Admin\ModelAdmin; +use Symbiote\GridFieldExtensions\GridFieldOrderableRows; /** * Class \Firesphere\SolrSearch\Admins\SearchAdmin @@ -12,7 +16,9 @@ class SearchAdmin extends ModelAdmin { private static $managed_models = [ - SearchClass::class + SearchClass::class, + Elevation::class, + ElevatedItem::class, ]; private static $menu_icon_class = 'font-icon-search'; @@ -20,5 +26,24 @@ class SearchAdmin extends ModelAdmin private static $url_segment = 'searchadmin'; private static $menu_title = 'Search'; + + public function getEditForm($id = null, $fields = null) + { + $oldImportFrom = $this->showImportForm; + $this->showImportForm = false; + /** @var GridField $gridField */ + $form = parent::getEditForm($id, $fields); + $this->showImportForm = $oldImportFrom; + + if ($this->modelClass === ElevatedItem::class) { + $gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass)); + + $gridField + ->getConfig() + ->addComponent(new GridFieldOrderableRows('Rank')); + } + + return $form; + } } /** **/ diff --git a/src/Models/ElevatedItem.php b/src/Models/ElevatedItem.php new file mode 100644 index 00000000..96f6be92 --- /dev/null +++ b/src/Models/ElevatedItem.php @@ -0,0 +1,26 @@ + 'Int', + 'Title' => 'Varchar(255)', + 'ObjectClass' => 'Varchar(255)', + 'ObjectID' => 'Int', + 'SolrID' => 'Varchar(255)', + 'Include' => 'Boolean(1)', + 'Exclude' => 'Boolean(0)', + ]; + + private static $belongs_many_many = [ + 'Keywords' => Elevation::class, + ]; + + private static $summary_fields = ['Title', 'Rank', 'ObjectClass', 'SolrID', 'Include', 'Exclude']; +} diff --git a/src/Models/Elevation.php b/src/Models/Elevation.php new file mode 100644 index 00000000..5f6d6965 --- /dev/null +++ b/src/Models/Elevation.php @@ -0,0 +1,20 @@ + 'Varchar(255)', + ]; + + private static $many_many = [ + 'Items' => ElevatedItem::class, + ]; + + private static $summary_fields = ['ID', 'Keyword']; +}