CountryPrice_CopyPrices_Controller   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 7
dl 0
loc 42
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_link() 0 4 1
A index() 0 13 4
A Link() 0 4 1
1
<?php
2
3
class CountryPrice_CopyPrices_Controller extends ContentController
4
{
5
    private static $url_segment = 'shoppingcart-copy-prices';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
6
7
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
8
        "index" => 'ADMIN'
9
    );
10
11
12
    public static function get_link(DataObject $object)
13
    {
14
        return Injector::inst()->get('CountryPrice_CopyPrices_Controller')->Link()."?class={$object->ClassName}&id={$object->ID}";
15
    }
16
17
    /**
18
     * requires the following _GET variables:
19
     *  - class
20
     *  - id
21
     *  - from (country code)
22
     *  - to (country code or codes!), using commas ...
23
     *
24
     */
25
    public function index()
26
    {
27
        if (Permission::check('ADMIN')) {
28
            $object = $_REQUEST['class']::get()->byID(intval($_REQUEST['id']));
29
            if ($object && $object->hasMethod('updatePrices')) {
30
                $object->updatePrices(Convert::raw2sql($_REQUEST['From']), explode(',', Convert::raw2sql($_REQUEST['To'])));
31
                echo '<p>All prices updated from <strong>'.$_REQUEST['From'].'</strong> to <strong>'.$_REQUEST['To'].'</strong></p>';
32
                return;
33
            }
34
        } else {
35
            echo "please log in as admin first";
36
        }
37
    }
38
39
40
    public function Link($action = null)
41
    {
42
        return Controller::join_links(Config::inst()->get('CountryPrice_CopyPrices_Controller', 'url_segment'), $action);
43
    }
44
}
45