Version: current

      1 <?php
      2
      3 /**
      4  * Description of DefaultCMSActionDecorator
      5  * Стандартные действия по управлению
      6  * @author inxo
      7  */
      8 class DefaultCMSActionDecorator extends LeftAndMainDecorator {
      9     static $allowed_actions = array('deletemarked', 'publishmarked', 'unpublishmarked');
     10     public function deletemarked($urlParams, $form) {
     11         $num = 0;
     12         if (isset($urlParams['ClassName']) && isset($urlParams['ID'])) {
     13             $Parent = DataObject::get_by_id($urlParams['ClassName'], $urlParams['ID']);
     14             $childClass = $Parent->stat('subpage_children');
     15             if (!$childClass)
     16                 user_error("No subpage_children static defined in " . $Parent->ClassName);
     17
     18             if ($list = $this->getSubpageIDList(@$urlParams['FieldName'])) {
     19                 if ($Pages = DataObject::get($childClass, "\"".$Parent->stat('subpage_children')."\".\"ID\" IN ($list)")) {
     20                     foreach ($Pages as $Page) {
     21                         if ($Page->doUnpublish()) {
     22                             $Page->delete();
     23                         }
     24                         $num++;
     25                     }
     26                 }
     27                 $message = sprintf(_t('Subpages.DELETEOK', 'Delete %s'), $num);
     28                 FormResponse::status_message($message, "good");
     29                 FormResponse::add("$('Form_EditForm_Subpages').refresh();");
     30             }
     31             else {
     32                 $message = sprintf(_t('Subpages.ERRORDELETE', 'Error delete'));
     33                 FormResponse::status_message($message, "bad");
     34             }
     35         }
     36         else {
     37             $message = sprintf(_t('Subpages.ERRORDELETE', 'Error delete'));
     38             FormResponse::status_message($message, "bad");
     39         }
     40         FormResponse::add("$('Form_EditForm_Subpages').refresh();");
     41         return FormResponse::respond();
     42     }
     43
     44     public function publishmarked($urlParams, $form) {
     45         $num = 0;
     46         if (isset($urlParams['ClassName']) && isset($urlParams['ID'])) {
     47             $Parent = DataObject::get_by_id($urlParams['ClassName'], $urlParams['ID']);
     48             $childClass = $Parent->stat('subpage_children');
     49             if (!$childClass)
     50                 user_error("No subpage_children static defined in " . $Parent->ClassName);
     51
     52             if ($list = $this->getSubpageIDList(@$urlParams['FieldName'])) {
     53                 if ($Pages = DataObject::get($childClass, "\"".$Parent->stat('subpage_children')."\".\"ID\" IN ($list)")) {
     54                     foreach ($Pages as $Page) {
     55                         $Page->doPublish(); // = 'Unpublished';
     56                         $num++;
     57                     }
     58                 }
     59                 else {
     60                     user_error("No $list could be found!", E_USER_ERROR);
     61                 }
     62                 $message = sprintf(_t('Subpages.PUBLISHOK', 'Publish %s'), $num);
     63                 FormResponse::status_message($message, "good");
     64                 FormResponse::add("$('Form_EditForm_Subpages').refresh();");
     65             }
     66             else {
     67                 $message = sprintf(_t('Subpages.ERRORPUBLISH', 'Error publish'));
     68                 FormResponse::status_message($message, "bad");
     69             }
     70         }
     71         else {
     72             $message = sprintf(_t('Subpages.ERRORPUBLISH', 'Error publish'));
     73             FormResponse::status_message($message, "bad");
     74         }
     75         FormResponse::add("$('Form_EditForm_Subpages').refresh();");
     76         return FormResponse::respond();
     77     }
     78
     79     public function unpublishmarked($urlParams, $form) {
     80         $num = 0;
     81         if (isset($urlParams['ClassName']) && isset($urlParams['ID'])) {
     82             $Parent = DataObject::get_by_id($urlParams['ClassName'], $urlParams['ID']);
     83             $childClass = $Parent->stat('subpage_children');
     84             if (!$childClass)
     85                 user_error("No subpage_children static defined in " . $Parent->ClassName);
     86
     87             if ($list = $this->getSubpageIDList(@$urlParams['FieldName'])) {
     88                 if ($Pages = DataObject::get($childClass, "\"".$Parent->stat('subpage_children')."\".\"ID\" IN ($list)")) {
     89                     foreach ($Pages as $Page) {
     90                         $Page->doUnpublish(); // = 'Unpublished';
     91                         $num++;
     92                     }
     93                 }
     94                 $message = sprintf(_t('Subpages.UNPUBLISHOK', 'Unpublish %s'), $num);
     95                 FormResponse::status_message($message, "good");
     96                 FormResponse::add("$('Form_EditForm_Subpages').refresh();");
     97             }
     98             else {
     99                 $message = sprintf(_t('Subpages.ERRORUNPUBLISH', 'Error unpublish'));
    100                 FormResponse::status_message($message, "bad");
    101             }
    102
    103         }
    104         else {
    105             $message = sprintf(_t('Subpages.ERRORUNPUBLISH', 'Error unpublish'));
    106             FormResponse::status_message($message, "bad");
    107         }
    108         FormResponse::add("$('Form_EditForm_Subpages').refresh();");
    109         return FormResponse::respond();
    110     }
    111
    112     public function addsubpage($urlParams, $form) {
    113         if (isset($urlParams['ClassName']) && isset($urlParams['ID'])) {
    114             $parent = DataObject::get_by_id($urlParams['ClassName'], $urlParams['ID']);
    115             $childClass = $parent->stat('subpage_children');
    116             if (!$childClass)
    117                 user_error("No subpage_children static defined in " . $parent->ClassName);
    118
    119             $newPage = new $childClass();
    120 //          $newPage->Title = _t('CMSMain.NEW',"New ",PR_MEDIUM,'"New " followed by a className').singleton($childClass)->i18n_singular_name();
    121             $newPage->Title = singleton($childClass)->i18n_singular_name();
    122             $newPage->ParentID = $parent->ID;
    123             $newPage->URLSegment = "new-" . strtolower($childClass);
    124             $newPage->write();
    125
    126             $message = sprintf(_t('Subpages.CREATEOK', 'Creates %s'), $newPage->Title);
    127             FormResponse::status_message($message, "good");
    128             FormResponse::get_page($newPage->ID);
    129             //FormResponse::add("$('Form_EditForm_Subpages').refresh();");
    130
    131         }
    132         return FormResponse::respond();
    133     }
    134
    135     private function getSubpageIDList($suffix = false) {
    136         $fieldName = 'SubpageIDs';
    137         if ($suffix) $fieldName .= '_' . $suffix;
    138
    139         $list = '';
    140         if (isset($_REQUEST[$fieldName]) && $_REQUEST[$fieldName]) {
    141             $list = preg_replace('! *, *!', "','", trim(addslashes($_REQUEST[$fieldName])));
    142         }
    143         return ($list) ? "'" . $list . "'" : false;
    144     }
    145 }
    146
    147

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