/*galeria zapisywana jest do bazy danych. Potem wyciągany jest jest id i tworzony katalog o takim id w folderze galeria. Przerzucamy tam pliki*/
public function executeZapiszgalerie(sfWebRequest $request)
{
if($request->isXmlHttpRequest()) {
$connection = Propel::getConnection();
$connection->beginTransaction();
$pokaznazwe = $this->getRequestParameter('pokaznazwe');
$nazwa = $this->getRequestParameter('nazwa');
$tytul = $this->getRequestParameter('tytul');
$status = $this->getRequestParameter('status');
$wyrownanie = $this->getRequestParameter('wyrownanie');
$tytulyzdjec = $this->getRequestParameter('tytulyzdjec');
$nazwyzdjec = $this->getRequestParameter('nazwyzdjec');
$kolejnosc = $this->getRequestParameter('kolejnosc');
$dostep = $this->getRequestParameter('dostep');
try {
$c1= new Galerie();
$c1->setNazwa($nazwa);
$c1->setTytul($tytul);
$c1->setAktywnosc($status);
$c1->setDostep($dostep);
$c1->setWyrownanie($wyrownanie);
$c1->setPokaztytul($pokaznazwe);
$c1->save($connection);
/* wybranie id nowo dodanej galeri */
$zapytanie = "SELECT max(i.id_galeri) as max FROM galerie i";
$wykonaj = $connection->prepare($zapytanie);
$wykonaj->execute();
$resultset = $wykonaj->fetch(PDO::FETCH_OBJ);
if($resultset->max) {
$wynik = $resultset->max;
} else {
$wynik = 1;
}
/* dodanie zdjęć i tytułów zdjęć do bazy danych*/
$sql = 'INSERT INTO galerie_zdjecia (tytul, id_galerii, nazwa, pozycja) VALUES (:tytul, :id_galerii, :nazwa, :pozycja)';
$statement = $connection->prepare($sql);
$count = 0;
foreach ($nazwyzdjec as $key => $value) {
$statement->bindValue(':tytul', $tytulyzdjec[$kolejnosc[$count]-1]);
$statement->bindValue(':id_galerii', $wynik);
$statement->bindValue(':nazwa', $value);
$statement->bindValue(':pozycja', $count+1);
$result = $statement->execute();
$count++;
}
$connection->commit(); // zatwierdzenie
} catch (Exception $e) {
$connection->rollback();
$response['error'] = $e->getMessage();
$this->status = json_encode($response);
}
try {
$galeriafoldery = new galeria_foldery('galeriana');
} catch(Exception $e) {
$response['error'] = $e->getMessage();
$this->status = json_encode($response);
}
}