public static function update($trap_id) { self::check_logged_in(); $params = $_POST; $attributes = array('trap_id' => $trap_id, 'trap_type' => $params['trap_type'], 'trap_model' => $params['trap_model'], 'trap_size' => $params['trap_size'], 'trap_color' => $params['trap_color'], 'picture_url' => $params['picture_url'], 'in_use' => $params['in_use']); $trap = new Trap($attributes); $errors = $trap->errors(); if (count($errors) === 0) { $trap->update(); Redirect::to('/trap/' . $trap->trap_id, array('trap' => $trap, 'message' => "Pyydystieto päivitettiin onnistuneesti!")); } else { $trap_types = Trap::types(); View::make('trap/updateTrap.html', array('errors' => $errors, 'attributes' => $attributes, 'trap_types' => $trap_types)); } }
public static function store() { self::check_logged_in(); $params = $_POST; $attributes = array('date' => $params['date'], 'time' => $params['time'], 'species' => $params['species'], 'count' => $params['count'], 'length' => $params['length'], 'weight' => $params['weight'], 'water_sys' => $params['water_sys'], 'location' => $params['location'], 'wind_speed' => $params['wind_speed'], 'wind_dir' => $params['wind_dir'], 'air_temp' => $params['air_temp'], 'water_temp' => $params['water_temp'], 'cloudiness' => $params['cloudiness'], 'notes' => $params['notes'], 'picture_url' => $params['picture_url'], 'trap_type' => $params['trap_type'], 'trap_id' => $params['trap_model']); if (isset($params['friends'])) { $attributes['friends'] = $params['friends']; } //Kint::dump($attributes); $catch = new CatchModel($attributes); $errors = $catch->errors(); //Kint::dump($errors); if (count($errors) === 0) { $catch->save(); //Kint::dump($catch->catch_id); Redirect::to("/catchList/" . $catch->catch_id . "", array('message' => 'Saalistieto lisättiin onnistuneesti!')); } else { $traps = Trap::in_use(); $trap_types = Trap::types(); View::make('catch/newCatch.html', array('errors' => $errors, 'attributes' => $attributes, 'traps' => $traps, 'trap_types' => $trap_types, 'friend_of' => $_SESSION['friend_of'])); } }