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