Skip to content

Commit

Permalink
FEATURE initial modeling (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirish authored Sep 5, 2024
1 parent 56542a7 commit 3c5e3ef
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 13 deletions.
31 changes: 18 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
{
"name": "dynamic/silverstripe-locations",
"description": "A locations module for silverstripe.",
"license": "BSD-3-Clause",
"type": "silverstripe-vendormodule",
"keywords": [
"silverstripe",
"CMS",
"locations"
],
"license": "BSD-3-Clause",
"authors": [
{
"name": "Dynamic",
"email": "[email protected]",
"homepage": "https://www.dynamicagency.com"
}
],
"require": {
"silverstripe/admin": "^2.0"
"silverstripe/recipe-cms": "^5.0",
"silverstripe/linkfield": "^4.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"silverstripe/frameworktest": "^1",
"squizlabs/php_codesniffer": "^3.7",
"silverstripe/standards": "^1",
"phpstan/extension-installer": "^1.3"
"dnadesign/silverstripe-elemental": "^5",
"silverstripe/recipe-testing": "^3"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Dynamic\\Locations\\": "src/",
"Dynamic\\Locations\\Tests\\": "tests/"
}
},
"extra": {
"expose": [
"client/dist"
]
},
"minimum-stability": "dev",
"prefer-stable": true
"branch-alias": {
"dev-master": "1.x-dev"
}
}
}
35 changes: 35 additions & 0 deletions src/Admin/LocationsAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Dynamic\Elements\Locations\Admin;

use SilverStripe\Admin\ModelAdmin;
use Dynamic\Locations\Model\Location;
use Dynamic\Locations\Model\LocationCategory;

/**
* Class \Dynamic\Elements\Locations\Admin\LocationsAdmin
*
*/
class LocationsAdmin extends ModelAdmin
{
/**
* @var array
* @config
*/
private static array $managed_models = [
Location::class,
LocationCategory::class,
];

/**
* @var string
* @config
*/
private static string $menu_title = 'Locations';

/**
* @var string
* @config
*/
private static string $url_segment = 'locations';
}
95 changes: 95 additions & 0 deletions src/Model/Location.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace Dynamic\Locations\Model;

use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\LinkField\Form\MultiLinkField;

/**
* Class \Dynamic\Elements\Locations\Model\Location
*
* @property string $Title
* @property string $Content
* @method DataList|Link[] Links()
* @method ManyManyList|LocationCategory[] Categories()
*/
class Location extends DataObject
{
/**
* @var string
* @config
*/
private static string $table_name = 'Location';

/**
* @var string
* @config
*/
private static string $singular_name = 'Location';

/**
* @var string
* @config
*/
private static string $plural_name = 'Locations';

/**
* @var string
* @config
*/
private static string $description = 'A Location DataObject for use with the Locations Element';

/**
* @var array
* @config
*/
private static array $db = [
'Title' => 'Varchar(255)',
'Content' => 'HTMLText',
];

/**
* @var array
* @config
*/
private static array $has_many = [
'Links' => Link::class . '.Owner',
];

/**
* @var array
* @config
*/
private static array $many_many = [
'Categories' => LocationCategory::class,
];

/**
* @var array
* @config
*/
private static array $owns = [
'Links',
];

/**
* @return FieldList
*/
public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->removeByName(['Links']);

$fields->addFieldsToTab(
'Root.Main',
[
MultiLinkField::create('Links'),
]
);
});

return parent::getCMSFields();
}
}
54 changes: 54 additions & 0 deletions src/Model/LocationCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Dynamic\Locations\Model;

use SilverStripe\ORM\DataObject;

/**
* Class \Dynamic\Elements\Locations\Model\LocationCategory
*
* @property string $Title
* @method ManyManyList|Location[] Locations()
*/
class LocationCategory extends DataObject
{
/**
* @var string
* @config
*/
private static string $table_name = 'LocationCategory';

/**
* @var string
* @config
*/
private static string $singular_name = 'Category';

/**
* @var string
* @config
*/
private static string $plural_name = 'Categories';

/**
* @var string
* @config
*/
private static string $description = 'A category to use with Location records';

/**
* @var array
* @config
*/
private static array $db = [
'Title' => 'Varchar(255)',
];

/**
* @var array
* @config
*/
private static array $belongs_many_many = [
'Locations' => Location::class,
];
}
25 changes: 25 additions & 0 deletions tests/Model/LocationCategoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Dynamic\Locations\Test;

use SilverStripe\Forms\FieldList;
use SilverStripe\Dev\SapphireTest;
use Dynamic\Locations\Model\LocationCategory;

class LocationCategoryTest extends SapphireTest
{
/**
* @var string
*/
protected static $fixture_file = 'location-category.yml';

/**
* Test the CMS Fields
*/
public function testGetCMSFields()
{
$object = $this->objFromFixture(LocationCategory::class, 'one');
$fields = $object->getCMSFields();
$this->assertInstanceOf(FieldList::class, $fields);
}
}
25 changes: 25 additions & 0 deletions tests/Model/LocationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Dynamic\Locations\Test;

use SilverStripe\Forms\FieldList;
use SilverStripe\Dev\SapphireTest;
use Dynamic\Locations\Model\Location;

class LocationTest extends SapphireTest
{
/**
* @var string
*/
protected static $fixture_file = 'location.yml';

/**
* Test the CMS Fields
*/
public function testGetCMSFields()
{
$object = $this->objFromFixture(Location::class, 'one');
$fields = $object->getCMSFields();
$this->assertInstanceOf(FieldList::class, $fields);
}
}
3 changes: 3 additions & 0 deletions tests/Model/location-category.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dynamic\Locations\Model\LocationCategory:
one:
Title: "Location Category One"
3 changes: 3 additions & 0 deletions tests/Model/location.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dynamic\Locations\Model\Location:
one:
Title: "Location One"

0 comments on commit 3c5e3ef

Please sign in to comment.