Cheers man that was pretty helpful. still some problems though.
putting the script inside Requirements::customScript SS complains about a bunch of syntax errors so i put it in
Requirements::javaScript("mysite/javascript/vimeo.js");
but I still cannot pass the variables into the js
VideoPage.php
<?php
class VideoPage extends SiteTree {
public static $db = array(
'MapURL' => 'HTMLText',
'VimeoID' => 'Text',
'Marker1' => 'VarChar',
'Marker2' => 'VarChar',
'Marker3' => 'VarChar',
'mapContent' => 'HTMLText',
'Date' => 'Date',
'shortDescription' => 'Text',
'Category' => "Enum('Cyclist, Driver,High Interaction, Low Interaction, Fast, Slow')"
);
public static $has_one = array(
'Thumbnail' => 'Image'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date', 'Date'),'Content');
$fields->addFieldToTab('Root.Content.Main', new TextAreaField('shortDescription', 'Short Description'));
$fields->addFieldToTab('Root.Content.Main', new DropdownField(
'Category',
'Category',
singleton('VideoPage')->dbObject('Category')->enumValues()
), 'Content');
$fields->addFieldToTab('Root.Content.Main', new HtmlEditorField('mapContent', 'Map Content'));
$fields->addFieldToTab('Root.Content.Embed', new TextareaField('MapURL', 'Google Map URL'));
$fields->addFieldToTab('Root.Content.Embed', new TextField('VimeoID', 'Vimeo video ID'));
$fields->addFieldToTab('Root.Content.Embed', new ImageField('Thumbnail', "Thumbnail"));
$fields->addFieldToTab('Root.Content.Embed', new NumericField('Marker1', 'playhead Marker 1'));
$fields->addFieldToTab('Root.Content.Embed', new NumericField('Marker2', 'playhead Marker 2'));
$fields->addFieldToTab('Root.Content.Embed', new NumericField('Marker3', 'playhead Marker 3'));
return $fields;
}
}
class VideoPage_Controller extends Page_Controller {
public function init() {
parent::init();
// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
//$query = DataObject::get("VideoPage", "ID = $this->VimeoID");
Requirements::javaScript("mysite/javascript/vimeo.js");
}
public function doVimeo() {
$query = (int)DB::query("SELECT VimeoID FROM `VideoPage`WHERE `ID` = '$this->ID' AND VimeoID IS NOT NULL")->value();
$text = $query;
//$query = ("VimeoURL FROM `videopage`WHERE `ID` = '$this->ID'");
$result = mysql_query($query);
$doc = new DomDocument('1.0');
// create root node
$root = $doc->createElement('vimeoURL');
$root = $doc->appendChild($root);
// add node for each row
$occ = $doc->createElement('vimeoID');
$occ = $root->appendChild($occ);
$child = $doc->createElement('ID');
$child = $occ->appendChild($child);
$value = $doc->createTextNode('ID' + $query);
$value = $child->appendChild($value);
$xml_string = $doc->saveXML();
//header('Content-Type: application/xml; charset=ISO-8859-1');
//echo $xml_string;
}
}
?>
vimeo.js
function playNewVideo()
{
console.log('".$this->vimeoID()."');
alert("PlayNewVideo");
var flashvars = {
'clip_id': '.$this->doVimeo().',
'server': 'vimeo.com',
'show_title': 1,
'show_byline': 1,
'show_portrait': 0,
'fullscreen': 1,
'js_api': 1
}
var parObj = {
'swliveconnect':true,
'fullscreen': 1,
'allowscriptaccess': 'always',
'allowfullscreen':true
};
var attObj = {}
attObj.id="myFlashID";
swfobject.embedSWF("http://www.vimeo.com/moogaloop.swf", "myContent", "100%", "195", "9.0.28", '',flashvars,parObj, attObj );
}
would it be better to use dataobject instead?