Xhgui_Controller_Watch::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
use Slim\Slim;
4
5
class Xhgui_Controller_Watch extends Xhgui_Controller
6
{
7
    /**
8
     * @var Xhgui_Searcher_Interface
9
     */
10
    protected $searcher;
11
12
    public function __construct(Slim $app, Xhgui_Searcher_Interface $searcher)
13
    {
14
        parent::__construct($app);
15
        $this->searcher = $searcher;
16
    }
17
18
    public function get()
19
    {
20
        $watched = $this->searcher->getAllWatches();
21
22
        $this->_template = 'watch/list.twig';
23
        $this->set(array('watched' => $watched));
24
    }
25
26
    public function post()
27
    {
28
        $saved = false;
29
        $request = $this->app->request();
30
        foreach ((array)$request->post('watch') as $data) {
31
            $saved = true;
32
            $this->searcher->saveWatch($data);
33
        }
34
        if ($saved) {
35
            $this->app->flash('success', 'Watch functions updated.');
36
        }
37
        $this->app->redirect($this->app->urlFor('watch.list'));
38
    }
39
}
40