Skip to content

Commit

Permalink
Converted to PSR-2
Browse files Browse the repository at this point in the history
  • Loading branch information
helpfulrobot committed Dec 23, 2015
1 parent acf3bb5 commit 99be72c
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 105 deletions.
133 changes: 70 additions & 63 deletions code/EventLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,84 @@
*
* @package silverstripe-eventlocations
*/
class EventLocation extends DataObject {
class EventLocation extends DataObject
{

private static $db = array(
'Title' => 'Varchar(255)',
'Capacity' => 'Int'
);
private static $db = array(
'Title' => 'Varchar(255)',
'Capacity' => 'Int'
);

private static $extensions = array(
'Addressable'
);
private static $extensions = array(
'Addressable'
);

private static $summary_fields = array(
'Title' => 'Title',
'Capacity' => 'Capacity',
'FullAddress' => 'Address'
);
private static $summary_fields = array(
'Title' => 'Title',
'Capacity' => 'Capacity',
'FullAddress' => 'Address'
);

private static $searchable_fields = array(
'Title'
);
private static $searchable_fields = array(
'Title'
);

public function getCMSFields(){
$fields = parent::getCMSFields();
public function getCMSFields()
{
$fields = parent::getCMSFields();

if(!class_exists('EventRegistration')){
$fields->removeByName('Capacity');
}
return $fields;
}
if (!class_exists('EventRegistration')) {
$fields->removeByName('Capacity');
}
return $fields;
}

public function summaryFields(){
$fields = parent::summaryFields();
if(!class_exists('EventRegistration')){
unset($fields['Capacity']);
}
return $fields;
}
public function summaryFields()
{
$fields = parent::summaryFields();
if (!class_exists('EventRegistration')) {
unset($fields['Capacity']);
}
return $fields;
}


/**
* @param Member $member
* @return boolean
*/
public function canView($member = null) {
return Permission::check('CMS_ACCESS_EventLocationAdmin', 'any', $member);
}

/**
* @param Member $member
* @return boolean
*/
public function canView($member = null)
{
return Permission::check('CMS_ACCESS_EventLocationAdmin', 'any', $member);
}

/**
* @param Member $member
* @return boolean
*/
public function canEdit($member = null) {
return Permission::check('CMS_ACCESS_EventLocationAdmin', 'any', $member);
}
/**
* @param Member $member
* @return boolean
*/
public function canEdit($member = null)
{
return Permission::check('CMS_ACCESS_EventLocationAdmin', 'any', $member);
}

/**
* @param Member $member
* @return boolean
*/
public function canDelete($member = null) {
return Permission::check('CMS_ACCESS_EventLocationAdmin', 'any', $member);
}
/**
* @param Member $member
* @return boolean
*/
public function canDelete($member = null)
{
return Permission::check('CMS_ACCESS_EventLocationAdmin', 'any', $member);
}

/**
* @todo Should canCreate be a static method?
*
* @param Member $member
* @return boolean
*/
public function canCreate($member = null) {
return Permission::check('CMS_ACCESS_EventLocationAdmin', 'any', $member);
}
}
/**
* @todo Should canCreate be a static method?
*
* @param Member $member
* @return boolean
*/
public function canCreate($member = null)
{
return Permission::check('CMS_ACCESS_EventLocationAdmin', 'any', $member);
}
}
16 changes: 8 additions & 8 deletions code/EventLocationAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*
* @package silverstripe-eventlocations
*/
class EventLocationAdmin extends ModelAdmin {
class EventLocationAdmin extends ModelAdmin
{

private static $title = 'Event Locations';
private static $menu_title = 'Event Locations';
private static $url_segment = 'event-locations';
private static $title = 'Event Locations';
private static $menu_title = 'Event Locations';
private static $url_segment = 'event-locations';

private static $managed_models = 'EventLocation';
private static $model_importers = array();

}
private static $managed_models = 'EventLocation';
private static $model_importers = array();
}
68 changes: 34 additions & 34 deletions code/LocationDateTimeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@
*
* @package silverstripe-eventlocations
*/
class LocationDateTimeExtension extends DataExtension {
class LocationDateTimeExtension extends DataExtension
{

private static $has_one = array(
'Location' => 'EventLocation'
);
private static $has_one = array(
'Location' => 'EventLocation'
);

public function updateCMSFields(FieldList $fields) {
$locations = function(){
return EventLocation::get()->map()->toArray();
};
public function updateCMSFields(FieldList $fields)
{
$locations = function () {
return EventLocation::get()->map()->toArray();
};

$dropdown = DropdownField::create(
'LocationID',
_t('EventLocations.LOCATION', 'Location'),
$locations()
)->setHasEmptyDefault(true);
$dropdown = DropdownField::create(
'LocationID',
_t('EventLocations.LOCATION', 'Location'),
$locations()
)->setHasEmptyDefault(true);

if(class_exists('QuickAddNewExtension')){
$dropdown->useAddNew('EventLocation', $locations);
}
if (class_exists('QuickAddNewExtension')) {
$dropdown->useAddNew('EventLocation', $locations);
}

if($this->owner->hasField('Capacity')){
Requirements::javascript(THIRDPARTY_DIR . '/jquery-metadata/jquery.metadata.js');
Requirements::add_i18n_javascript('eventlocations/javascript/lang');
Requirements::javascript('eventlocations/javascript/LocationDateTimeCms.js');
if ($this->owner->hasField('Capacity')) {
Requirements::javascript(THIRDPARTY_DIR . '/jquery-metadata/jquery.metadata.js');
Requirements::add_i18n_javascript('eventlocations/javascript/lang');
Requirements::javascript('eventlocations/javascript/LocationDateTimeCms.js');

$capacities = array();
foreach ($locations as $location) {
if ($location->Capacity) {
$capacities[$location->ID] = (int) $location->Capacity;
}
}
$dropdown->addExtraClass('{ capacities: ' . Convert::array2json($capacities) . ' }');
}
$fields->insertBefore($dropdown, 'StartDate');
}

}
$capacities = array();
foreach ($locations as $location) {
if ($location->Capacity) {
$capacities[$location->ID] = (int) $location->Capacity;
}
}
$dropdown->addExtraClass('{ capacities: ' . Convert::array2json($capacities) . ' }');
}
$fields->insertBefore($dropdown, 'StartDate');
}
}

0 comments on commit 99be72c

Please sign in to comment.