Version: current

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

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