Ejemplo n.º 1
0
 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;
     }
 }
Ejemplo n.º 2
0
 /**
  * @param mixed $sections A single {@link OnpubSection} object or an array of {@link OnpubSection} objects (to insert multiple sections at a time).
  * @return mixed The ID(s) of the new section(s). An int will be returned if a single section was inserted. An array of ints will be returned if multiple sections were inserted.
  * @throws PDOException if there's a database error.
  */
 public function insert($sections, $insertWSMaps = FALSE)
 {
     $oimages = new OnpubImages($this->pdo, FALSE);
     $owsmaps = new OnpubWSMaps($this->pdo, FALSE);
     $IDs = array();
     $isArray = TRUE;
     $wsmaps = array();
     if (!is_array($sections)) {
         $sections = array($sections);
         $isArray = FALSE;
     }
     if ($this->enableTransactions) {
         $status = $this->pdo->beginTransaction();
         OnpubDatabase::verifyTransaction($this->pdo, $status);
     }
     $stmt = $this->pdo->prepare("INSERT INTO OnpubSections (ID, imageID, websiteID, parentID, name, url, created, modified) VALUES (:ID, :imageID, :websiteID, :parentID, :name, :url, :created, :modified)");
     OnpubDatabase::verifyPrepare($this->pdo, $stmt, $this->enableTransactions);
     foreach ($sections as $section) {
         if ($section->image) {
             try {
                 $imageID = $oimages->insert($section->image);
                 $section->imageID = $imageID;
             } catch (PDOException $e) {
                 if ($this->enableTransactions) {
                     $this->pdo->rollBack();
                 }
                 throw $e;
             }
         }
         try {
             $ID = $this->getID($section);
         } catch (PDOException $e) {
             if ($this->enableTransactions) {
                 $this->pdo->rollBack();
             }
             throw $e;
         }
         if ($ID) {
             $IDs[] = $ID;
             $section->ID = $ID;
         } else {
             $ID = $section->ID;
             $imageID = $section->imageID;
             $websiteID = $section->websiteID;
             $parentID = $section->parentID;
             $name = OnpubDatabase::utf8Decode(trim($section->name));
             $url = OnpubDatabase::utf8Decode(trim($section->url));
             $created = $section->getCreated()->format('Y-m-d H:i:s');
             $modified = $section->getModified()->format('Y-m-d H:i:s');
             $stmt->bindParam(':ID', $ID);
             $stmt->bindParam(':imageID', $imageID);
             $stmt->bindParam(':websiteID', $websiteID);
             $stmt->bindParam(':parentID', $parentID);
             $stmt->bindParam(':name', $name);
             $stmt->bindParam(':url', $url);
             $stmt->bindParam(':created', $created);
             $stmt->bindParam(':modified', $modified);
             $result = $stmt->execute();
             OnpubDatabase::verifyExecute($this->pdo, $result, $this->enableTransactions, $stmt->errorInfo());
             $IDs[] = $this->pdo->lastInsertId();
             $section->ID = $this->pdo->lastInsertId();
         }
         $wsmap = new OnpubWSMap();
         $wsmap->websiteID = $section->websiteID;
         $wsmap->sectionID = $section->ID;
         $wsmap->setCreated($section->getCreated());
         $wsmap->setModified($section->getModified());
         $wsmaps[] = $wsmap;
     }
     if ($insertWSMaps) {
         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);
     }
     if ($isArray) {
         return $IDs;
     } else {
         return end($IDs);
     }
 }
Ejemplo n.º 3
0
 /**
  * @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();
 }