/** * @param int $ID ID of the section to delete. * @return int 1 if the section was deleted, 0 if the section does not exist in the database. */ public function delete($ID) { $osamaps = new OnpubSAMaps($this->pdo, FALSE); $owsmaps = new OnpubWSMaps($this->pdo, FALSE); if ($this->enableTransactions) { $status = $this->pdo->beginTransaction(); OnpubDatabase::verifyTransaction($this->pdo, $status); } try { $osamaps->delete($ID, NULL); } catch (PDOException $e) { if ($this->enableTransactions) { $this->pdo->rollBack(); } throw $e; } try { $owsmaps->delete(NULL, $ID); } catch (PDOException $e) { if ($this->enableTransactions) { $this->pdo->rollBack(); } throw $e; } $stmt = $this->pdo->prepare("DELETE FROM OnpubSections WHERE ID = :ID"); OnpubDatabase::verifyPrepare($this->pdo, $stmt, $this->enableTransactions); $stmt->bindParam(':ID', $ID); $result = $stmt->execute(); OnpubDatabase::verifyExecute($this->pdo, $result, $this->enableTransactions, $stmt->errorInfo()); if ($this->enableTransactions) { $status = $this->pdo->commit(); OnpubDatabase::verifyTransaction($this->pdo, $status); } return $stmt->rowCount(); }
public function process() { $osections = new OnpubSections($this->pdo); $owsmaps = new OnpubWSMaps($this->pdo); $wsmap = new OnpubWSMap(); $wsmap->websiteID = $this->osection->websiteID; $wsmap->sectionID = $this->osection->ID; try { $osections->update($this->osection); if ($this->visible) { $owsmaps->insert($wsmap); } else { $owsmaps->delete($this->osection->websiteID, $this->osection->ID); } } catch (PDOException $e) { throw $e; } }
/** * @param OnpubWebsite $website The website to be updated. * @return int 1 if the website was updated. 0 if the website does not exist in the database. */ public function update(OnpubWebsite $website) { $owsmaps = new OnpubWSMaps($this->pdo, FALSE); $now = new DateTime(); if ($this->enableTransactions) { $status = $this->pdo->beginTransaction(); OnpubDatabase::verifyTransaction($this->pdo, $status); } $stmt = $this->pdo->prepare("UPDATE OnpubWebsites SET imageID = :imageID, name = :name, url = :url, imagesURL = :imagesURL, imagesDirectory = :imagesDirectory, modified = :modified WHERE ID = :ID"); OnpubDatabase::verifyPrepare($this->pdo, $stmt, $this->enableTransactions); $ID = $website->ID; $imageID = $website->imageID; $name = OnpubDatabase::utf8Decode(trim($website->name)); $url = OnpubDatabase::utf8Decode(trim($website->url)); $imagesURL = OnpubDatabase::utf8Decode(trim($website->imagesURL)); $imagesDirectory = OnpubDatabase::utf8Decode(trim($website->imagesDirectory)); $modified = $now->format('Y-m-d H:i:s'); $stmt->bindParam(':ID', $ID); $stmt->bindParam(':imageID', $imageID); $stmt->bindParam(':name', $name); $stmt->bindParam(':url', $url); $stmt->bindParam(':imagesURL', $imagesURL); $stmt->bindParam(':imagesDirectory', $imagesDirectory); $stmt->bindParam(':modified', $modified); $result = $stmt->execute(); OnpubDatabase::verifyExecute($this->pdo, $result, $this->enableTransactions, $stmt->errorInfo()); try { $owsmaps->delete($website->ID, NULL); } catch (PDOException $e) { if ($this->enableTransactions) { $this->pdo->rollBack(); } throw $e; } $sections = $website->sections; $wsmaps = array(); foreach ($sections as $section) { $wsmap = new OnpubWSMap(); $wsmap->websiteID = $section->websiteID; $wsmap->sectionID = $section->ID; $wsmaps[] = $wsmap; } try { $owsmaps->insert($wsmaps); } catch (PDOException $e) { if ($this->enableTransactions) { $this->pdo->rollBack(); } throw $e; } if ($this->enableTransactions) { $status = $this->pdo->commit(); OnpubDatabase::verifyTransaction($this->pdo, $status); } return $stmt->rowCount(); }