Version: current

     1 <?php
     2
     3 class VideoEntry extends DataObject {
     4
     5     static $db = array(
     6         'Title' => 'Text',
     7         'Description' => 'Text',
     8         'Lenght' => 'Varchar(7)',
     9         'Source' => 'Varchar(255)',
    10         'SourceLink' => 'Varchar(255)'
    11     );
    12     static $has_one = array(
    13         'SourceVideo' => 'VideoFile',
    14         'PreviewImage' => 'Image',
    15         'VideoCategory' => 'VideoCategory',
    16         'VideoBankPage' => 'VideoBankPage',
    17     );
    18     static $casting = array(
    19         'Video' => 'HTMLText'
    20     );
    21
    22     /*
    23      * Ссылка на видео
    24      */
    25
    26     function Link() {
    27         return VideoBankPage::find_root_link() . 'show/' . $this->ID;
    28     }
    29
    30     function Video() {
    31         $sc = SiteConfig::current_site_config();
    32         $width = $sc->VideoWidth;
    33         $height = $sc->VideoHeight;
    34         if ($this->PreviewImageID != 0 && $this->PreviewImage()->ID != 0) {
    35             $img = $this->PreviewImage();
    36         } else {
    37             $img = $this->SourceVideo()->VideoThumbnail();
    38         }
    39         $img = $img->CroppedImage($width, $height)->URL;
    40         return "<a href=\"" . $this->SourceVideo()->URL . "\" style=\"display:block;width:" . $width . "px;height:" . $height . "px;\" class=\"modern-light\"><img src=\"" . $img . "\" alt=\"" . $this->Title . "\" /></a>";
    41     }
    42
    43     function Value(){
    44         return $this->Title;
    45     }
    46
    47     function getCMSFields($params = null) {
    48         $fields = parent::getCMSFields($params);
    49         $fields->removeByName('SortOrder');
    50         return $fields;
    51     }
    52
    53     function getCMSFields_forPopup() {
    54         $fields = parent::getCMSFields();
    55         $fields->removeByName('SortOrder');
    56         $fields->replaceField('Title', new TextField('Title', $this->fieldLabel('Title')));
    57         $fields->replaceField('PreviewImage', new ImageField('PreviewImage', _t('VideoEntry.has_one_PreviewImage','Preview Image')));
    58         return $fields;
    59     }
    60
    61     static function get_by_id($id, $cache = true) {
    62         $callerClass = 'VideoEntry';
    63         $item = DataObject::get_by_id($callerClass, $id, $cache);
    64         return $item;
    65     }
    66
    67     static function get($filter="",$sort = "", $limit = "") {
    68         $callerClass = 'VideoEntry';
    69         $join = "";
    70         return DataObject::get($callerClass, $filter, $sort, $join, $limit);
    71     }
    72
    73     function onBeforeDelete() {
    74         if ($this->SourceVideo()->ID) {
    75             $this->SourceVideo()->delete();
    76         }
    77         if ($this->PreviewImage()->ID) {
    78             $this->PreviewImage()->delete();
    79         }
    80         parent::onBeforeDelete();
    81     }
    82 }
    83
    84 ?>
    85

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -