Update for toolbox code
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 28 Jul 2014 14:37:46 +0000 (10:37 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 28 Jul 2014 14:37:46 +0000 (10:37 -0400)
If they have coupons but no members.
Will have to update demo on this too.

Toolkit/Toolbox/PageGatewayDraft.php

index 2b51dfe..7a4e165 100644 (file)
@@ -1,29 +1,29 @@
 <?php
 class Toolkit_Toolbox_PageGatewayDraft
-       extends Toolkit_Toolbox_PageGatewayAbstract
+    extends Toolkit_Toolbox_PageGatewayAbstract
 {
-       //      {{{     delete()
+    //  {{{ delete()
 
-       public function delete($id)
-       {
-               $pageSql = "
+    public function delete($id)
+    {
+        $pageSql = "
             DELETE
               FROM pages_draft
              WHERE id = :id";
 
-               try {
-                       $stmt = $this->dbh->prepare($pageSql);
-                       $stmt->bindParam(':id', $id, PDO::PARAM_INT);
-                       return $stmt->execute();
-               } catch (PDOException $e) {
-                       Toolkit_Logger::logException('DB Error', $e);
-                       throw new Toolkit_Toolbox_Exception(
-                               "Unable to delete page draft `$id`"
-                       );
-               }
-       }
-
-       //      }}}
+        try {
+            $stmt = $this->dbh->prepare($pageSql);
+            $stmt->bindParam(':id', $id, PDO::PARAM_INT);
+            return $stmt->execute();
+        } catch (PDOException $e) {
+            Toolkit_Logger::logException('DB Error', $e);
+            throw new Toolkit_Toolbox_Exception(
+                "Unable to delete page draft `$id`"
+            );
+        }
+    }
+
+    //  }}}
     public function findNavItem($id)
     {
         $sql = "
@@ -31,7 +31,7 @@ class Toolkit_Toolbox_PageGatewayDraft
               FROM pages
              WHERE id = :id";
 
-               try {
+        try {
             $stmt = $this->dbh->prepare($sql);
             $stmt->bindParam(
                 ':id',
@@ -39,17 +39,17 @@ class Toolkit_Toolbox_PageGatewayDraft
                 PDO::PARAM_INT
             );
             $stmt->execute();
-                       return $stmt->fetch(PDO::FETCH_ASSOC);
-               } catch (PDOException $e) {
-                       Toolkit_Logger::logException('DB Error', $e);
-                       throw new Toolkit_Toolbox_Exception("Unable to find page `$id`");
-               }
+            return $stmt->fetch(PDO::FETCH_ASSOC);
+        } catch (PDOException $e) {
+            Toolkit_Logger::logException('DB Error', $e);
+            throw new Toolkit_Toolbox_Exception("Unable to find page `$id`");
+        }
     }
-       //      {{{     find()
+    //  {{{ find()
 
-       public function find($id)
-       {
-               $pageSql = "
+    public function find($id)
+    {
+        $pageSql = "
             SELECT p1.*, p1.id AS page_id,
                    CASE p1.active
                    WHEN true THEN 'active'
@@ -61,467 +61,469 @@ class Toolkit_Toolbox_PageGatewayDraft
              WHERE p1.id  = :id
                AND (p2.pos = 1 OR p2.pos IS NULL)";
 
-               try {
-                       return $this->findPage($id, $pageSql);
-               } catch (PDOException $e) {
-                       Toolkit_Logger::logException('DB Error', $e);
-                       throw new Toolkit_Toolbox_Exception(
-                               "Unable to find page draft `$id`"
-                       );
-               }
-       }
-
-       //      }}}
-       //      {{{     findAll()
-
-       public function findAll()
-       {
-               try {
-                       $sql = "
-                               SELECT *
-                                 FROM pages_draft
-                                ORDER by parent, pos";
-
-                       return $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
-               } catch (PDOException $e) {
-                       Toolkit_Logger::logException('DB Error', $e);
-                       throw new Toolkit_Toolbox_Exception(
-                               'Error fetching all draft pages'
-                       );
-               }
-       }
-
-       //      }}}
-       //      {{{     findByKeyword()
-
-       public function findByKeyword($keyword)
-       {
-               try {
-                       $pageSql = "
-                               SELECT id
-                                 FROM pages_draft
-                                WHERE keyword = :keyword";
-
-                       $stmt = $this->dbh->prepare($pageSql);
-                       $stmt->bindParam(':keyword', $keyword);
-                       $stmt->execute();
-
-                       // Bind by column number
-                       $stmt->bindColumn(1, $id);
-
-                       $stmt->fetch(PDO::FETCH_ASSOC);
-
-                       return $this->find($id);
-               } catch (PDOException $e) {
-                       Toolkit_Logger::logException('DB Error', $e);
-                       throw new Toolkit_Toolbox_Exception(
-                               "Unable to find page draft `$id`"
-                       );
-               }
-       }
-
-       //      }}}
-       //      {{{     findTopParent()
-
-       public function findTopParent($pageId, $useDraftTable = true)
-       {
-               if (!ctype_digit((string)$pageId)) {
-                       throw new runtimeException("Invalid pageId `$pageId` to fetch");
-               }
-
-               try {
-                       if ($useDraftTable) {
-                               $sql = "
-                                       SELECT *
-                                         FROM pages_draft
-                                        WHERE id = :id";
-                       } else {
-                               $sql = "
-                                       SELECT *
-                                         FROM pages
-                                        WHERE id = :id";
-                       }
-
-                       $stmt = $this->dbh->prepare($sql);
-                       $stmt->bindParam(':id', $pageId, PDO::PARAM_INT);
-                       $stmt->execute();
-
-                       $row = $stmt->fetch(PDO::FETCH_ASSOC);
-
-                       if ($row['parent'] == '0') {
-                               return $row['id'];
-                       } else {
-                               return $this->findTopParent($row['parent'], false);
-                       }
-               } catch (PDOException $e) {
-                       Toolkit_Logger::logException('DB Error', $e);
-                       throw new Toolkit_Toolbox_Exception(
-                               "Unable to find parent for page `$pageId`"
-                       );
-               }
-       }
-
-       //      }}}
-
-       //      {{{     insert()
-
-       public function insert(array $data)
-       {
-               if (empty($data['published_page'])) {
-                       settype($data['published_page'], 'null');
-               }
-
-               if ($this->hasHeadlines()) {
-                       $headlineColumns = 'headline, headline_intro,';
-                       $headlineParams  = ':headline, :headline_intro,';
-               }
-
-               if ($this->hasMemberDb()) {
-                       $memberColumns = 'include_member_map, search_form, ';
-                       $memberParams  = ':include_member_map, :search_form, ';
-               }
-
-               $pageSql = "
-                       INSERT INTO pages_draft (
-                               $headlineColumns $memberColumns keyword, meta_title,
-                               meta_description, navigation_name, parent, paragraph_links,
-                               short_url, template, published_page, include_members, include_coupons)
-                       VALUES (
-                               $headlineParams $memberParams :keyword, :meta_title,
-                           :meta_description, :navigation_name, :parent,
-                           :paragraph_links, :short_url, :template, :published_page, :include_members, :include_coupons)";
-
-               $paragraphSql = "
-                       INSERT INTO paragraphs_draft (
-                               active, title, description, image, caption, page)
-                       VALUES (
-                               true, :title, :description, :image, :caption, :page)";
-
-               try {
-                       $this->dbh->beginTransaction();
-
-                       $pageStmt = $this->dbh->prepare($pageSql);
-                       $this->setPageVars($pageStmt, $data);
-                       $pageStmt->bindParam(':published_page', $data['published_page']);
-                       $pageStmt->execute();
-
-                       $row = $this->dbh
-                               ->query('select id from pages_draft order by id desc limit 1')
-                               ->fetch(PDO::FETCH_ASSOC);
-
-                       if (defined('MEMBERS_DB') && MEMBERS_DB) {
-                               $this->_updateMemberCategories(
-                                       $data['member_categories'],
-                                       $row['id']
-                               );
-                       }
-
-                       if (defined('COUPONS') && COUPONS) {
-                               $this->_updateCouponCategories(
-                                       $data['coupon_categories'],
-                                       $row['id']
-                               );
-                $this->_updateMemberCities(
-                    $data['member_regions'],
+        try {
+            return $this->findPage($id, $pageSql);
+        } catch (PDOException $e) {
+            Toolkit_Logger::logException('DB Error', $e);
+            throw new Toolkit_Toolbox_Exception(
+                "Unable to find page draft `$id`"
+            );
+        }
+    }
+
+    //  }}}
+    //  {{{ findAll()
+
+    public function findAll()
+    {
+        try {
+            $sql = "
+                SELECT *
+                  FROM pages_draft
+                 ORDER by parent, pos";
+
+            return $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
+        } catch (PDOException $e) {
+            Toolkit_Logger::logException('DB Error', $e);
+            throw new Toolkit_Toolbox_Exception(
+                'Error fetching all draft pages'
+            );
+        }
+    }
+
+    //  }}}
+    //  {{{ findByKeyword()
+
+    public function findByKeyword($keyword)
+    {
+        try {
+            $pageSql = "
+                SELECT id
+                  FROM pages_draft
+                 WHERE keyword = :keyword";
+
+            $stmt = $this->dbh->prepare($pageSql);
+            $stmt->bindParam(':keyword', $keyword);
+            $stmt->execute();
+
+            // Bind by column number
+            $stmt->bindColumn(1, $id);
+
+            $stmt->fetch(PDO::FETCH_ASSOC);
+
+            return $this->find($id);
+        } catch (PDOException $e) {
+            Toolkit_Logger::logException('DB Error', $e);
+            throw new Toolkit_Toolbox_Exception(
+                "Unable to find page draft `$id`"
+            );
+        }
+    }
+
+    //  }}}
+    //  {{{ findTopParent()
+
+    public function findTopParent($pageId, $useDraftTable = true)
+    {
+        if (!ctype_digit((string)$pageId)) {
+            throw new runtimeException("Invalid pageId `$pageId` to fetch");
+        }
+
+        try {
+            if ($useDraftTable) {
+                $sql = "
+                    SELECT *
+                      FROM pages_draft
+                     WHERE id = :id";
+            } else {
+                $sql = "
+                    SELECT *
+                      FROM pages
+                     WHERE id = :id";
+            }
+
+            $stmt = $this->dbh->prepare($sql);
+            $stmt->bindParam(':id', $pageId, PDO::PARAM_INT);
+            $stmt->execute();
+
+            $row = $stmt->fetch(PDO::FETCH_ASSOC);
+
+            if ($row['parent'] == '0') {
+                return $row['id'];
+            } else {
+                return $this->findTopParent($row['parent'], false);
+            }
+        } catch (PDOException $e) {
+            Toolkit_Logger::logException('DB Error', $e);
+            throw new Toolkit_Toolbox_Exception(
+                "Unable to find parent for page `$pageId`"
+            );
+        }
+    }
+
+    //  }}}
+
+    //  {{{ insert()
+
+    public function insert(array $data)
+    {
+        if (empty($data['published_page'])) {
+            settype($data['published_page'], 'null');
+        }
+
+        if ($this->hasHeadlines()) {
+            $headlineColumns = 'headline, headline_intro,';
+            $headlineParams  = ':headline, :headline_intro,';
+        }
+
+        if ($this->hasMemberDb()) {
+            $memberColumns = 'include_member_map, search_form, ';
+            $memberParams  = ':include_member_map, :search_form, ';
+        }
+
+        $pageSql = "
+            INSERT INTO pages_draft (
+                $headlineColumns $memberColumns keyword, meta_title,
+                meta_description, navigation_name, parent, paragraph_links,
+                short_url, template, published_page, include_members, include_coupons)
+            VALUES (
+                $headlineParams $memberParams :keyword, :meta_title,
+                :meta_description, :navigation_name, :parent,
+                :paragraph_links, :short_url, :template, :published_page, :include_members, :include_coupons)";
+
+        $paragraphSql = "
+            INSERT INTO paragraphs_draft (
+                active, title, description, image, caption, page)
+            VALUES (
+                true, :title, :description, :image, :caption, :page)";
+
+        try {
+            $this->dbh->beginTransaction();
+
+            $pageStmt = $this->dbh->prepare($pageSql);
+            $this->setPageVars($pageStmt, $data);
+            $pageStmt->bindParam(':published_page', $data['published_page']);
+            $pageStmt->execute();
+
+            $row = $this->dbh
+                ->query('select id from pages_draft order by id desc limit 1')
+                ->fetch(PDO::FETCH_ASSOC);
+
+            if (defined('MEMBERS_DB') && MEMBERS_DB) {
+                $this->_updateMemberCategories(
+                    $data['member_categories'],
                     $row['id']
                 );
-                       }
-
-                       $paragraphStmt = $this->dbh->prepare($paragraphSql);
-                       $this->setParagraphVars($paragraphStmt, $data);
-                       $paragraphStmt->bindParam(':page', $row['id']);
-                       $paragraphStmt->execute();
-
-                       $this->dbh->commit();
-
-                       return $row['id'];
-               } catch (PDOException $e) {
-                       $this->dbh->rollback();
-                       Toolkit_Logger::logException('DB Error', $e);
-                       $content = serialize($data);
-                       throw new Toolkit_Toolbox_Exception(
-                               "Unable to insert page draft [$content]"
-                       );
-               }
-       }
-
-       //      }}}
-
-       //      {{{     update()
-
-       public function update(array $data, $id)
-       {
-               if ($this->hasHeadlines()) {
-                       $headlineColumns = '
-                               headline = :headline,
-                               headline_intro = :headline_intro, ';
-               }
-
-               if ($this->hasMemberDb()) {
-                       $memberColumns = '
-                               include_member_map = :include_member_map,
-                               search_form = :search_form, ';
-               }
-
-               $pageSql = "
+            }
+
+            if (defined('COUPONS') && COUPONS) {
+                $this->_updateCouponCategories(
+                    $data['coupon_categories'],
+                    $row['id']
+                );
+                if (defined('MEMBERS_DB') && MEMBERS_DB) {
+                    $this->_updateMemberCities(
+                        $data['member_regions'],
+                        $row['id']
+                    );
+                }
+            }
+
+            $paragraphStmt = $this->dbh->prepare($paragraphSql);
+            $this->setParagraphVars($paragraphStmt, $data);
+            $paragraphStmt->bindParam(':page', $row['id']);
+            $paragraphStmt->execute();
+
+            $this->dbh->commit();
+
+            return $row['id'];
+        } catch (PDOException $e) {
+            $this->dbh->rollback();
+            Toolkit_Logger::logException('DB Error', $e);
+            $content = serialize($data);
+            throw new Toolkit_Toolbox_Exception(
+                "Unable to insert page draft [$content]"
+            );
+        }
+    }
+
+    //  }}}
+
+    //  {{{ update()
+
+    public function update(array $data, $id)
+    {
+        if ($this->hasHeadlines()) {
+            $headlineColumns = '
+                headline = :headline,
+                headline_intro = :headline_intro, ';
+        }
+
+        if ($this->hasMemberDb()) {
+            $memberColumns = '
+                include_member_map = :include_member_map,
+                search_form = :search_form, ';
+        }
+
+        $pageSql = "
             UPDATE pages_draft
-                          SET $headlineColumns
-                              $memberColumns
-                                  keyword = :keyword,
-                              meta_title = :meta_title,
-                              meta_description = :meta_description,
-                              navigation_name = :navigation_name,
-                              parent = :parent,
-                              paragraph_links = :paragraph_links,
-                              short_url = :short_url,
-                              template = :template,
+               SET $headlineColumns
+                   $memberColumns
+                   keyword = :keyword,
+                   meta_title = :meta_title,
+                   meta_description = :meta_description,
+                   navigation_name = :navigation_name,
+                   parent = :parent,
+                   paragraph_links = :paragraph_links,
+                   short_url = :short_url,
+                   template = :template,
                    include_members = :include_members,
                    include_coupons = :include_coupons
              WHERE id = :id";
 
-               $paragraphSql = "
-                       UPDATE paragraphs_draft
-                          SET title = :title,
-                                  description = :description,
-                                  image = :image,
-                                  caption = :caption
-                        WHERE page = :page
-                          AND pos = 1";
-
-               try {
-                       $this->dbh->beginTransaction();
-
-                       $pageStmt = $this->dbh->prepare($pageSql);
-                       $this->setPageVars($pageStmt, $data);
-                       $pageStmt->bindParam(':id', $id, PDO::PARAM_INT);
-                       $pageStmt->execute();
-
-                       if (defined('MEMBERS_DB') && MEMBERS_DB) {
-                               $this->_updateMemberCategories($data['member_categories'], $id);
-                               $this->_updateMemberCities($data['member_regions'], $id);
-                       }
-                       if (defined('COUPONS') && COUPONS) {
-                               $this->_updateCouponCategories($data['coupon_categories'], $id);
-                       }
-
-                       $paragraphStmt = $this->dbh->prepare($paragraphSql);
-                       $this->setParagraphVars($paragraphStmt, $data);
-                       $paragraphStmt->bindParam(':page', $id);
-                       $paragraphStmt->execute();
-
-                       return $this->dbh->commit();
-               } catch (PDOException $e) {
-                       $this->dbh->rollback();
-                       Toolkit_Logger::logException('DB Error', $e);
-                       $content = serialize($data);
-                       throw new Toolkit_Toolbox_Exception(
-                               "Unable to update page draft [$content]"
-                       );
-               }
-       }
-
-       //      }}}
-
-       //      {{{     _updateMemberCategories()
-
-       private function _updateMemberCategories(array $data = null, $id)
-       {
-               $deleteCatsSql = "
+        $paragraphSql = "
+            UPDATE paragraphs_draft
+               SET title = :title,
+                   description = :description,
+                   image = :image,
+                   caption = :caption
+             WHERE page = :page
+               AND pos = 1";
+
+        try {
+            $this->dbh->beginTransaction();
+
+            $pageStmt = $this->dbh->prepare($pageSql);
+            $this->setPageVars($pageStmt, $data);
+            $pageStmt->bindParam(':id', $id, PDO::PARAM_INT);
+            $pageStmt->execute();
+
+            if (defined('MEMBERS_DB') && MEMBERS_DB) {
+                $this->_updateMemberCategories($data['member_categories'], $id);
+                $this->_updateMemberCities($data['member_regions'], $id);
+            }
+            if (defined('COUPONS') && COUPONS) {
+                $this->_updateCouponCategories($data['coupon_categories'], $id);
+            }
+
+            $paragraphStmt = $this->dbh->prepare($paragraphSql);
+            $this->setParagraphVars($paragraphStmt, $data);
+            $paragraphStmt->bindParam(':page', $id);
+            $paragraphStmt->execute();
+
+            return $this->dbh->commit();
+        } catch (PDOException $e) {
+            $this->dbh->rollback();
+            Toolkit_Logger::logException('DB Error', $e);
+            $content = serialize($data);
+            throw new Toolkit_Toolbox_Exception(
+                "Unable to update page draft [$content]"
+            );
+        }
+    }
+
+    //  }}}
+
+    //  {{{ _updateMemberCategories()
+
+    private function _updateMemberCategories(array $data = null, $id)
+    {
+        $deleteCatsSql = "
             DELETE FROM member_categories2toolbox_pages_draft
              WHERE page = :id";
-               $delStmt = $this->dbh->prepare($deleteCatsSql);
-               $delStmt->bindParam(':id', $id, PDO::PARAM_INT);
-               $delStmt->execute();
-
-               if (is_array($data)) {
-                       $insertCatsSql = "
-                               INSERT INTO member_categories2toolbox_pages_draft (page, category)
-                               VALUES (:page, :category)";
-                       $insStmt = $this->dbh->prepare($insertCatsSql);
-                       $insStmt->bindParam(':page', $id, PDO::PARAM_INT);
-                       foreach ($data as $category) {
-                               $insStmt->bindParam(':category', $category, PDO::PARAM_INT);
-                               $insStmt->execute();
-                       }
-               }
-       }
-
-       //      }}}
-       //      {{{     getMemberCategoriesForPage()
-
-       protected function getMemberCategoriesForPage($id)
-       {
-               try {
-                       $sql = "
+        $delStmt = $this->dbh->prepare($deleteCatsSql);
+        $delStmt->bindParam(':id', $id, PDO::PARAM_INT);
+        $delStmt->execute();
+
+        if (is_array($data)) {
+            $insertCatsSql = "
+                INSERT INTO member_categories2toolbox_pages_draft (page, category)
+                VALUES (:page, :category)";
+            $insStmt = $this->dbh->prepare($insertCatsSql);
+            $insStmt->bindParam(':page', $id, PDO::PARAM_INT);
+            foreach ($data as $category) {
+                $insStmt->bindParam(':category', $category, PDO::PARAM_INT);
+                $insStmt->execute();
+            }
+        }
+    }
+
+    //  }}}
+    //  {{{ getMemberCategoriesForPage()
+
+    protected function getMemberCategoriesForPage($id)
+    {
+        try {
+            $sql = "
                 SELECT *
                   FROM member_categories2toolbox_pages_draft
                  WHERE page = :id";
 
-                       $stmt = $this->dbh->prepare($sql);
-                       $stmt->bindParam(':id', $id);
-                       $stmt->execute();
+            $stmt = $this->dbh->prepare($sql);
+            $stmt->bindParam(':id', $id);
+            $stmt->execute();
 
-                       $categories = array();
-                       while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
-                               $categories[] = $row['category'];
-                       }
+            $categories = array();
+            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+                $categories[] = $row['category'];
+            }
 
-                       return $categories;
-               } catch (PDOException $e) {
-                       Toolkit_Logger::logException('DB Error', $e);
-                       throw new Toolkit_Toolbox_Exception(
-                               "Unable to fetch member categories for page draft `$id`"
-                       );
-               }
-       }
+            return $categories;
+        } catch (PDOException $e) {
+            Toolkit_Logger::logException('DB Error', $e);
+            throw new Toolkit_Toolbox_Exception(
+                "Unable to fetch member categories for page draft `$id`"
+            );
+        }
+    }
 
-       //      }}}
+    //  }}}
 
-       //      {{{     _updateMemberCities()
+    //  {{{ _updateMemberCities()
 
-       private function _updateMemberCities(array $data = null, $id)
-       {
-               $deleteCitiesSql = "
+    private function _updateMemberCities(array $data = null, $id)
+    {
+        $deleteCitiesSql = "
             DELETE FROM member_regions2toolbox_pages_draft
              WHERE page = :id";
-               $delStmt = $this->dbh->prepare($deleteCitiesSql);
-               $delStmt->bindParam(':id', $id, PDO::PARAM_INT);
-               $delStmt->execute();
-
-               if (is_array($data)) {
-                       $insertCitiesSql = "
-                               INSERT INTO member_regions2toolbox_pages_draft (page, region)
-                               VALUES (:page, :region)";
-                       $insStmt = $this->dbh->prepare($insertCitiesSql);
-                       $insStmt->bindParam(':page', $id, PDO::PARAM_INT);
-                       foreach ($data as $region) {
-                               $insStmt->bindParam(':region', $region, PDO::PARAM_INT);
-                               $insStmt->execute();
-                       }
-               }
-       }
-
-       //      }}}
-    // //      {{{     getMemberRegionsForPage()
-
-       protected function getMemberRegionsForPage($id)
-       {
-               try {
-                       $sql = "
+        $delStmt = $this->dbh->prepare($deleteCitiesSql);
+        $delStmt->bindParam(':id', $id, PDO::PARAM_INT);
+        $delStmt->execute();
+
+        if (is_array($data)) {
+            $insertCitiesSql = "
+                INSERT INTO member_regions2toolbox_pages_draft (page, region)
+                VALUES (:page, :region)";
+            $insStmt = $this->dbh->prepare($insertCitiesSql);
+            $insStmt->bindParam(':page', $id, PDO::PARAM_INT);
+            foreach ($data as $region) {
+                $insStmt->bindParam(':region', $region, PDO::PARAM_INT);
+                $insStmt->execute();
+            }
+        }
+    }
+
+    //  }}}
+    //  //  {{{ getMemberRegionsForPage()
+
+    protected function getMemberRegionsForPage($id)
+    {
+        try {
+            $sql = "
                 SELECT *
                   FROM member_regions2toolbox_pages_draft
                  WHERE page = :id";
 
-                       $stmt = $this->dbh->prepare($sql);
-                       $stmt->bindParam(':id', $id);
-                       $stmt->execute();
-
-                       $regions = array();
-                       while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
-                               $regions[] = $row['region'];
-                       }
-
-                       return $regions;
-               } catch (PDOException $e) {
-                       Toolkit_Logger::logException('DB Error', $e);
-                       throw new Toolkit_Toolbox_Exception(
-                               "Unable to fetch member regions for page `$id`"
-                       );
-               }
-       }
-
-       //      }}}
-       //      {{{     getMemberCitiesForPage()
-
-       protected function getMemberCitiesForPage($id)
-       {
-               try {
-                       $sql = "
+            $stmt = $this->dbh->prepare($sql);
+            $stmt->bindParam(':id', $id);
+            $stmt->execute();
+
+            $regions = array();
+            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+                $regions[] = $row['region'];
+            }
+
+            return $regions;
+        } catch (PDOException $e) {
+            Toolkit_Logger::logException('DB Error', $e);
+            throw new Toolkit_Toolbox_Exception(
+                "Unable to fetch member regions for page `$id`"
+            );
+        }
+    }
+
+    //  }}}
+    //  {{{ getMemberCitiesForPage()
+
+    protected function getMemberCitiesForPage($id)
+    {
+        try {
+            $sql = "
                 SELECT *
                   FROM member_regions2toolbox_pages_draft
                  WHERE page = :id";
 
-                       $stmt = $this->dbh->prepare($sql);
-                       $stmt->bindParam(':id', $id);
-                       $stmt->execute();
+            $stmt = $this->dbh->prepare($sql);
+            $stmt->bindParam(':id', $id);
+            $stmt->execute();
 
-                       $regions = array();
-                       while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
-                               $regions[] = $row['region'];
-                       }
+            $regions = array();
+            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+                $regions[] = $row['region'];
+            }
 
-                       return $regions;
-               } catch (PDOException $e) {
-                       Toolkit_Logger::logException('DB Error', $e);
-                       throw new Toolkit_Toolbox_Exception(
-                               "Unable to fetch member regions for page `$id`"
-                       );
-               }
-       }
+            return $regions;
+        } catch (PDOException $e) {
+            Toolkit_Logger::logException('DB Error', $e);
+            throw new Toolkit_Toolbox_Exception(
+                "Unable to fetch member regions for page `$id`"
+            );
+        }
+    }
 
-       //      }}}
+    //  }}}
 
-       //      {{{     _updateCouponCategories()
+    //  {{{ _updateCouponCategories()
 
-       private function _updateCouponCategories(array $data = null, $id)
-       {
-               $deleteCatsSql = "
+    private function _updateCouponCategories(array $data = null, $id)
+    {
+        $deleteCatsSql = "
             DELETE FROM coupon_categories2toolbox_pages_draft
              WHERE page = :id";
-               $delStmt = $this->dbh->prepare($deleteCatsSql);
-               $delStmt->bindParam(':id', $id, PDO::PARAM_INT);
-               $delStmt->execute();
-
-               if (is_array($data)) {
-                       $insertCatsSql = "
-                               INSERT INTO coupon_categories2toolbox_pages_draft (page, category)
-                               VALUES (:page, :category)";
-                       $insStmt = $this->dbh->prepare($insertCatsSql);
-                       $insStmt->bindParam(':page', $id, PDO::PARAM_INT);
-                       foreach ($data as $category) {
-                               $insStmt->bindParam(':category', $category, PDO::PARAM_INT);
-                               $insStmt->execute();
-                       }
-               }
-       }
-
-       //      }}}
-       //      {{{     getCouponCategoriesForPage()
-
-       protected function getCouponCategoriesForPage($id)
-       {
-               try {
-                       $sql = "
+        $delStmt = $this->dbh->prepare($deleteCatsSql);
+        $delStmt->bindParam(':id', $id, PDO::PARAM_INT);
+        $delStmt->execute();
+
+        if (is_array($data)) {
+            $insertCatsSql = "
+                INSERT INTO coupon_categories2toolbox_pages_draft (page, category)
+                VALUES (:page, :category)";
+            $insStmt = $this->dbh->prepare($insertCatsSql);
+            $insStmt->bindParam(':page', $id, PDO::PARAM_INT);
+            foreach ($data as $category) {
+                $insStmt->bindParam(':category', $category, PDO::PARAM_INT);
+                $insStmt->execute();
+            }
+        }
+    }
+
+    //  }}}
+    //  {{{ getCouponCategoriesForPage()
+
+    protected function getCouponCategoriesForPage($id)
+    {
+        try {
+            $sql = "
                 SELECT *
                   FROM coupon_categories2toolbox_pages_draft
                  WHERE page = :id";
 
-                       $stmt = $this->dbh->prepare($sql);
-                       $stmt->bindParam(':id', $id);
-                       $stmt->execute();
+            $stmt = $this->dbh->prepare($sql);
+            $stmt->bindParam(':id', $id);
+            $stmt->execute();
 
-                       $categories = array();
-                       while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
-                               $categories[] = $row['category'];
-                       }
+            $categories = array();
+            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+                $categories[] = $row['category'];
+            }
 
-                       return $categories;
-               } catch (PDOException $e) {
-                       Toolkit_Logger::logException('DB Error', $e);
-                       throw new Toolkit_Toolbox_Exception(
-                               "Unable to fetch coupon categories for page draft `$id`"
-                       );
-               }
-       }
+            return $categories;
+        } catch (PDOException $e) {
+            Toolkit_Logger::logException('DB Error', $e);
+            throw new Toolkit_Toolbox_Exception(
+                "Unable to fetch coupon categories for page draft `$id`"
+            );
+        }
+    }
 
-       //      }}}
+    //  }}}
 
-       //      {{{     getPhotoGalleriesForPage()
+    //  {{{ getPhotoGalleriesForPage()
 
-       protected function getPhotoGalleriesForPage($id)
-       {
-               try {
-                       $sql = "
+    protected function getPhotoGalleriesForPage($id)
+    {
+        try {
+            $sql = "
                 SELECT pc.*
                   FROM photo_category pc
                   JOIN photo_category_bus pcb
@@ -530,24 +532,24 @@ class Toolkit_Toolbox_PageGatewayDraft
                     ON (pd.published_page = pcb.buscat_id)
                  WHERE pcb.buscat_id      = :id";
 
-                       $stmt = $this->dbh->prepare($sql);
-                       $stmt->bindParam(':id', $id);
-                       $stmt->execute();
-
-                       $photoGalleries = array();
-                       while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
-                               $photoGalleries[$row['id']] = $row['category'];
-                       }
-
-                       return $photoGalleries;
-               } catch (PDOException $e) {
-                       Toolkit_Logger::logException('DB Error', $e);
-                       throw new Toolkit_Toolbox_Exception(
-                               "Unable to fetch member categories for page `$id`"
-                       );
-               }
-       }
-
-       //      }}}
+            $stmt = $this->dbh->prepare($sql);
+            $stmt->bindParam(':id', $id);
+            $stmt->execute();
+
+            $photoGalleries = array();
+            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+                $photoGalleries[$row['id']] = $row['category'];
+            }
+
+            return $photoGalleries;
+        } catch (PDOException $e) {
+            Toolkit_Logger::logException('DB Error', $e);
+            throw new Toolkit_Toolbox_Exception(
+                "Unable to fetch member categories for page `$id`"
+            );
+        }
+    }
+
+    //  }}}
 }
 ?>