diff --git a/openstack/code/PresentationCategoryPage.php b/openstack/code/PresentationCategoryPage.php index 46e5d3d..942611f 100644 --- a/openstack/code/PresentationCategoryPage.php +++ b/openstack/code/PresentationCategoryPage.php @@ -1,4 +1,5 @@ '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(); diff --git a/openstack/code/summit/FeaturedVideo.php b/openstack/code/summit/FeaturedVideo.php index 46f5bd0..b59afde 100644 --- a/openstack/code/summit/FeaturedVideo.php +++ b/openstack/code/summit/FeaturedVideo.php @@ -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)); } + + +} + + + + ?> diff --git a/themes/openstack/templates/Layout/Includes/VideoThumbnails.ss b/themes/openstack/templates/Layout/Includes/VideoThumbnails.ss index 0491283..7a9b1b1 100644 --- a/themes/openstack/templates/Layout/Includes/VideoThumbnails.ss +++ b/themes/openstack/templates/Layout/Includes/VideoThumbnails.ss @@ -21,15 +21,17 @@