Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.13 KB | None | 0 0
  1. <?php
  2.  
  3. class HomePage extends Page {
  4.     private static $db = array(
  5.         'VideoCaption' => 'HTMLText',
  6.         'VideoUrl' => 'Text',
  7.         'TopRowContent' => 'HTMLText',
  8.         'WhereRightColumnContent' => 'HTMLText',
  9.         'BottomRowContent' => 'HTMLText',
  10.         'HeaderMenuSetID' => 'int',
  11.         'FooterMenuSetID' => 'int',
  12.     );
  13.  
  14.     private static $has_one = array(
  15.         'VideoRowBackground' => 'Image',
  16.         'VideoPreviewThumbnail' => 'Image',
  17.         'TopRowBackground' => 'Image',
  18.     );
  19.  
  20.     function getCMSFields() {
  21.         $fields = parent::getCMSFields();
  22.         $fields ->addFieldToTab('Root.TopRow', new HtmlEditorField('TopRowContent','Content'));
  23.         $fields ->addFieldsToTab('Root.TopRow', new UploadField('TopRowBackground','Row Background Image'));
  24.         $fields ->addFieldToTab('Root.VideoRow', new HtmlEditorField('VideoCaption','Video Caption'));
  25.         $fields ->addFieldToTab('Root.VideoRow', new TextField('VideoUrl','Vimeo Url'));
  26.         $fields ->addFieldsToTab('Root.VideoRow', new UploadField('VideoPreviewThumbnail','Video Preview Thumbnail'));
  27.         $fields ->addFieldsToTab('Root.VideoRow', new UploadField('VideoRowBackground','Row Background Image'));
  28.         $fields ->addFieldToTab('Root.Main', new HtmlEditorField('WhereRightColumnContent','Right Column Content'));
  29.         $fields ->addFieldToTab('Root.BottomRow', new HtmlEditorField('BottomRowContent','Bottom Row Center Column Content'));
  30.  
  31.  
  32.         return $fields;
  33.     }
  34.     function getSettingsFields() {
  35.         $fields = parent::getSettingsFields();
  36.         $ddHeaderField = new DropdownField("NewHeaderMenuSetID","Which Menu Set to use for the Header?",
  37.             $this->getExistingMenuSets(), $this->HeaderMenuSetID);
  38.         $ddHeaderField->setEmptyString("Header not linked to a Menu");
  39.         $ddHeaderField->setHasEmptyDefault(true);
  40.         $fields->addFieldToTab('Root.Settings', $ddHeaderField);
  41.  
  42.         $ddFooterField = new DropdownField("NewFooterMenuSetID","Which Menu Set to use for the Footer?",
  43.             $this->getExistingMenuSets(), $this->FooterMenuSetID);
  44.         $ddFooterField->setEmptyString("Footer not linked to a Menu");
  45.         $ddFooterField->setHasEmptyDefault(true);
  46.         $fields->addFieldToTab('Root.Settings', $ddFooterField);
  47.         return $fields;
  48.     }
  49.     public function getExistingMenuSets()
  50.     {
  51.         if ($MenuSets = DataObject::get('MenuSet'))
  52.         {
  53.             return $MenuSets->map('ID', 'Title');
  54.         }
  55.         else
  56.         {
  57.             return array ('none defined');
  58.         }
  59.     }
  60.     public function onBeforeWrite()
  61.     {
  62.         parent::onBeforeWrite();
  63.  
  64.         if ($this->NewHeaderMenuSetID != 0) {
  65.             $this->HeaderMenuSetID = $this->NewHeaderMenuSetID;
  66.         } else {
  67.             $this->HeaderMenuSetID = 0;
  68.         }
  69.         if ($this->NewFooterMenuSetID != 0) {
  70.             $this->FooterMenuSetID = $this->NewFooterMenuSetID;
  71.         } else {
  72.             $this->FooterMenuSetID = 0;
  73.         }
  74.  
  75.         parent::onBeforeWrite();
  76.  
  77.     }
  78. }
  79. class HomePage_Controller extends Page_Controller {
  80.  
  81.     private static $allowed_actions = array('Form','Faq');
  82.     public function Form() {
  83.  
  84.         $nameField = new TextField('Name');
  85.         $nameField->setFieldHolderTemplate('FormField_holder_notitle');
  86.         $nameField->setValue('NAME');
  87.         $emailField = new EmailField('Email');
  88.         $emailField->setvalue('EMAIL@EMAIL.COM');
  89.         $emailField->setFieldHolderTemplate('FormField_holder_notitle');
  90.  
  91.         $fields = new FieldList(
  92.             $nameField,
  93.             $emailField
  94.         );
  95.         $actions = new FieldList(
  96.             new FormAction('submit', 'SUBMIT')
  97.         );
  98.         $form = new Form($this, 'Form', $fields, $actions);
  99.         return $form;
  100.     }
  101.     public function FaqList() {
  102.         $faq = Faq::get()->sort("RAND()")->limit(5);
  103.         return $faq;
  104.     }
  105.     public function init() {
  106.         parent::init();
  107.  
  108.         // You can include any CSS or JS required by your project here.
  109.         // See: http://doc.silverstripe.org/framework/en/reference/requirements
  110.  
  111.  
  112.     }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement