Adding code for putting together the pages
authorSteve Sutton <ssutton@gmail.com>
Fri, 10 Jul 2015 18:35:26 +0000 (14:35 -0400)
committerSteve Sutton <ssutton@gmail.com>
Fri, 10 Jul 2015 18:35:26 +0000 (14:35 -0400)
NOTES.md
controllers/Import.php

index 4f0e03c..bd35942 100644 (file)
--- a/NOTES.md
+++ b/NOTES.md
@@ -48,3 +48,6 @@ $post = array(
   'page_template'  => [ <string> ] // Requires name of template file, eg template.php. Default empty.
 );
 ```
+
+##Settings
+Will also need to add the site url to the setting and this will need to be required. I need to build the urls for the images.
index 5aa61e4..c17725d 100644 (file)
      class Toolbox_Import extends WP_Importer
      {
          private $_dbh;
+         private $_post;
          function __construct()
          {
          }
 
         function connect()
         {
-             // read optios for the import and if they aren't set then give a warning.
+            if ($this->_dbh) {
+                return;
+            }
+             // read options for the import and if they aren't set then give a warning.
              $options = get_option(GLM_WP_IMPORT_SETTINGS);
              // try making a postgres connection to the database
              $connString  = 'dbname=' . $options['db_name'];
              echo '<a href="admin.php?import=toolbox&amp;step=1">Start the Import Now</a>';
          }
 
+        function displayImage($data, $alignment)
+        {
+            if ($data['caption']) {
+                $content .= '[caption id="attachment_'.$data['id'].'" align="align'.$alignment.'"]'
+                    .'<img class="align'.$alignment.' size-medium wp-image-'.$data['id'].'" '
+                    . ' src="' . TOOLBOX_IMAGE_URL . $data['image'].'"> '
+                    . $data['caption'] . '[/caption]';
+            } else {
+                $content .= '<img class="align'.$alignment.' size-medium wp-image-'.$data['id'].'" '
+                    . ' src="' . TOOLBOX_IMAGE_URL . $data['image'].'">';
+            }
+            return $content;
+        }
+
          function fetchAllPages()
          {
+             $this->connect();
+            $pageSql = "
+              SELECT *
+                FROM toolbox.pages
+            ORDER BY parent,pos";
+            $pageData = $this->_dbh->query($pageSql)->fetchAll(PDO::FETCH_ASSOC);
+            $paragraphSql = "
+              SELECT *
+                FROM toolbox.paragraphs
+               WHERE page = :page
+            ORDER BY pos";
+            $paraStmt = $this->_dbh->prepare($paragraphSql);
+             $data = $this->_dbh->query($pageSql)->fetchAll();
+            foreach ($data as &$page) {
+                $paraStmt->bindParam(':page', $page['id'], PDO::PARAM_INT);
+                $paraStmt->execute();
+                $paragraphs     = $paraStmt->fetchAll(PDO::FETCH_ASSOC);
+                $primaryAlign   = 'right';
+                $secondaryAlign = 'right';
+                $alternateImg   = false;
+
+                switch ($page['template']) {
+                case 1:
+                    break;
+                case 2:
+                    $primaryAlign   = 'left';
+                    $secondaryAlign = 'left';
+                    break;
+                case 3:
+                    $secondaryAlign = 'left';
+                    $alternateImg   = true;
+                    break;
+                case 4:
+                    $primaryAlign   = 'left';
+                    $alternateImg   = true;
+                    break;
+                case 5:
+                    $primaryAlign   = 'left';
+                    break;
+                case 6:
+                    $secondaryAlign = 'left';
+                    break;
+                }
+                $iterator = 1;
+            $page['pageContent'] = '';
+            foreach ($paragraphs as $paragraph) {
+                switch ($iterator) {
+                case 1:
+                    if ($paragraph['title']) {
+                        $page['pageContent'] .= '<h1>'.$paragraph['title'].'</h1>';
+                    }
+                    if ($paragraph['image']) {
+                        $page['pageContent'] .= $this->displayImage($paragraph, $primaryAlign);
+                    }
+                    break;
+                case 2:
+                    if ($paragraph['title']) {
+                        $page['pageContent'] .= '<h2>'.$paragraph['title'].'</h2>';
+                    }
+                    if ($paragraph['image']) {
+                        $page['pageContent'] .= $this->displayImage($paragraph, $secondaryAlign);
+                    }
+                    break;
+                default:
+                    if ($paragraph['title']) {
+                        $page['pageContent'] .= '<h2>'.$paragraph['title'].'</h2>';
+                    }
+                    if ($alternateImg && $page['template'] == 3) {
+                        $align = ($iterator%2 == 0) ? 'left' : 'right';
+                    } else {
+                        $align = $secondaryAlign;
+                    }
+                    if ($paragraph['image']) {
+                        $page['pageContent'] .= $this->displayImage($paragraph, $align);
+                    }
+                    break;
+                }
+                $page['pageContent'] .= $paragraph['description'];
+                ++$iterator;
+                }
+            }
+            return $data;
          }
 
          function import()
          {
-
+            echo '<p>Fetching Pages</p>';
+            // grab all pages and build the post array
+            $pages = $this->fetchAllPages();
+            echo '<pre>'.print_r($pages, true).'</pre>';
          }
 
          function dispatch()