Version: current

     1 <?php
     2
     3 /**
     4  * Обработка событий сортировки таблицы
     5  *
     6  * @author inxo
     7  */
     8 class SortCMSActionDecorator extends LeftAndMainDecorator {
     9     static $allowed_actions = array('sort');
    10     function sort($urlParams, $form) {
    11         if (isset($urlParams['action_sort']) && $urlParams['action_sort'] == 1 && isset($urlParams['SortList'])) {
    12             $SortList = explode(',', $urlParams['SortList']);
    13             foreach ($SortList as $Item) {
    14                 if (!is_numeric($Item)) {
    15                     $message = sprintf(_t('SubpageSort.CANTSORT', 'Can\'t sort'));
    16                     FormResponse::status_message($message, "bad");
    17                     $error = true;
    18                     break;
    19                 }
    20             }
    21             // Получаем список для этого раздела
    22             //Debug::dump($this); die();
    23             if (!isset($error) && isset($urlParams['ClassName']) && isset($urlParams['ID']) && class_exists($urlParams['ClassName'])) {
    24                 $Parent = DataObject::get_by_id($urlParams['ClassName'], $urlParams['ID']);
    25                 $Items = DataObject::get($Parent->stat('subpage_children'), "ParentID = {$Parent->ID}");
    26                 if (count($Items) == count($SortList)) {
    27                     foreach ($Items as $Item) {
    28                         $num = array_keys($SortList, $Item->ID);
    29                         $Item->Sort = $num[0]+1;
    30                         $Item->writeWithoutVersion();
    31                     }
    32                     $message = sprintf(_t('SubPageSort.SORTDX', 'Sorted %s'), $num);
    33                     FormResponse::status_message($message, "good");
    34                     FormResponse::add("$('Form_EditForm_Subpages').refresh();");
    35                 }else{
    36                     $message = sprintf(_t('SubpageSort.CANTSORT', 'Can\'t sort'));
    37                     FormResponse::status_message($message, "bad");
    38                 }
    39             }
    40         }
    41
    42         return FormResponse::respond();
    43     }
    44
    45 }
    46

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