Completed
Pull Request — master (#331)
by Elan
01:21
created

WatchController::__construct()   A

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
namespace XHGui\Controller;
4
5
use Slim\Slim;
6
use XHGui\Searcher\SearcherInterface;
7
use XHGui\AbstractController;
8
9
class WatchController extends AbstractController
10
{
11
    /**
12
     * @var SearcherInterface
13
     */
14
    protected $searcher;
15
16
    public function __construct(Slim $app, SearcherInterface $searcher)
17
    {
18
        parent::__construct($app);
19
        $this->searcher = $searcher;
20
    }
21
22
    public function get()
23
    {
24
        $watched = $this->searcher->getAllWatches();
25
26
        $this->_template = 'watch/list.twig';
27
        $this->set(['watched' => $watched]);
28
    }
29
30
    public function post()
31
    {
32
        $saved = false;
33
        $request = $this->app->request();
34
        foreach ((array)$request->post('watch') as $data) {
35
            $saved = true;
36
            $this->searcher->saveWatch($data);
37
        }
38
        if ($saved) {
39
            $this->app->flash('success', 'Watch functions updated.');
40
        }
41
        $this->app->redirect($this->app->urlFor('watch.list'));
42
    }
43
}
44