Version: current

     1 <?php
     2
     3 class VideoCategory extends DataObject {
     4
     5     static $db = array(
     6         'Title' => 'Varchar(255)',
     7         'URLSegment' => 'Varchar(255)'
     8     );
     9
    10     static $belong_many_many = array(
    11         'VideoBankPage' => 'VideoBankPage'
    12     );
    13
    14     function  getCMSFields() {
    15         $fields = parent::getCMSFields();
    16         $fields->removeByName('URLSegment');
    17         return $fields;
    18     }
    19
    20     function  onBeforeWrite() {
    21         parent::onBeforeWrite();
    22         $this->URLSegment = Convert::rus2lat($this->Title);
    23     }
    24
    25     /*
    26      * Ссылка на видео этой категории
    27      */
    28     function Link(){
    29         return VideoBankPage::find_root_link().'theme/'.$this->URLSegment;
    30     }
    31
    32     static function getCategory($title){
    33         $category = DataObject::get_one('VideoCategory', '"URLSegment" LIKE \'' . $title . '\'');
    34         return ($category) ? $category : null;
    35     }
    36
    37     static function getVideoByCategory($category, $limit) {
    38         if ($category) {
    39             $category = DataObject::get_one('VideoCategory', '"URLSegment" LIKE \'' . $category . '\'');
    40             if ($category) {
    41                 return self::getByCategoryID($category->ID, $limit);
    42             }
    43         }
    44         return null;
    45     }
    46
    47     static function getByCategoryID($categoryID, $limit) {
    48         if (is_numeric($categoryID)) {
    49             $filter = '"VideoCategoryID" = ' . $categoryID;
    50         } else {
    51             return null;
    52         }
    53         return self::getFilteredVideo($filter, $limit);
    54     }
    55
    56     private static function getFilteredVideo($filter, $limit) {
    57         return DataObject::get('VideoEntry', $filter, "\"Created\" DESC", null, $limit);
    58     }
    59
    60
    61 }
    62

[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. -