-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from muskie9/enhancement/youtubeBlock
ENAHNCEMENT RecentVideosBlock
- Loading branch information
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |