Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted to PSR-2 #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}