Exemplo n.º 1
0
        } else {
            // Prihlasenie zlyhalo
            $app['session']->getFlashBag()->add('error', 'Zadal si nespravne meno alebo heslo.');
        }
    }
    return $app['twig']->render('login.twig', array('form' => $form->createView()));
})->bind('login.process');
/**
 * Sekcia pre ucitelov
 */
$app->post('/zadanie/new', function (Symfony\Component\HttpFoundation\Request $request) use($app) {
    $user = $app['session']->get('user');
    if ($user['role'] != 2) {
        throw new Exception('Permission denied');
    }
    $zadanie = new Zadanie();
    $zadanie->setPouzivatelId($user['id']);
    $form = $app['form.factory']->create(new ZadanieForm($app['repository.triedy'], $app['repository.predmety']), $zadanie);
    $form->bind($request);
    if ($form->isValid()) {
        $app['zadania_service']->save($zadanie);
        $app['session']->getFlashBag()->add('success', 'Zadanie bolo pridane.');
    }
    return new RedirectResponse($app['url_generator']->generate('home'));
})->before($checkUser)->bind('zadanie.new');
$app->get('/zadanie/{id}/delete', function (Silex\Application $app, $id) {
    $user = $app['session']->get('user');
    if ($user['role'] != 2) {
        throw new Exception('Permission denied');
    }
    $app['zadania_service']->delete($id);
Exemplo n.º 2
0
 public function save(Zadanie $zadanie)
 {
     $zadanieData = array('nazov' => $zadanie->getNazov(), 'trieda_id' => $zadanie->getTriedaId(), 'pouzivatel_id' => $zadanie->getPouzivatelId(), 'predmet_id' => $zadanie->getPredmetId(), 'stav' => $zadanie->getStav(), 'cas_uzatvorenia' => $zadanie->getCasUzatvorenia());
     if ($zadanie->getId()) {
         $this->db->update('zadania', $zadanieData, array('zadanie_id' => $zadanie->getId()));
     } else {
         $this->db->insert('zadania', $zadanieData, array(PDO::PARAM_STR, PDO::PARAM_INT, PDO::PARAM_INT, PDO::PARAM_INT, PDO::PARAM_INT, 'datetime'));
         $id = $this->db->lastInsertId();
         $zadanie->setId($id);
     }
 }