Passed
Pull Request — master (#635)
by Roman
04:20
created

OrdersAdmin::SearchForm()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 2
nop 0
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverShop\Admin;
4
5
use SilverShop\Forms\GridField\OrderGridFieldDetailForm_ItemRequest;
6
use SilverShop\Model\Order;
7
use SilverShop\Model\OrderStatusLog;
8
use SilverStripe\Admin\ModelAdmin;
9
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
10
use SilverStripe\Forms\GridField\GridFieldConfig;
11
use SilverStripe\Forms\GridField\GridFieldDataColumns;
12
use SilverStripe\Forms\GridField\GridFieldDetailForm;
13
use SilverStripe\Forms\GridField\GridFieldSortableHeader;
14
15
/**
16
 * Order administration interface, based on ModelAdmin
17
 *
18
 * @package SilverShop\Admin
19
 */
20
class OrdersAdmin extends ModelAdmin
21
{
22
    private static $url_segment = 'orders';
0 ignored issues
show
introduced by
The private property $url_segment is not used, and could be removed.
Loading history...
23
24
    private static $menu_title = 'Orders';
0 ignored issues
show
introduced by
The private property $menu_title is not used, and could be removed.
Loading history...
25
26
    private static $menu_priority = 1;
0 ignored issues
show
introduced by
The private property $menu_priority is not used, and could be removed.
Loading history...
27
28
    private static $menu_icon_class = 'silvershop-icon-cart';
0 ignored issues
show
introduced by
The private property $menu_icon_class is not used, and could be removed.
Loading history...
29
30
    private static $managed_models = [
0 ignored issues
show
introduced by
The private property $managed_models is not used, and could be removed.
Loading history...
31
        Order::class,
32
        OrderStatusLog::class
33
    ];
34
35
    private static $model_importers = array();
0 ignored issues
show
introduced by
The private property $model_importers is not used, and could be removed.
Loading history...
36
37
    /**
38
     * Restrict list to non-hidden statuses
39
     */
40
    public function getList()
41
    {
42
        if ($this->modelClass == $this->sanitiseClassName(Order::class)) {
43
            $context = $this->getSearchContext();
44
            $params = $this->request->requestVar('q');
45
            //TODO update params DateTo, to include the day, ie 23:59:59
46
            $list = $context->getResults($params)
47
                ->exclude('Status', Order::config()->hidden_status); //exclude hidden statuses
48
49
            $this->extend('updateList', $list);
50
            return $list;
51
        } else {
52
            return parent::getList();
53
        }
54
    }
55
56
    /**
57
     * Replace gridfield detail form to include print functionality
58
     */
59
    function getEditForm($id = null, $fields = null)
60
    {
61
        $form = parent::getEditForm($id, $fields);
62
        if ($this->modelClass == $this->sanitiseClassName(Order::class)) {
63
            /** @var GridFieldConfig $config */
64
            $config = $form->Fields()->fieldByName($this->modelClass)->getConfig();
65
            $config->getComponentByType(GridFieldSortableHeader::class)->setFieldSorting(
0 ignored issues
show
Bug introduced by
The method setFieldSorting() does not exist on SilverStripe\Forms\GridField\GridFieldComponent. It seems like you code against a sub-type of SilverStripe\Forms\GridField\GridFieldComponent such as SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\GridF...GridFieldSortableHeader or SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\GridF...GridFieldSortableHeader or SilverStripe\Forms\GridF...GridFieldSortableHeader or SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\Tests...ndlerTest\TestComponent or SilverStripe\Forms\GridField\GridFieldDetailForm. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
            $config->getComponentByType(GridFieldSortableHeader::class)->/** @scrutinizer ignore-call */ setFieldSorting(
Loading history...
66
                [
67
                    'StatusI18N' => 'Status'
68
                ]
69
            );
70
            $config
71
                ->getComponentByType(GridFieldDetailForm::class)
72
                ->setItemRequestClass(OrderGridFieldDetailForm_ItemRequest::class); //see below
0 ignored issues
show
Bug introduced by
The method setItemRequestClass() does not exist on SilverStripe\Forms\GridField\GridFieldComponent. It seems like you code against a sub-type of SilverStripe\Forms\GridField\GridFieldComponent such as SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\Tests...ndlerTest\TestComponent or SilverStripe\Forms\GridField\GridFieldDetailForm. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
                ->/** @scrutinizer ignore-call */ setItemRequestClass(OrderGridFieldDetailForm_ItemRequest::class); //see below
Loading history...
73
        }
74
        if ($this->modelClass == $this->sanitiseClassName(OrderStatusLog::class)) {
75
            /** @var GridFieldConfig $config */
76
            $config = $form->Fields()->fieldByName($this->modelClass)->getConfig();
77
            // Remove add new button
78
            $config->removeComponentsByType($config->getComponentByType(GridFieldAddNewButton::class));
0 ignored issues
show
Bug introduced by
$config->getComponentByT...eldAddNewButton::class) of type SilverStripe\Forms\GridField\GridFieldComponent is incompatible with the type string|string[] expected by parameter $types of SilverStripe\Forms\GridF...emoveComponentsByType(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

78
            $config->removeComponentsByType(/** @scrutinizer ignore-type */ $config->getComponentByType(GridFieldAddNewButton::class));
Loading history...
79
        }
80
81
        return $form;
82
    }
83
}
84