RemoveFacebookItemController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Link() 0 4 1
A remove() 0 8 2
1
<?php
2
3
namespace SunnysideUp\ShareThis;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\Core\Convert;
7
use SunnysideUp\ShareThis\FacebookFeed_Item;
8
use SilverStripe\Control\Controller;
9
10
/**
11
 * RemoveFacebookItemController
12
 */
13
class RemoveFacebookItemController extends Controller
14
{
15
    /**
16
     * @var array
17
     */
18
    private static $allowed_actions = [
0 ignored issues
show
introduced by MasseyIsaako
The private property $allowed_actions is not used, and could be removed.
Loading history...
19
        'remove' => 'ADMIN'
20
    ];
21
22
    /**
23
     * @var string
24
     */
25
    private static $url_segment = 'removefacebooklink';
0 ignored issues
show
introduced by Nicolaas
The private property $url_segment is not used, and could be removed.
Loading history...
26
27
    /**
28
     * Link
29
     *
30
     * @return  string
31
     */
32
    public function Link($action = null)
33
    {
34
        $urlSegment = Config::inst()->get(RemoveFacebookItemController::class, 'url_segment');
35
        return '/'.$urlSegment.'/'.$action;
36
    }
37
38
    /**
39
     * remove
40
     *
41
     * @return void
42
     */
43
    public function remove($request)
44
    {
45
        $uid = Convert::raw2sql($request->param('ID'));
46
        $item = FacebookFeed_Item::get()->filter(array("UID" => $uid))->first();
47
        if ($item) {
0 ignored issues
show
introduced by sunnysideup
$item is of type SilverStripe\ORM\DataObject, thus it always evaluated to true.
Loading history...
48
            $item->Hide = true;
49
            $item->write();
50
            $this->redirect('/?flush=all');
51
        }
52
    }
53
}
54