More video page fixes

Conflicts:

	openstack/code/PresentationCategoryPage.php
This commit is contained in:
Todd Morey 2014-11-04 15:44:52 +01:00 committed by Sebastian Marcet
parent 343420ad15
commit f9168bdaf2
5 changed files with 149 additions and 17 deletions

View File

@ -1,4 +1,5 @@
<?php
/**
* Copyright 2014 Openstack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
@ -21,8 +22,9 @@ class PresentationCategoryPage extends Page
'StillUploading' => 'Boolean'
);
static $has_one = array();
static $has_many = array(
'Presentations' => 'Presentation',
'Presentations' => 'Presentation',
'FeaturedVideos' => 'FeaturedVideo'
);
@ -33,18 +35,22 @@ class PresentationCategoryPage extends Page
function getCMSFields()
{
$fields = parent::getCMSFields();
$presentationsTable = new GridField('Presentations', 'Presentations', $this->Presentations());
$fields->addFieldToTab('Root.Presentations', $presentationsTable);
$presentationsTable = new GridField('Presentations', 'Presentations', $this->Presentations(),GridFieldConfig_RecordEditor::create(10));
$fields->addFieldToTab('Root.Content.Presentations', $presentationsTable);
// Summit Videos
$VideosUploadingField = new OptionSetField('StillUploading', 'Are videos still being uploaded?', array(
'1' => 'Yes - A message will be displayed.',
'0' => 'No'
));
$fields->addFieldToTab("Root.Content.Main", $VideosUploadingField, 'Content');
$featuredVideos = new DataObjectManager($this, 'FeaturedVideos', 'FeaturedVideo');
$featuredVideos = new GridField('FeaturedVideos', 'FeaturedVideos', $this->FeaturedVideos(),GridFieldConfig_RecordEditor::create(10));
$fields->addFieldToTab('Root.Content.FeaturedVideos', $featuredVideos);
return $fields;
}
@ -56,6 +62,7 @@ class PresentationCategoryPage_Controller extends Page_Controller
static $allowed_actions = array(
'presentation',
'featured',
'updateURLS' => 'admin'
);
@ -100,6 +107,28 @@ class PresentationCategoryPage_Controller extends Page_Controller
}
}
//Show the Presentation detail page using the PresentationCategoryPage_presentation.ss template
function featured()
{
if ($Presentation = $this->getPresentationByURLSegment(TRUE)) {
$Data = array(
'Presentation' => $Presentation
);
$this->Title = $Presentation->Name;
$this->Autoplay = Session::get('Autoplay');
// Clear autoplay so it only happens when you come directly from videos index
Session::set('Autoplay', FALSE);
//return our $Data to use on the page
return $this->Customise($Data);
} else {
//Presentation not found
return $this->httpError(404, 'Sorry that presentation could not be found');
}
}
function PresentationDayID($PresentationDay)
{
return trim($PresentationDay, ' ');
@ -125,15 +154,20 @@ class PresentationCategoryPage_Controller extends Page_Controller
//Get the current Presentation from the URL, if any
public function getPresentationByURLSegment()
public function getPresentationByURLSegment($featured = FALSE)
{
$Params = $this->getURLParams();
$Segment = convert::raw2sql($Params['ID']);
if ($Params['ID'] && $Presentation = DataObject::get_one('Presentation', "`URLSegment` = '" . $Segment . "' AND `PresentationCategoryPageID` = " . $this->ID)) {
if ($featured == FALSE && $Params['ID'] && $Presentation = DataObject::get_one('Presentation', "`URLSegment` = '" . $Segment . "' AND `PresentationCategoryPageID` = " . $this->ID)) {
return $Presentation;
} elseif ($featured == TRUE && $Params['ID'] && $FeaturedVideo = DataObject::get_one('FeaturedVideo', "`URLSegment` = '" . $Segment . "'")) {
return $FeaturedVideo;
}
}
function currentDay()
{
$day = Session::get('Day');
@ -144,7 +178,7 @@ class PresentationCategoryPage_Controller extends Page_Controller
function updateURLS()
{
$presentations = Presentation::get()->filter('PresentationCategoryPageID', $this->ID)->sort('StartTime', 'ASC');
$presentations = dataobject::get('Presentation', 'PresentationCategoryPageID = ' . $this->ID, 'StartTime ASC');
foreach ($presentations as $presentation) {
if ($presentation->URLSegment == NULL) {
$presentation->write();

View File

@ -14,7 +14,50 @@ class FeaturedVideo extends DataObject {
'PresentationCategoryPage' => 'PresentationCategoryPage'
);
function onBeforeWrite() {
parent::onBeforeWrite();
// If there is no URLSegment set, generate one from Title
if((!$this->URLSegment || $this->URLSegment == 'new-presentation') && $this->Title != 'New Presentation')
{
$this->URLSegment = SiteTree::generateURLSegment($this->Title);
}
else if($this->isChanged('URLSegment'))
{
// Make sure the URLSegment is valid for use in a URL
$segment = preg_replace('/[^A-Za-z0-9]+/','-',$this->URLSegment);
$segment = preg_replace('/-+/','-',$segment);
// If after sanitising there is no URLSegment, give it a reasonable default
if(!$segment) {
$segment = "presentation-".$this->ID;
}
$this->URLSegment = $segment;
}
// Ensure that this object has a non-conflicting URLSegment value by appending number if needed
$count = 2;
while($this->LookForExistingURLSegment($this->URLSegment))
{
$this->URLSegment = preg_replace('/-[0-9]+$/', null, $this->URLSegment) . '-' . $count;
$count++;
}
}
//Test whether the URLSegment exists already on another Video
function LookForExistingURLSegment($URLSegment)
{
return (DataObject::get_one('Company', "URLSegment = '" . $URLSegment ."' AND ID != " . $this->ID));
}
}
?>

View File

@ -21,15 +21,17 @@
<div class="container">
<!-- Start Videos -->
<div class="row">
<div class="col-lg-12">
<% control Presentations.GroupedBy(PresentationDay) %>
<div class="row">
<div class="col-lg-12">
<h2 id="day-{$Pos}">$PresentationDay</h2>
<div class="row">
<div class="col-lg-12">
<h2 id="day-{$Pos}">$PresentationDay</h2>
</div>
</div>
<div class="row">
<% control Children %>
<!-- Video Block -->
<% if YouTubeID %>
<div class="col-lg-3 col-md-3 col-sm-3 video-block">
@ -47,13 +49,18 @@
</a>
</div>
<% end_if %>
<% if MultipleOf(4) %>
</div>
<div class="row">
<% end_if %>
<% if Last %>
</div>
<% end_if %>
<% end_control %>
</div>
<% end_control %>
</div>
</div>
<!-- End Videos -->
</div>
<!-- End Page Content -->

View File

@ -37,6 +37,26 @@
<div class="container daily-recap-wrapper">
<div class="row">
<% control FeaturedVideos %>
<!-- If there is a YouTube ID -->
<% if YouTubeID %>
<div class="col-lg-3 col-md-3 col-sm-3 video-block">
<a href="{$Top.Link}featured/{$URLSegment}">
<div class="video-thumb">
<div class="thumb-play"></div>
<img class="video-thumb-img" src="//img.youtube.com/vi/{$YouTubeID}/0.jpg">
</div>
<p class="video-thumb-title">
$Name
</p>
</a>
</div>
<% else %>
<div class="col-lg-3 col-md-3 col-sm-3">
<div class="video-thumb">
<img class="video-thumb-img" src="/themes/openstack/images/no-video.jpg">
@ -45,6 +65,10 @@
Day {$Pos} - Coming Soon
</p>
</div>
<% end_if %>
<% end_control %>
</div>
</div>

View File

@ -0,0 +1,24 @@
<% require themedCSS(videos) %>
<% control Presentation %>
<div class="main-video-wrapper">
<iframe width="853" height="480" src="//www.youtube.com/embed/{$YouTubeID}?rel=0<% if Top.Autoplay %>&autoplay=1<% end_if %>" frameborder="0" allowfullscreen></iframe>
</div>
<div class="container single-video-details">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3 video-share">
<a href="https://twitter.com/share" data-related="jasoncosta" data-lang="en" data-size="large" data-count="none"><i class="fa fa-twitter"></i></a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<h3>$Name</h3>
</div>
</div>
</div>
<% end_control %>
<% include VideoThumbnails %>