Version: current

     1 <?php
     2
     3 /**
     4  * Декларируем действия в CMS
     5  *
     6  * @package Catalog
     7  * @author inxo
     8  */
     9 class CatalogCMSActionDecorator extends LeftAndMainDecorator {
    10
    11     /**
    12      * Перемещение отмеченных
    13      * @param <type> $urlParams
    14      * @param <type> $form
    15      * @return <type>
    16      */
    17     public function movemarked($urlParams, $form) {
    18         //Debug::message('nen');
    19         $num = 0;
    20         $copy = false;
    21         if (isset($_REQUEST['Copy']) && $_REQUEST['Copy'])
    22             $copy = true;
    23         if ($_REQUEST['DestID'] && (is_numeric($_REQUEST['DestID']))) {
    24             $destID = $_REQUEST['DestID'];
    25             $Dest = DataObject::get_by_id("Catalog", $destID);
    26
    27             if ($Dest && isset($_REQUEST['SubpageIDs'])) {
    28                 $List = "'" . ereg_replace(' *, *', "','", trim(addslashes($_REQUEST['SubpageIDs']))) . "'";
    29                 if ($List != "''") {
    30                     $Pages = DataObject::get("Product", "\"Product\".\"ID\" IN ($List)");
    31                     if ($Pages) {
    32
    33                         foreach ($Pages as $Page) {
    34                             if ($copy) {
    35                                 $virtual = new VirtualProduct();
    36                                 $virtual->setParent($destID);
    37                                 $virtual->setCopyContentFromID($Page->ID);
    38                                 $virtual->doPublish();
    39                                 $virtual->write();
    40                             } else {
    41                                 if ($Page->ParentID != $destID) {
    42                                     $Page->ParentID = $destID;
    43                                     $Page->doUnpublish(); // = 'Unpublished';
    44                                     $Page->write();
    45                                 }
    46                             }
    47                             $num++;
    48                         }
    49                     }
    50                 } else {
    51                     user_error("No $List could be found!", E_USER_ERROR);
    52                 }
    53                 if ($num > 0) {
    54                     if ($copy)
    55                         $message = sprintf(_t('Catalog.COPIEDX', 'Copied %s'), $num);
    56                     else
    57                         $message = sprintf(_t('Catalog.MOVEDX', 'Moved %s'), $num);
    58
    59                     FormResponse::status_message($message, "good");
    60                 }else {
    61                     $message = sprintf(_t('Catalog.ERRORMCX', 'Error move or copy, can\'t find products'), $num);
    62                     FormResponse::status_message($message, "bad");
    63                 }
    64                 FormResponse::add("$('Form_EditForm_Subpages').refresh();");
    65             } else {
    66                 /* Перетаскивание в спец.разделы */
    67                 if ($copy) {
    68                     $message = sprintf(_t('Catalog.CANTCOPIEDX', 'Can\'t copy here %s products'), $num);
    69                     FormResponse::status_message($message, "bad");
    70                 } else {
    71                     $Dest = DataObject::get_by_id('SpecialCatalog', $destID);
    72                     if ($Dest) {
    73                         $List = "'" . ereg_replace(' *, *', "','", trim(addslashes($_REQUEST['SubpageIDs']))) . "'";
    74                         if ($List != "''") {
    75                             // Добавляем продукты к списку спец.раздела.
    76                             $Pages = DataObject::get("Product", "\"Product\".\"ID\" IN ($List)");
    77                             if ($Pages) {
    78                                 $Dest->Products->addMany($Pages);
    79                                 $message = sprintf(_t('Catalog.COPIEDX', 'Copied %s'), '');
    80                                 FormResponse::status_message($message, "good");
    81                             }
    82                         } else {
    83                             user_error("No $List could be found", E_USER_ERROR);
    84                         }
    85                     } else {
    86                         $message = sprintf(_t('Catalog.CANTCOPIEDX', 'Can\'t copy here %s products'), $num);
    87                         FormResponse::status_message($message, "bad");
    88                     }
    89                 }
    90             }
    91
    92             return FormResponse::respond();
    93         }
    94     }
    95 }
    96
    97

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