AllOrdersReport::sourceRecords()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 4
nop 3
1
<?php
2
/**
3
 * An extension to {@link SSReport} that allows a user
4
 * to view all Order instances in the system.
5
 *
6
 *
7
 * @authors: Silverstripe, Jeremy, Nicolaas
8
 *
9
 * @package: ecommerce
10
 * @sub-package: reports
11
 *
12
 **/
13
14
class AllOrdersReport extends SS_Report
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
15
{
16
    protected $title = 'All orders';
17
18
    protected $description = 'Show all orders in the system.';
19
20
    public function sourceRecords($params, $sort = "", $limit = "")
0 ignored issues
show
Unused Code introduced by
The parameter $sort is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    {
22
        $filters = array();
23
        if (isset($params['OrderID']) && $params['OrderID']) {
24
            $filters[] = "\"ID\" = ".$params['OrderID'];
25
        }
26
        if (isset($params['Status']) && $params['Status']) {
27
            $filters[] = "\"Status\" = '".$params['Status']."'";
28
        }
29
        $sort = "";
30
        $filter = implode(" AND ", $filters);
31
        return DataObject::get('Order', $filter, $sort, "", $limit);
32
    }
33
34
    public function columns()
35
    {
36
        $cols = Order::get_summary_fields();
37
        $cols['Invoice'] = 'Invoice';
38
        return $cols;
39
    }
40
41
    public function getReportField()
42
    {
43
        $tlf = parent::getReportField();
44
        $tlf->setFieldFormatting(array(
45
            'Invoice' => '<a target=\"_blank\" href=\"OrderReport_Popup/invoice/$ID\">'.i18n::_t('Report.VIEW', 'view').'</a> ' .
46
                    '<a target=\"_blank\" href=\"OrderReport_Popup/index/$ID?print=1\">'.i18n::_t('Report.PRINT', 'print').'</a>',
47
        ));
48
        $tlf->setFieldCasting(array(
49
            'Created' => 'Date->Long',
50
            'Total' => 'Currency->Nice'
51
        ));
52
        $tlf->setPermissions(array('edit', 'show', 'export', 'delete', 'print'));
53
        return $tlf;
54
    }
55
56
    public function parameterFields()
57
    {
58
        $fields = new FieldSet(
59
            new TextField('OrderID', 'Order No'),
60
            new DateField('Created', 'Created'),
61
            //new TextField('FirstName','First Name'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
62
            //new TextField('Surname','Surname'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63
            //new NumericField('Total','Total'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
64
            $ddf = new DropdownField('StatusID', 'Status', DataObject::get("OrderStep")->toDropdownMap())
65
        );
66
        $ddf->setHasEmptyDefault(true);
67
        return $fields;
68
    }
69
}
70