public function saveToDB($poiId, $componentId, $stageRating) { global $secKeys; $now = date("Y-m-d H:i:s"); try { DataBase::connect('localhost', $secKeys->cakeVars->{'dbUsr'}, $secKeys->cakeVars->{'dbPw'}, $secKeys->cakeVars->{'dbCake'}); $sql = "INSERT INTO stages (component_id, poi_id, created, modified, rating) VALUES (:component_id, :poi_id, :tstamp, :tstamp, :rating)"; $para = array('component_id' => $componentId, 'poi_id' => $poiId, 'tstamp' => $now, 'rating' => $stageRating); DataBase::fire($sql, $para); $this->savedStagesCount = DataBase::lastInsertId(); DataBase::close(); } catch (Exception $e) { die('Fehler bei .... Fehler: ' . $e->getMessage()); } }
public function saveToDB($filterdQueryData) { global $secKeys; ControlFunctions::forDebug($filterdQueryData, "Gefilterte Pois"); // for ($i = 0; $i < 5; $i++) { for ($i = 0; $i < count($filterdQueryData); $i++) { $now = date("Y-m-d H:i:s"); try { DataBase::connect('localhost', $secKeys->cakeVars->{'dbUsr'}, $secKeys->cakeVars->{'dbPw'}, $secKeys->cakeVars->{'dbCake'}); $sql = "INSERT INTO pois (created, modified, name, lat, lng, google_place, icon, rating, vicinity) VALUES (:tstamp, :tstamp, :name, :lat, :lng, :google_place, :icon, :rating, :vicinity)"; $para = array('tstamp' => $now, 'name' => $filterdQueryData[$i]->name, 'lat' => $filterdQueryData[$i]->geometry->location->lat, 'lng' => $filterdQueryData[$i]->geometry->location->lng, 'google_place' => $filterdQueryData[$i]->place_id, 'icon' => $filterdQueryData[$i]->icon, 'rating' => isset($filterdQueryData[$i]->rating) ? $filterdQueryData[$i]->rating : null, 'vicinity' => $filterdQueryData[$i]->vicinity); DataBase::fire($sql, $para); $lastPoisId = DataBase::lastInsertId(); echo ControlFunctions::tagIt("h1", "Letzter Eintrag: " . $lastPoisId); foreach ($filterdQueryData[$i]->types as $tag) { $tagId = null; // Check if tag is already present $sql = "SELECT EXISTS(SELECT 1 FROM tags WHERE title LIKE '%" . $tag . "%')"; $rows = DataBase::fire($sql); $tagPresent = current(current($rows)) == "1" ? true : false; ControlFunctions::forDebug($rows, "Ausgabe für Tag {$tag}"); echo $tagPresent ? "Wert für {$tag} ist: vorhanden" : "Wert für {$tag} ist: Nicht existent!"; if ($tagPresent) { $sql = "SELECT id FROM tags WHERE title LIKE '%" . $tag . "%'"; $rows = DataBase::fire($sql); $tagId = current(current($rows)); ControlFunctions::forDebug($rows, "Ausgabe für Tag {$tag}, tag ID: "); echo ControlFunctions::tagIt("h1", "{$tag} ID: {$tagId}"); } else { // Paste Tag $sql = "INSERT INTO tags (title, created, modified) VALUES (:title, :tstamp, :tstamp)"; $para = array('title' => $tag, 'tstamp' => $now); DataBase::fire($sql, $para); // Save ID $tagId = DataBase::lastInsertId(); } // Paste Relation $sql = "INSERT INTO pois_tags (poi_id, tag_id) VALUES (:poi_id, :tag_id)"; $para = array('poi_id' => $lastPoisId, 'tag_id' => $tagId); DataBase::fire($sql, $para); echo ControlFunctions::tagIt("h1", "Letzter Eintrag: " . DataBase::lastInsertId()); } DataBase::close(); } catch (Exception $e) { die('Fehler bei .... Fehler: ' . $e->getMessage()); } } }