Skip to content

Commit

Permalink
Merge pull request #14 from muskie9/enhancement/youtubeBlock
Browse files Browse the repository at this point in the history
ENAHNCEMENT RecentVideosBlock
  • Loading branch information
muskie9 authored Jan 5, 2017
2 parents 38ef728 + 1b697fe commit 9181f64
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions code/blocks/RecentVideosBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

/**
* Class RecentVideosBlock
*
* @property int $Limit
* @property int $VideoPageID
* @method YouTubeIntegrationVideosPage $VideoPage
*/
class RecentVideosBlock extends Block
{
/**
* @var string
*/
private static $singular_name = 'Recent Videos Block';

/**
* @var string
*/
private static $plural_name = 'Recent Videos Blocks';

/**
* @var array
*/
private static $db = array(
'Limit' => 'Int',
);

/**
* @var array
*/
private static $has_one = array(
'VideoPage' => 'YouTubeIntegrationVideosPage',
);

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

/**
* @var
*/
private $recent_videos;

/**
* @return FieldList
*/
public function getCMSFields()
{
$fields = singleton('Block')->getCMSFields();

$fields->addFieldsToTab('Root.Main', array(
NumericField::create('Limit'),
));

$fields->addFieldToTab(
'Root.Main',
DropdownField::create('VideoPageID', 'Featured Video Page', YouTubeIntegrationVideosPage::get()->map())
->setEmptyString('')
);

return $fields;
}

/**
* @param null $member
* @return bool
*/
public function canCreate($member = null)
{
return parent::canCreate($member);
}

/**
* @param null $member
* @return bool
*/
public function canView($member = null)
{
return parent::canView($member);
}

/**
* @return mixed
*/
public function getRecentVideos()
{
if (!$this->recent_videos) {
$this->setRecentVideos();
}
return $this->recent_videos;
}

/**
* @return $this
*/
public function setRecentVideos()
{
$this->recent_videos = ($this->VideoPageID != 0)
? $this->VideoPage()->getVideosList()->limit($this->Limit)
: SilverStripeYouTubeVideo::get()->limit($this->Limit);
return $this;
}

}

0 comments on commit 9181f64

Please sign in to comment.