Version: current

      1 <?php
      2 /**
      3  * Description of PublHolder
      4  *
      5  * @author inxo
      6  */
      7
      8 class PublHolder extends Page {
      9     static $db = array(
     10             'PublPerPage' => 'Int',
     11             'SortType' => 'Int', // Сортировка, 1 - По названию, 2 - По дате в обратном порядке (по-умолчанию) 3 - По дате в прямом порядке
     12             'Template' => 'Text',
     13     );
     14
     15     static $defaults = array(
     16             'PublPerPage' => 20,
     17             'SortType' => 2,
     18             'AutoChild' => 0,
     19             'Template' => 'Publication'
     20     );
     21
     22     static $icon = "publication/img/publicationholder";
     23     static $allowed_children = array('Publication','PublHolder');
     24
     25     static $subpage_children = 'Publication';
     26
     27     protected function getSQLSort() {
     28         switch ($this->SortType) {
     29             case 1:
     30                 return "Title ASC";
     31
     32             case 2:
     33                 return "`Publication`.Date DESC";
     34
     35             case 3:
     36                 return "`Publication`.Date ASC";
     37         }
     38     }
     39
     40     public function Entries($start = '', $limit = '') {
     41         return DataObject::get("Publication", "`ParentID` = {$this->ID} AND `IsHidden` = 0", $this->getSQLSort(), "", "$start,$limit");
     42     }
     43
     44     public function EntriesSummary($start = 0, $limit = 2) {
     45         return $this->Entries($start, $limit);
     46     }
     47
     48     public function SubPublHolders() {
     49         return DataObject::get("PublHolder", "`ParentID` = {$this->ID}", "Title ASC");
     50     }
     51
     52     public function Favorites($count = 3) {
     53         return DataObject::get("Publication", "`Favorite` = 1", 'Date DESC', "", $count);
     54     }
     55
     56
     57     function getCMSFields() {
     58         $fields = parent::getCMSFields();
     59
     60         $fields->addFieldToTab('Root.Content.Main',
     61             new OptionsetField('SortType', $this->fieldLabel('SortType'), array(
     62                 '1' => _t('PublHolder.SORT_NAME',"Name"),
     63                 '2' => _t('PublHolder.SORT_DATEDESC',"Date DESC"),
     64                 '3' => _t('PublHolder.SORT_DATE',"Date")
     65             )),
     66             'Content'
     67         );
     68         $fields->addFieldToTab('Root.Content.Main', new NumericField("PublPerPage", _t('PublHolder.NPS', "Publication per page")), 'Content');
     69
     70 //      $fields->addFieldToTab('Root.Content', new Tab("FullContent",  _t('PublHolder.tab_Content', 'Content')), 'Metadata');
     71 //      $fields->addFieldToTab('Root.Content.FullContent', $fields->dataFieldByName('Content'));
     72
     73         $fields->addFieldToTab('Root.Content', new Tab("tabSubPages", _t('PublHolder.tab_Articles', 'Articles')), 'Metadata');
     74
     75         $subClass = self::$subpage_children;
     76         $sp = new SubpageListField('Subpages', $this, $subClass, $this->getSQLSort());
     77         $sp->Sortable = false;
     78         $url = '<a href=\"admin/show/$ID\">$value</a>';
     79         $sp->setFieldFormatting(array_combine(array_keys(singleton($subClass)->summaryFields()), array_fill(0, count(singleton($subClass)->summaryFields()), $url)));
     80         $fields->addFieldToTab('Root.Content.tabSubPages', $sp);
     81
     82         if(Director::isDev()) $fields->addFieldToTab('Root.Content.Main', new TextField("Template", _t('PublHolder.TEMPLATE', "Template")));
     83         return $fields;
     84     }
     85
     86 }
     87
     88 class PublHolder_Controller extends Page_Controller {
     89
     90     /***
     91      * Показ списка статей
     92      */
     93     function ArticleEntries() {
     94         $start = 0;
     95         $limit = ($this->PublPerPage > 0) ? $this->PublPerPage : 20; // TODO вытаскивать из PublHolder::$defaults
     96         if(isset ($_GET['start'])) {
     97             if(is_numeric($_GET['start'])) {
     98                 $start = (int) $_GET['start'];
     99             }
    100         }
    101         $rs = $this->Entries($start, $limit);
    102         if ($this->hasMethod('setSEOVars')) {
    103             $this->setSEOVars($rs); //Выставляем SEO-переменные (ф-я setSEOVars находится в Webylon Page_Controller)
    104         }
    105         return $rs;
    106     }
    107
    108     /**
    109      * Показ разделов
    110      */
    111     function Tree() {
    112         return $this->SubPublHolders();
    113     }
    114 }
    115
    116

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