Ingo, tx for replying
The series are DataObjects, i will post my code below.
The meaning of it all....I stream videos on an Internal Network ( among other stuff i present on the webpage ), so i provide a webpage for people to look trough the series and pick a episode to watch. Everybody loves the way it works ( tx SilverStripe guys ).
Offcourse i could stay with 2.3.7. but i want to move on.....
-----------------Code Video--------------------------
class Video extends DataObject {
static $db = array(
'Name' => 'Varchar',
'Server' => 'VarChar',
'Folder' => 'VarChar',
'Omschrijving' => 'Text',
'URLSegment' => 'Varchar(255)');
static $has_one = array(
'VideoPage' => 'VideoPage',
'Photo' => 'Image');
static $has_many = array(
'VideoCats' => 'VideoCat',
'VideoStreams' => 'VideoStream');
public function getCMSFields(){
return new FieldSet(
new TextField('Name'),
new TextField('Server'),
new TextField('Folder'),
new TextareaField('Omschrijving'),
new ImageField('Photo', 'COVER'),
new DataObjectManager(
$this,
'VideoCats',
'VideoCat',
array('Name' => 'Naam', )));
}
public function getThumb(){
if($this->PhotoID)
return $this->Photo()->CMSThumbnail();
else
return '(No Photo)';
}
public function getLinkingMode(){
if($this->URLSegment == Director::URLParam('Action')){
return 'current';
}
else{
return 'link';
}
}
public function onBeforeWrite(){
if($this->Name){
$this->URLSegment = SiteTree::GenerateURLSegment($this->Name);
if($object = DataObject::get_one($this->ClassName, "URLSegment='".$this->URLSegment."' AND ID !=".$this->ID)){
$this->URLSegment = $this->URLSegment.'-'.$this->ID;
}
} else {
$this->URLSegment = SiteTree::GenerateURLSegment($this->ClassName.'-'.$this->ID);
}
parent::onBeforeWrite();
}
}
---------------------- end of code Video ------------------
---------------------- code VideoCat ----------------------
class VideoCat extends DataObject {
static $db = array('Name' => 'Varchar');
static $has_one = array('Video' => 'Video');
static $has_many = array('VideoStreams' => 'VideoStream');
function getCMSFields() {
return new FieldSet(
new TextField('Name', 'Categorie '),
new DataObjectManager(
$this,
'VideoStreams',
'VideoStream',
array('Name'=>'Naam')));
}
}
------------------- end of code VideoCat ---------------------------
------------------- code VideoStream --------------------------------
class VideoStream extends DataObject {
static $db = array('Name' => 'Varchar');
static $has_one = array(
'Video'=> 'Video',
'VideoCat' => 'VideoCat');
function getCMSFields() {
return new FieldSet(
new TextField('Name', 'exacte naam van het file, ZONDER extensie'));
}
}
--------------- end of Code VideoStream --------------------------------
--------------- Code VideoPage -----------------------------------------
class VideoPage extends Page {
static $has_many = array('Videos' => 'Video');
function getCMSFields() {
$fields = parent::getCMSFields();
$dataobjectmanager = new HasManyDataObjectManager(
$this,
'Videos',
'Video',
array('Thumb' => 'Photo', 'Name' => 'Name','Server' => 'Server', 'Folder' => 'Folder', 'Omschrijving' => 'Omschrijving'),
'getCMSFields_forPopup'
);
$dataobjectmanager->setPluralTitle("een video");
$fields->addFieldToTab("Root.Content.Video", $dataobjectmanager);
$fields->removeFieldFromTab("Root.Content.Main","Content");
return $fields;
}
class VideoPage_Controller extends Page_Controller {
function init(){
parent::init();
Requirements::JavaScript('/mysite/javascript/jquery.min.js');
Requirements::JavaScript('/mysite/javascript/prototype.js');
}
public function getIndividualVideo(){
if($URLAction = Director::URLParam('Action')){
$VideoID = Convert::raw2xml($URLAction);
if($VideoID ){
return DataObject::get_one('Video', "URLSegment='".$VideoID."'");
}
}
}
}
---------------------- end of Code VideoPage --------------------------