Skip to content

Commit

Permalink
Merge pull request #60 from muskie9/statics
Browse files Browse the repository at this point in the history
Update statics from public to private
  • Loading branch information
muskie9 committed Jul 20, 2015
2 parents 7742e23 + acc033c commit dd431b2
Show file tree
Hide file tree
Showing 5 changed files with 374 additions and 346 deletions.
260 changes: 135 additions & 125 deletions code/Location.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
<?php

class Location extends DataObject implements PermissionProvider{

static $db = array(
'Title' => 'Varchar(255)',
'Featured' => 'Boolean',
'Website' => 'Varchar(255)',
'Phone' => 'Varchar(40)',
'EmailAddress' => 'Varchar(255)',
'ShowInLocator' => 'Boolean',
);

static $has_one = array(
'Category' => 'LocationCategory'
);

static $casting = array(
'distance' => 'Int'
);

static $default_sort = 'Title';

static $defaults = array(
'ShowInLocator' => true
);

public static $singular_name = "Location";
public static $plural_name = "Locations";

// api access via Restful Server module
static $api_access = true;
class Location extends DataObject implements PermissionProvider
{

private static $db = array(
'Title' => 'Varchar(255)',
'Featured' => 'Boolean',
'Website' => 'Varchar(255)',
'Phone' => 'Varchar(40)',
'EmailAddress' => 'Varchar(255)',
'ShowInLocator' => 'Boolean',
);

private static $has_one = array(
'Category' => 'LocationCategory'
);

private static $casting = array(
'distance' => 'Int'
);

private static $default_sort = 'Title';

private static $defaults = array(
'ShowInLocator' => true
);

private static $singular_name = "Location";
private static $plural_name = "Locations";

// api access via Restful Server module
private static $api_access = true;

// search fields for Model Admin
private static $searchable_fields = array(
Expand All @@ -46,117 +47,126 @@ class Location extends DataObject implements PermissionProvider{
'Phone',
'EmailAddress'
);
// columns for grid field
static $summary_fields = array(
'Title',
'Address',
'Suburb',
'State',
'Postcode',
'Country',
'Category.Name',
'ShowInLocator.NiceAsBoolean',
'Featured.NiceAsBoolean',

// columns for grid field
private static $summary_fields = array(
'Title',
'Address',
'Suburb',
'State',
'Postcode',
'Country',
'Category.Name',
'ShowInLocator.NiceAsBoolean',
'Featured.NiceAsBoolean',
'Coords'
);
);

// Coords status for $summary_fields
public function getCoords() {
return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
}
// Coords status for $summary_fields
public function getCoords()
{
return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
}

// custom labels for fields
function fieldLabels($includerelations = true) {
$labels = parent::fieldLabels();

$labels['Title'] = 'Name';
$labels['Suburb'] = "City";
$labels['Postcode'] = 'Postal Code';
$labels['ShowInLocator'] = 'Show';
function fieldLabels($includerelations = true)
{
$labels = parent::fieldLabels();

$labels['Title'] = 'Name';
$labels['Suburb'] = "City";
$labels['Postcode'] = 'Postal Code';
$labels['ShowInLocator'] = 'Show';
$labels['ShowInLocator.NiceAsBoolean'] = 'Show';
$labels['Category.Name'] = 'Category';
$labels['EmailAddress'] = 'Email';
$labels['Featured.NiceAsBoolean'] = 'Featured';
$labels['Category.Name'] = 'Category';
$labels['EmailAddress'] = 'Email';
$labels['Featured.NiceAsBoolean'] = 'Featured';
$labels['Coords'] = 'Coords';

return $labels;
}

public function getCMSFields() {

$fields = parent::getCMSFields();

// remove Main tab
$fields->removeByName('Main');

// create and populate Info tab
$fields->addFieldsToTab('Root.Info', array(
HeaderField::create('InfoHeader', 'Contact Information'),
TextField::create('Website'),
TextField::create('EmailAddress'),
TextField::create('Phone')
));

// change label of Suburb from Addressable to City
$fields->removeByName('Suburb');
$fields->insertBefore(TextField::create('Suburb', 'City'), 'State');

// If categories have been created, show category drop down
if (LocationCategory::get()->Count() > 0) {
$fields->insertAfter(DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))->setEmptyString('-- select --'), 'Phone');
}

// move Title and ShowInLocator fields to Address tab from Addressable
$fields->insertAfter(TextField::create('Title'), 'AddressHeader');
$fields->insertAfter(CheckboxField::create('Featured', 'Featured'), 'Title');
$fields->insertAfter(CheckboxField::create('ShowInLocator', 'Show on Map'), 'Country');
return $labels;
}

public function getCMSFields()
{

$fields = parent::getCMSFields();

// remove Main tab
$fields->removeByName('Main');

// create and populate Info tab
$fields->addFieldsToTab('Root.Info', array(
HeaderField::create('InfoHeader', 'Contact Information'),
TextField::create('Website'),
TextField::create('EmailAddress'),
TextField::create('Phone')
));

// change label of Suburb from Addressable to City
$fields->removeByName('Suburb');
$fields->insertBefore(TextField::create('Suburb', 'City'), 'State');

// If categories have been created, show category drop down
if (LocationCategory::get()->Count() > 0) {
$fields->insertAfter(DropDownField::create('CategoryID', 'Category',
LocationCategory::get()->map('ID', 'Title'))->setEmptyString('-- select --'), 'Phone');
}

// move Title and ShowInLocator fields to Address tab from Addressable
$fields->insertAfter(TextField::create('Title'), 'AddressHeader');
$fields->insertAfter(CheckboxField::create('Featured', 'Featured'), 'Title');
$fields->insertAfter(CheckboxField::create('ShowInLocator', 'Show on Map'), 'Country');

// allow to be extended via DataExtension
$this->extend('updateCMSFields', $fields);

return $fields;
}
$this->extend('updateCMSFields', $fields);

public function validate() {
return $fields;
}

public function validate()
{
$result = parent::validate();

return $result;
}

/**
* @param Member $member
* @return boolean
*/
public function canView($member = false) {
//return Permission::check('Location_VIEW');
return true;
}

public function canEdit($member = false) {
return Permission::check('Location_EDIT');
}

public function canDelete($member = false) {
return Permission::check('Location_DELETE');
}

public function canCreate($member = false) {
return Permission::check('Location_CREATE');
}

public function providePermissions() {
return array(
//'Location_VIEW' => 'Read a Location',
'Location_EDIT' => 'Edit a Location',
'Location_DELETE' => 'Delete a Location',
'Location_CREATE' => 'Create a Location'
);
}

public function onBeforeWrite(){
/**
* @param Member $member
* @return true
*/
public function canView($member = false)
{
return true;
}

public function canEdit($member = false)
{
return Permission::check('Location_EDIT');
}

public function canDelete($member = false)
{
return Permission::check('Location_DELETE');
}

public function canCreate($member = false)
{
return Permission::check('Location_CREATE');
}

public function providePermissions()
{
return array(
'Location_EDIT' => 'Edit a Location',
'Location_DELETE' => 'Delete a Location',
'Location_CREATE' => 'Create a Location'
);
}

public function onBeforeWrite()
{

parent::onBeforeWrite();
}

}
49 changes: 26 additions & 23 deletions code/LocationAdmin.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
<?php
class LocationAdmin extends ModelAdmin {

static $managed_models = array(
'Location',
'LocationCategory'
);

static $model_importers = array(
'Location' => 'LocationCsvBulkLoader',
'LocationCategory' => 'CsvBulkLoader'

class LocationAdmin extends ModelAdmin
{

private static $managed_models = array(
'Location',
'LocationCategory'
);

static $menu_title = 'Locator';
static $url_segment = 'locator';

public function getExportFields() {
private static $model_importers = array(
'Location' => 'LocationCsvBulkLoader',
'LocationCategory' => 'CsvBulkLoader'
);

private static $menu_title = 'Locator';
private static $url_segment = 'locator';

public function getExportFields()
{
return array(
'Title' => 'Name',
'Address' => 'Address',
'Suburb' => 'City',
'State' => 'State',
'Postcode' => 'Postal Code',
'Country' => 'Country',
'Website' => 'Website',
'Phone' => 'Phone',
'Fax' => 'Fax',
'EmailAddress' => 'Email Address',
'ShowInLocator' => 'Show',
'Lat' => 'Lat',
'Lng' => 'Lng'
'Postcode' => 'Postal Code',
'Country' => 'Country',
'Website' => 'Website',
'Phone' => 'Phone',
'Fax' => 'Fax',
'EmailAddress' => 'Email Address',
'ShowInLocator' => 'Show',
'Lat' => 'Lat',
'Lng' => 'Lng'
);
}
}
31 changes: 16 additions & 15 deletions code/LocationCategory.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php

class LocationCategory extends DataObject {

static $db = array(
'Name' => 'Varchar(100)'
);

static $has_many = array(
'Locations' => 'Location'
);

public static $singular_name = "Category";
public static $plural_name = "Categories";

private static $default_sort = 'Name';

class LocationCategory extends DataObject
{

private static $db = array(
'Name' => 'Varchar(100)'
);

private static $has_many = array(
'Locations' => 'Location'
);

private static $singular_name = "Category";
Private static $plural_name = "Categories";

private static $default_sort = 'Name';

}
Loading

0 comments on commit dd431b2

Please sign in to comment.