public static function poista($bra_id)
 {
     self::check_logged_in();
     $brandi = new Brandi(array('bra_id' => $bra_id));
     $brandi->destroy();
     Redirect::to('/brandi', array('message' => 'Brändi on  nyt poistettu onnistuneesti!'));
 }
 public static function update($as_id)
 {
     $params = $_POST;
     $brandit = $params['brandit'];
     $omistajat = $params['omistajat'];
     $attributes = array('as_id' => $as_id, 'nimi' => $params['nimi'], 'vari' => $params['vari'], 'koko' => $params['koko'], 'hinta' => $params['hinta'], 'muoto' => $params['muoto'], 'malli' => $params['malli'], 'brandit' => array(), 'omistajat' => array());
     foreach ($brandit as $brandi) {
         $attributes['brandit'][] = $brandi;
     }
     foreach ($omistajat as $omistaja) {
         $attributes['omistajat'][] = $omistaja;
     }
     $astia = new Astiat($attributes);
     $errors = $astia->errors();
     if (count($errors) > 0) {
         View::make('/astia/muutos.html', array('errors' => $errors, 'attributes' => $attributes, 'brandit' => Brandi::all(), 'omistajat' => Omistaja::all()));
     } else {
         $astia->update();
         Redirect::to('/astia/' . $astia->as_id, array('message' => 'Astiaa on nyt muokattu onnistuneesti!'));
     }
 }
Пример #3
0
 public static function find($as_id)
 {
     $query = DB::connection()->prepare('SELECT * FROM Astiat WHERE as_id = :as_id LIMIT 1');
     $query->execute(array('as_id' => $as_id));
     $row = $query->fetch();
     if ($row) {
         $astia = new Astiat(array('as_id' => $row['as_id'], 'nimi' => $row['nimi'], 'vari' => $row['vari'], 'koko' => $row['koko'], 'hinta' => $row['hinta'], 'muoto' => $row['muoto'], 'malli' => $row['malli'], 'omistajat' => Omistaja::findOmistaja($as_id), 'brandit' => Brandi::findBrandi($as_id)));
         return $astia;
     }
     return null;
 }