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

Clean up #63

Merged
merged 1 commit into from
Sep 15, 2016
Merged
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
26 changes: 1 addition & 25 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
---
Name: FlexSlider
---
SlideImage:
db:
Name: Varchar(255)
Headline: Varchar(255)
Description: Text
SortOrder: Int
ShowSlide: Boolean
has_one:
Image: Image
Page: Page
PageLink: SiteTree
singular_name:
- Slide
plural_name:
- Slides
default_order:
- SortOrder
summary_fields:
Image.CMSThumbnail: Image
Name: Name
searchable_fields:
Name: Name
Title: Title
Description: Description
---
74 changes: 74 additions & 0 deletions code/FlexSlider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,53 @@

class FlexSlider extends DataExtension
{
/**
* @var array
*/
public static $db = array(
'Animation' => "Enum('slide, fade', 'slide')",
'Loop' => 'Boolean',
'Animate' => 'Boolean',
'ThumbnailNav' => 'Boolean',
);

/**
* @var array
*/
public static $has_many = array(
'Slides' => 'SlideImage',
);

/**
* @var array
*/
public static $defaults = array(
'Loop' => '1',
'Animate' => '1',
);

/**
*
*/
public function populateDefaults()
{
parent::populateDefaults();
$this->Loop = 1;
$this->Animate = 1;
}

/**
* @param FieldList $fields
*/
public function updateCMSFields(FieldList $fields)
{
$fields->removeByName(array(
'Animation',
'Loop',
'Animate',
'ThumbnailNav',
));

// Slides
if ($this->owner->ID) {
$config = GridFieldConfig_RecordEditor::create();
Expand Down Expand Up @@ -57,8 +79,60 @@ public function updateCMSFields(FieldList $fields)
}
}

/**
* @return DataList
*/
public function SlideShow()
{
return $this->owner->Slides()->filter(array('ShowSlide' => 1))->sort('SortOrder');
}

/**
* add requirements to Page_Controller init()
*/
public function contentcontrollerInit()
{
// Flexslider options
$animate = ($this->owner->Animate) ? 'true' : 'false';
$loop = ($this->owner->Loop) ? 'true' : 'false';
$sync = ($this->owner->ThumbnailNav == true) ? "sync: '#carousel'," : '';
$before = (method_exists($this->owner->ClassName, 'flexSliderBeforeAction'))
? $this->owner->flexSliderBeforeAction()
: 'function(){}';
$after = (method_exists($this->owner->ClassName, 'flexSliderAfterAction'))
? $this->owner->flexSliderAfterAction()
: 'function(){}';
$speed = (method_exists($this->owner->ClassName, 'setFlexSliderSpeed'))
? $this->owner->setFlexSliderSpeed()
: 7000;

// only call custom script if page has Slides and DataExtension
if (Object::has_extension($this->owner->ClassName, 'FlexSlider')) {
if ($this->owner->Slides()->exists()) {
Requirements::customScript("
(function($) {
$(document).ready(function(){
$('.flexslider').flexslider({
slideshow: ".$animate.",
animation: '".$this->owner->Animation."',
animationLoop: ".$loop.",
controlNav: true,
directionNav: true,
prevText: '',
nextText: '',
pauseOnAction: true,
pauseOnHover: true,
".$sync."
start: function(slider){
$('body').removeClass('loading');
},
before: ".$before.',
after: '.$after.',
slideshowSpeed: '.$speed.'
});
});
}(jQuery));');
}
}
}
}
52 changes: 8 additions & 44 deletions code/FlexSliderExtension.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,15 @@
<?php

/**
* Class FlexSliderExtension
*
* @deprecated 1.0.0 This class's methods have been moved to {@link FlexSlider}
*/
class FlexSliderExtension extends Extension
{
public function onAfterInit()
public function __construct()
{

// Flexslider options
$animate = ($this->owner->Animate) ? 'true' : 'false';
$loop = ($this->owner->Loop) ? 'true' : 'false';
$sync = ($this->owner->ThumbnailNav == true) ? "sync: '#carousel'," : '';
$before = (method_exists($this->owner->ClassName, 'flexSliderBeforeAction'))
? $this->owner->flexSliderBeforeAction()
: 'function(){}';
$after = (method_exists($this->owner->ClassName, 'flexSliderAfterAction'))
? $this->owner->flexSliderAfterAction()
: 'function(){}';
$speed = (method_exists($this->owner->ClassName, 'setFlexSliderSpeed'))
? $this->owner->setFlexSliderSpeed()
: 7000;

// only call custom script if page has Slides and DataExtension
if (Object::has_extension($this->owner->data()->ClassName, 'FlexSlider')) {
if ($this->owner->data()->Slides()->exists()) {
Requirements::customScript("
(function($) {
$(document).ready(function(){
$('.flexslider').flexslider({
slideshow: ".$animate.",
animation: '".$this->owner->Animation."',
animationLoop: ".$loop.",
controlNav: true,
directionNav: true,
prevText: '',
nextText: '',
pauseOnAction: true,
pauseOnHover: true,
".$sync."
start: function(slider){
$('body').removeClass('loading');
},
before: ".$before.',
after: '.$after.',
slideshowSpeed: '.$speed.'
});
});
}(jQuery));');
}
}
trigger_error('Class no longer used, please remove references to this class from any extension declarations.', E_USER_NOTICE);
parent::__construct();
}
}
82 changes: 81 additions & 1 deletion code/SlideImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,68 @@

class SlideImage extends DataObject implements PermissionProvider
{
//TODO: move to config.yml
/**
* @var string
*/
private static $singular_name = 'Slide';

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

/**
* @var array
*/
private static $db = array(
'Name' => 'Varchar(255)',
'Headline' => 'Varchar(255)',
'Description' => 'Text',
'SortOrder' => 'Int',
'ShowSlide' => 'Boolean',
);

/**
* @var array
*/
private static $has_one = array(
'Image' => 'Image',
'Page' => 'Page',
'PageLink' => 'SiteTree',
);

/**
* @var string
*/
private static $default_sort = 'SortOrder';

/**
* @var array
*/
private static $defaults = array(
'ShowSlide' => true,
);

/**
* @var array
*/
private static $summary_fields = array(
'Image.CMSThumbnail' => 'Image',
'Name' => 'Name',
);

/**
* @var array
*/
private static $searchable_fields = array(
'Name',
'Headline',
'Description',
);

/**
* @return FieldList
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();
Expand Down Expand Up @@ -40,6 +97,9 @@ public function getCMSFields()
return $fields;
}

/**
* @return ValidationResult
*/
public function validate()
{
$result = parent::validate();
Expand All @@ -55,6 +115,9 @@ public function validate()
return $result;
}

/**
* @return array
*/
public function providePermissions()
{
return array(
Expand All @@ -63,21 +126,38 @@ public function providePermissions()
'Slide_CREATE' => 'Slide Create',
);
}

/**
* @param null $member
* @return bool|int
*/
public function canCreate($member = null)
{
return Permission::check('Slide_CREATE');
}

/**
* @param null $member
* @return bool|int
*/
public function canEdit($member = null)
{
return Permission::check('Slide_EDIT');
}

/**
* @param null $member
* @return bool|int
*/
public function canDelete($member = null)
{
return Permission::check('Slide_DELETE');
}

/**
* @param null $member
* @return bool
*/
public function canView($member = null)
{
return true;
Expand Down
4 changes: 0 additions & 4 deletions docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ In your `mysite/_config/config.yml` add the following to the desired page type o
Page:
extensions:
- FlexSlider
Page_Controller:
extensions:
- FlexSliderExtension
```

Alternatively you could add the following to your `mysite/_config.php` file:

```
Page::add_extension('FlexSlider');
Page_Controller::add_extension('FlexSliderExtension')
```

After attaching the DataExtension to your page type or DataObject run a `dev/build` then `?flush=all`.
Expand Down