public function save()
{
$pdo_connection = DB::connection();
$success = true;
//the begin of transaction
$pdo_connection->beginTransaction();
try {
$query = $pdo_connection->prepare("INSERT INTO saalistieto (pvm, kellonaika," . " kalalaji, lkm, pituus, paino, vesisto, paikka, tuulenvoimakkuus," . " tuulensuunta, ilmanlampo, vedenlampo, pilvisyys, huomiot," . " saaliskuva, pyydys) VALUES(:pvm, NULLIF(:aika,'')::time, :laji, :lkm," . " NULLIF(:pituus,'')::numeric, NULLIF(:paino,'')::numeric, :vesisto," . " :paikka, :tuulenVoima, :tuulenSuunta," . " NULLIF(:ilmanLampo,'')::integer, NULLIF(:vedenLampo,'')::integer, :pilvisyys," . " :huomiot, :kuva, NULLIF(:pyydys,'default')::integer) RETURNING saalisid");
$query->execute(array('pvm' => $this->date, 'aika' => $this->time, 'laji' => $this->species, 'lkm' => $this->count, 'pituus' => $this->length, 'paino' => $this->weight, 'vesisto' => $this->water_sys, 'paikka' => $this->location, 'tuulenVoima' => $this->wind_speed, 'tuulenSuunta' => $this->wind_dir, 'ilmanLampo' => $this->air_temp, 'vedenLampo' => $this->water_temp, 'pilvisyys' => $this->cloudiness, 'huomiot' => $this->notes, 'kuva' => $this->picture_url, 'pyydys' => $this->trap_id));
$resultRow = $query->fetch();
$this->catch_id = $resultRow['saalisid'];
$catchers;
$username = array($_SESSION['user']);
if (isset($this->friends)) {
$catchers = array_merge($username, $this->friends);
} else {
$catchers = $username;
}
$query_2 = $pdo_connection->prepare("INSERT INTO pyydystaja VALUES(" . ":kalastaja, :saalisid)");
foreach ($catchers as $catcher) {
$query_2->execute(array('kalastaja' => $catcher, 'saalisid' => $this->catch_id));
}
} catch (PDOException $e) {
$success = false;
Kint::dump($e);
Kint::trace();
}
//end of transaction
if (!$success) {
$pdo_connection->rollBack();
} else {
$pdo_connection->commit();
}
}