PlaylistService::init(); $pldata = array(); foreach (PlaylistService::getData() as $pld) { $pldata[$pld['id']] = $pld['name']; } $form = $app['form.factory']->createBuilder('form')->add('playlist', 'choice', array('choices' => $pldata, 'expanded' => true, 'constraints' => $request->request->get('stop') ? array() : array(new Assert\Choice(array_keys($pldata)), new Assert\NotNull())))->add('security', 'password', array('constraints' => array(new Security()), 'attr' => array('placeholder' => 'Biztonsági kód'), 'label' => 'Biztonsági kód'))->getForm(); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $data = $form->getData(); $saved = false; if ($request->request->get('stop')) { PlaylistService::disablePlaylist(true); $saved = PlaylistService::savePlaylist(); } if ($request->request->get('play')) { PlaylistService::disablePlaylist(true); PlaylistService::enablePlaylist($data['playlist']); $saved = PlaylistService::savePlaylist(); } if ($saved) { $daemon = new Kiosk\Daemon(); $daemon->reload(); } // return $app->redirect('/playlist'); } } // display the form return $app['twig']->render('playlist.twig', array('form' => $form->createView(), 'permission_error' => !PlaylistService::isWritable())); }); return $app;
$pldata[$pld['id']] = $pld['name']; } if ('POST' == $_SERVER['REQUEST_METHOD']) { $saved = false; // Stop if (isset($_POST['stop'])) { PlaylistService::disablePlaylist(true); $saved = PlaylistService::savePlaylist(); } // Play if (isset($_POST['play'])) { if (!isset($_POST['form']['playlist']) || !in_array($_POST['form']['playlist'], array_keys($pldata))) { h('error', 'Nem választottál ki semmit!'); } else { PlaylistService::disablePlaylist(true); PlaylistService::enablePlaylist($_POST['form']['playlist']); $saved = PlaylistService::savePlaylist(); } } // Refresh if (isset($_POST['refresh'])) { try { $saved = PlaylistService::refreshPlaylist($config['datadir']); $pldata = array(); foreach (PlaylistService::getData() as $pld) { $pldata[$pld['id']] = $pld['name']; } } catch (Exception $e) { h('error', $e->getMessage()); } }