Skip to content

Commit

Permalink
FEATURE initial modeling
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirish committed Sep 4, 2024
1 parent 00948e5 commit 82db9ad
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 6 deletions.
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{
"name": "dynamic/silverstripe-elemental-locations",
"description": "A locations block for Silverstripe. Display one or more locations on a map.",
"license": "BSD-3-Clause",
"type": "silverstripe-vendormodule",
"keywords": [
"silverstripe",
"CMS"
],
"license": "BSD-3-Clause",
"require": {
"dnadesign/silverstripe-elemental": "^4.8",
"dnadesign/silverstripe-elemental": "^5",
"silverstripe/linkfield": "^4.0",
"symbiote/silverstripe-addressable": "^5.0"
},
"require-dev": {
"silverstripe/recipe-testing": "^2",
"squizlabs/php_codesniffer": "^3.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Dynamic\\Elements\\Locations\\": "src/",
"Dynamic\\Elements\\Blog\\Locations\\": "tests/"
"Dynamic\\Elements\\\\Locations\\Test\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
32 changes: 32 additions & 0 deletions src/Admin/LocationsAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Dynamic\Elements\Locations\Admin;

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

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

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

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

namespace Dynamic\Elements\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 $Phone
* @property string $Email
* @property string $Fax
* @method DataList|Link[] Links()
* @method ManyManyList|LocationCategory[] Categories()
*/
class Location extends DataObject
{
/**
* @var string
*/
private static $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 for use with the Locations Element';

/**
* @var array
*/
private static $db = [
'Title' => 'Varchar(255)',
'Phone' => 'Varchar(40)',
'Email' => 'Varchar(255)',
'Fax' => 'Varchar(45)',
];

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

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

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

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

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

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

namespace Dynamic\Elements\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
*/
private static $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';

private static $db = [
'Title' => 'Varchar(255)',
];

/**
* @var array
*/
private static $belongs_many_many = [
'Locations' => Location::class,
];
}

0 comments on commit 82db9ad

Please sign in to comment.