Version: current

      1 <?php
      2
      3 /**
      4  * Управление заказами
      5  *
      6  * @package cart
      7  * @author inxo, dvp
      8  */
      9 class OrderAdmin extends ModelAdmin {
     10
     11     static $url_segment = 'orderadmin';
     12     protected $resultsTableClassName = 'CartTableListField';
     13     public static $allowed_actions = array(
     14         'add',
     15         'edit',
     16         'delete',
     17         'export',
     18         'import',
     19         'renderimportform',
     20         'handleList',
     21         'handleItem',
     22     );
     23     public static $managed_models = array('Order');
     24     static $menu_title = 'Orders';
     25     public static $collection_controller_class = "OrderAdmin_CollectionController";
     26     public static $record_controller_class = "OrderAdmin_RecordController";
     27
     28 }
     29
     30 class OrderAdmin_CollectionController extends ModelAdmin_CollectionController {
     31
     32     public function ImportForm() {
     33         return false;
     34     }
     35
     36     public function CreateForm() {
     37         return false;
     38     }
     39
     40     function getResultsTable($searchCriteria) {
     41
     42         $summaryFields = $this->getResultColumns($searchCriteria);
     43         $className = $this->parentController->resultsTableClassName();
     44         $tf = new $className($this->modelClass, $this->modelClass, $summaryFields);
     45
     46         $tf->setCustomQuery($this->getSearchQuery($searchCriteria));
     47         $tf->setPageSize($this->parentController->stat('page_length'));
     48         $tf->setShowPagination(true);
     49         //$tf->Markable=true;
     50         // @todo Remove records that can't be viewed by the current user
     51         $tf->setPermissions(array_merge(array('edit', 'export'), TableListField::permissions_for_object($this->modelClass)));
     52
     53         $tf->actions = array_merge(
     54         array(
     55             'export'=> array(
     56                 'label' => 'Export',
     57                 'icon' => 'cms/images/network-save-bw.gif',
     58                 'icon_disabled' => 'cms/images/network-save-bw.gif',
     59                 'class' => 'downloadlink',
     60             ),
     61             'edit'=> array(
     62                 'label' => 'Edit',
     63                 'icon' => 'cms/images/edit.gif',
     64                 'icon_disabled' => 'cms/images/edit_disabled.gif',
     65                 'class' => 'editlink',
     66             ),
     67         ), $tf->actions);
     68
     69
     70         // csv export settings (select all columns regardless of user checkbox settings in 'ResultsAssembly')
     71         $exportFields = $this->getResultColumns($searchCriteria, false);
     72         $tf->setFieldListCsv($exportFields);
     73
     74         $url = '<a href=\"' . $this->Link() . '/$ID/edit\">$value</a>';
     75         $tf->setFieldFormatting(array_combine(array_keys($summaryFields), array_fill(0, count($summaryFields), $url)));
     76         return $tf;
     77     }
     78
     79     public function SearchForm() {
     80         $context = singleton($this->modelClass)->getDefaultSearchContext();
     81         $fields = $context->getSearchFields();
     82
     83         $statusValues = singleton('Order')->dbObject('Status')->enumValues();
     84         foreach ($statusValues as $statusItem => $statusName) {
     85             $statusValues[$statusItem] = Order::status_title($statusItem);
     86         }
     87         $statusValues[''] = Order::status_title('Any');
     88         $fields->replaceField('Status', new DropdownField('Status', _t('Order.db_Status', 'Status'), $statusValues));
     89
     90         $columnSelectionField = $this->ColumnSelectionField();
     91         $fields->push($columnSelectionField);
     92         $validator = new RequiredFields();
     93         $validator->setJavascriptValidationHandler('none');
     94
     95         $form = new Form($this, "SearchForm",
     96                         $fields,
     97                         new FieldSet(
     98                                 new FormAction('search', _t('MemberTableField.SEARCH', 'Search')),
     99                                 $clearAction = new ResetFormAction('clearsearch', _t('ModelAdmin.CLEAR_SEARCH', 'Clear Search'))
    100                         ),
    101                         $validator
    102         );
    103         //$form->setFormAction(Controller::join_links($this->Link(), "search"));
    104         $form->setFormMethod('get');
    105         $form->setHTMLID("Form_SearchForm_" . $this->modelClass);
    106         $form->disableSecurityToken();
    107         $clearAction->useButtonTag = true;
    108         $clearAction->addExtraClass('minorAction');
    109
    110         return $form;
    111     }
    112
    113 }
    114
    115 class OrderAdmin_RecordController extends ModelAdmin_RecordController {
    116
    117     static $allowed_actions = array('edit', 'view', 'EditForm', 'ViewForm', 'export',);
    118
    119     /**
    120      * Renders the record view template.
    121      *
    122      * @param SS_HTTPRequest $request
    123      * @return mixed
    124      */
    125     function export($request) {
    126         if($this->currentRecord) {
    127         // header content-disposition
    128             // без этого шаблон падает с segmentation fault
    129             foreach ($this->currentRecord->Items() as $row) {
    130                 $row->getProduct();
    131             }
    132
    133             return SS_HTTPRequest::send_file($this->currentRecord->renderWith('OrderExport'), 'Order_'.$this->currentRecord->ID.'.xml', 'text/plain');
    134
    135         } else {
    136             return _t('ModelAdmin.ITEMNOTFOUND');
    137         }
    138     }
    139
    140 }
    141
    142

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