public static function paivita($id) { self::check_logged_in_as_admin(); $params = $_POST; $attributes = array('id' => $id, 'nimi' => $params['nimi'], 'kuvaus' => $params['kuvaus']); $aihe = new Aihe($attributes); $errors = $aihe->errors(); if (count($errors) > 0) { View::make('aihe/muokkaa.html', array('errors' => $errors, 'attributes' => $attributes)); } else { $aihe->paivita(); Redirect::to('/aihe/' . $aihe->id, array('message' => 'Aiheen kuvausta on muokattu onnistuneesti!')); } }
public static function update($id) { self::check_moderator(); $params = $_POST; $vanhaaihe = Aihe::find($id); $attributes = array('id' => $id, 'nimi' => $params['nimi'], 'luontiaika' => $vanhaaihe->luontiaika, 'luoja_id' => $vanhaaihe->luoja_id); $aihe = new Aihe($attributes); $errors = $aihe->errors(); if (count($errors) == 0) { $aihe->update(); Redirect::to('/aihelistaus/' . $aihe->id, array('message' => 'Aiheen muokkaus onnistui')); } else { View::make('aihe/edit.html', array('aihe' => $aihe, 'errors' => $errors)); } }
public static function lisaaAihe($alueId) { $lomakkeenTiedot = $_POST; $aihe = new Aihe(array('aihealue' => $alueId)); $virheetAihe = $aihe->errors(); if (count($virheetAihe) == 0) { $aloitus = new Vastaus(array('otsikko' => $lomakkeenTiedot['otsikko'], 'teksti' => $lomakkeenTiedot['teksti'], 'laatija' => BaseController::get_user_logged_in()->id, 'aihe' => -1)); $virheetAloitus = $aloitus->errors(); if (count($virheetAloitus) == 0) { $aihe->lisaa(); $aloitus->aihe = $aihe->id; $aloitus->lisaa(); Redirect::to('/aihe/' . $aihe->id); } } $aihealue = Aihealue::haeYksi($alueId); View::make('uusiAihe.html', array('aihealue' => $aihealue, 'virheet' => $virheetAloitus, 'aloitus' => $aloitus)); }