WIP for pdf event output
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 31 Mar 2016 20:17:50 +0000 (16:17 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 31 Mar 2016 20:17:50 +0000 (16:17 -0400)
classes/data/dataEvents.php
classes/data/dataRecurrences.php
classes/data/dataTimes.php
models/front/events/list.php

index be46841..59290fc 100644 (file)
@@ -87,6 +87,7 @@ class GlmDataEvents extends GlmDataAbstract
      */
     public $postAddTimes = false;
     public $postAddLocations = false;
+    public $postAddRecurrences = false;
     public $dateRange = "start_time >= now()";
 
     /**
@@ -439,7 +440,19 @@ class GlmDataEvents extends GlmDataAbstract
                 $r['locations'] = $locations[key($locations)];
             }
         }
+        if ($this->postAddRecurrences) {
+            $r['recurrences'] = array();
+            include_once  GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataRecurrences.php';
+            $recurrenceData = new GlmDataEventsRecurrences( $this->wpdb, $this->config );
+            $where = "T.event = {$r['id']}";
+            $recurrences = $recurrenceData->getList( $where );
+            if ( !empty( $recurrences ) ) {
+                foreach ( $recurrences as $recurrence ) {
+                    $r['recurrences'][] = $recurrence;
+                }
+            } 
 
+        }
 
         return $r;
     }
index 49ceb02..0ecf4d7 100644 (file)
@@ -276,7 +276,7 @@ class GlmDataEventsRecurrences extends GlmDataAbstract
 
     }
 
-    /*
+    /**
      * Entry Post Processing Call-Back Method
      *
      * Perform post-processing for all result entries.
@@ -295,7 +295,7 @@ class GlmDataEventsRecurrences extends GlmDataAbstract
         return $r;
     }
 
-    /*
+    /**
      * Calculate and create all entries for the times table from recurrence data.
      *
      * @param integer $recurID ID of the event recurrence record
@@ -342,7 +342,7 @@ class GlmDataEventsRecurrences extends GlmDataAbstract
         }
     }
 
-    /*
+    /**
      * Calculate and create all entries for the times table from recurrence data.
      *
      * @param array $recurID ID of recurrence entry
index 4748ff5..56546f3 100644 (file)
@@ -213,7 +213,7 @@ class GlmDataEventsTimes extends GlmDataAbstract
 
     }
 
-    /*
+    /**
      * Entry Post Processing Call-Back Method
      *
      * Perform post-processing for all result entries.
index e4cf5aa..de98fdd 100644 (file)
@@ -23,11 +23,17 @@ require_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/models/front/events/baseAction.p
 class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
 {
     const PDF_TOP_Y      = 750;
-    const PDF_BOTTOM_Y   = 60;
-    const LINE_HEIGHT    = 12;
+    const PDF_BOTTOM_Y   = 80;
+    const LINE_HEIGHT    = 10;
+    const PDF_WIDTH      = 570;
+    const PDF_FONT_SIZE  = 8;
     const PDF_LOGO_SCALE = 4;
     const PDF_LOGO_X     = 20;
     const PDF_LOGO_Y     = 760;
+    const PDF_LFT_COL_X  = 20;
+    const PDF_RGT_COL_X  = 200;
+
+    private $pages = array();
     /**
      * modelAction
      *
@@ -57,17 +63,32 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
         if (isset($_REQUEST['glm-event-pdf']) && $pdf = filter_var($_REQUEST['glm-event-pdf'], FILTER_VALIDATE_BOOLEAN)) {
             $search = true;
             $action = 'pdf';
-            //include '/var/www/localhost/htdocs/pdfTest/index.php';
-            //echo '<pre>$_REQUEST: ' . print_r($_REQUEST, true) . '</pre>';
-            //exit;
         }
         if ( isset($_REQUEST['glm_event_from']) ) {
-            $fromDate = filter_var($_REQUEST['glm_event_from'], FILTER_SANITIZE_STRING);
+            //$fromDate = filter_var($_REQUEST['glm_event_from'], FILTER_SANITIZE_STRING);
+            $fromDate = filter_var(
+                $_REQUEST['glm_event_from'],
+                FILTER_VALIDATE_REGEXP,
+                array(
+                    'options' => array(
+                        'regexp' => '%[0-9]{2}/[0-9]{2}/[0-9]{4}%'
+                    )
+                )
+            );
         } else {
             $fromDate = date('m/d/Y');
         }
         if ( isset($_REQUEST['glm_event_to']) ) {
-            $toDate   = filter_var($_REQUEST['glm_event_to'], FILTER_SANITIZE_STRING);
+            //$toDate   = filter_var($_REQUEST['glm_event_to'], FILTER_SANITIZE_STRING);
+            $toDate = filter_var(
+                $_REQUEST['glm_event_to'],
+                FILTER_VALIDATE_REGEXP,
+                array(
+                    'options' => array(
+                        'regexp' => '%[0-9]{2}/[0-9]{2}/[0-9]{4}%'
+                    )
+                )
+            );
         } else {
             if ( isset($_REQUEST['t']) && $t = filter_var( $_REQUEST['t'], FILTER_SANITIZE_STRING ) ) {
                 switch ( $t ) {
@@ -92,6 +113,11 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
             $from = date('Y-m-d', strtotime($fromDate));
             $to   = date('Y-m-d', strtotime($toDate));
             $this->dateRange = "start_time BETWEEN CAST('{$from}' AS DATE) AND CAST('{$to}' as DATE)";
+            $this->dateRange = "id IN (
+                SELECT id
+                  FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times
+                 WHERE DATE(start_time) BETWEEN '{$from}' AND '{$to}'
+            )";
         }
         //echo '<pre>$this->dateRange: ' . print_r($this->dateRange, true) . '</pre>';
 
@@ -120,7 +146,11 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
             break;
         case 'pdf':
             include_once '/var/www/localhost/Setasign/SetaPDF-Core_2.18.0.817_Ioncubed-PHP5.4/library/SetaPDF/Autoload.php';
+            $this->postAddLocations   = true;
+            $this->postAddRecurrences = true;
             $events = $this->getModelEventsData($categoryId);
+            $this->postAddLocations   = false;
+            $this->postAddRecurrences = false;
             //echo '<pre>$events: ' . print_r($events, true) . '</pre>';
             //exit;
             try {
@@ -136,6 +166,8 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
 
                 $pages = $document->getCatalog()->getPages();
                 $page  = $pages->create(SetaPDF_Core_PageFormats::A4);
+                // store the page into $this->pages so we can add footers later
+                $this->pages[] = $page;
 
                 // add logo to top of the page
                 $xObject->draw(
@@ -150,51 +182,104 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
                 $index = 0;
 
                 foreach ( $events as $eventId => $event ) {
+                    $eventTopY = $pdfY;
                     // dates
-                    $dates = new SetaPDF_Core_Text_Block( $boldFont, 8 );
+                    $dates = new SetaPDF_Core_Text_Block( $boldFont, self::PDF_FONT_SIZE );
                     $dates->setText($event['dates']);
                     $lineCount = $dates->getLineCount();
                     //echo '<pre>dates $lineCount: ' . print_r($lineCount, true) . '</pre>';
-                    $dates->draw($page->getCanvas(), 20, $pdfY);
+                    $dates->draw($page->getCanvas(), self::PDF_LFT_COL_X, $pdfY);
 
                     $pdfY -= self::LINE_HEIGHT * $lineCount;
                     //echo '<pre>dates $pdfY: ' . print_r($pdfY, true) . '</pre>';
 
                     // title
-                    $title = new SetaPDF_Core_Text_Block( $boldFont, 8 );
+                    $title = new SetaPDF_Core_Text_Block( $boldFont, self::PDF_FONT_SIZE );
                     $title->setText($event['name']);
                     $lineCount = $title->getLineCount();
                     //echo '<pre>title $lineCount: ' . print_r($lineCount, true) . '</pre>';
-                    $title->draw($page->getCanvas(), 20, $pdfY);
+                    $title->draw($page->getCanvas(), self::PDF_LFT_COL_X, $pdfY);
 
-                    $pdfY -= self::LINE_HEIGHT * $lineCount  + 10;
+                    $pdfY -= self::LINE_HEIGHT * $lineCount;
                     //echo '<pre>title $pdfY: ' . print_r($pdfY, true) . '</pre>';
 
                     if ( isset($event['categories']) && !empty($event['categories']) ) {
+                        $categoryNames = array();
+                        $category = new SetaPDF_Core_Text_Block( $boldFont, self::PDF_FONT_SIZE );
+                        $category->setText('Categories:');
+                        $category->draw($page->getCanvas(), self::PDF_RGT_COL_X, $eventTopY );
                         foreach ( $event['categories'] as $category ) {
-                            // output the categories
+                            $categoryNames[] = $category['name'];
+                        }
+                        // output the categories
+                        $category = new SetaPDF_Core_Text_Block( $font, self::PDF_FONT_SIZE );
+                        $category->setText( implode( ',', $categoryNames ) );
+                        $category->draw($page->getCanvas(), self::PDF_RGT_COL_X + 50, $eventTopY );
+                    }
+
+                    if ( isset($event['locations']) && !empty($event['locations']) ) {
+                        $address = array();
+                        $address[] = $event['locations']['name'];
+                        $address[] = $event['locations']['address'];
+                        $address[] = $event['locations']['city']['name'];
+                        $address[] = $event['locations']['state']['name'];
+                        $address[] = $event['locations']['zip'];
+                        $location = new SetaPDF_Core_Text_Block( $font, self::PDF_FONT_SIZE );
+
+                        $location->setText(implode(', ', $address));
+                        $location->draw($page->getCanvas(), self::PDF_LFT_COL_X, $pdfY);
+                        $pdfY -= self::LINE_HEIGHT * $lineCount;
+                        
+                        // check for phone, url or email to output
+                        $contactInfo = array();
+                        if ( $event['locations']['phone'] ) {
+                            $contactInfo[] = $event['locations']['phone'];
                         }
+                        if ( $event['locations']['email'] ) {
+                            $contactInfo[] = $event['locations']['email'];
+                        }
+                        if ( $event['locations']['url'] ) {
+                            $contactInfo[] = $event['locations']['url'];
+                        }
+                        if ( !empty($contactInfo) ) {
+                            $contact = new SetaPDF_Core_Text_Block( $font, self::PDF_FONT_SIZE );
+                            $contact->setText( implode( ' - ', $contactInfo ) );
+                            $contact->draw( $page->getCanvas(), self::PDF_LFT_COL_X, $pdfY );
+                            $pdfY -= self::LINE_HEIGHT * $lineCount;
+                        }
+                    }
+
+                    if ( $event['url'] ) {
+                        $url = new SetaPDF_Core_Text_Block( $font, self::PDF_FONT_SIZE );
+                        $url->setText( $event['url'] );
+                        $url->draw( $page->getCanvas(), self::PDF_LFT_COL_X, $pdfY );
+                        $pdfY -= self::LINE_HEIGHT;
                     }
+                    $pdfY -= self::LINE_HEIGHT * 2;
+
 
                     if ( isset($event['intro']) && $event['intro'] ) {
                         // text
-                        $intro = new SetaPDF_Core_Text_Block( $font, 8 );
+                        $intro = new SetaPDF_Core_Text_Block( $font, self::PDF_FONT_SIZE );
                         $introText = html_entity_decode(
                             $this->cleanText( $event['intro'] ),
                             ENT_HTML5
                         );
                         $intro->setText($introText);
-                        $intro->setWidth(500);
+                        $intro->setWidth(self::PDF_WIDTH - 30);
                         $lineCount = $intro->getLineCount();
                         //echo '<pre>intro $lineCount: ' . print_r($lineCount, true) . '</pre>';
-                        $intro->draw($page->getCanvas(), 20, $pdfY);
+                        $intro->draw($page->getCanvas(), self::PDF_LFT_COL_X, $pdfY);
 
                         $pdfY -= self::LINE_HEIGHT * $lineCount;
+                        $page->getCanvas()->draw()->line(self::PDF_LFT_COL_X, $pdfY, self::PDF_WIDTH, $pdfY);
+                        $pdfY -= self::LINE_HEIGHT;
                         if ( $lineCount == 1 ) {
                              $pdfY -= self::LINE_HEIGHT;
                         }
                     //echo '<pre>intro $pdfY: ' . print_r($pdfY, true) . '</pre>';
                     }
+                    // line at the bottom of the event
                     ++$index;
 
                     //$pdfY -= self::LINE_HEIGHT;
@@ -203,6 +288,8 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
                     if ( $pdfY <= self::PDF_BOTTOM_Y && !( $totalEvents == $index ) ) {
                         $pdfY = self::PDF_TOP_Y;
                         $page = $pages->create(SetaPDF_Core_PageFormats::A4);
+                        // store the page into $this->pages so we can add footers later
+                        $this->pages[] = $page;
                         // add logo to top of the page
                         $xObject->draw(
                             $page->getCanvas(),
@@ -215,6 +302,18 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
                 }
 
 
+                // add footers to each page
+                $footer = new SetaPDF_Core_Text_Block( $font, self::PDF_FONT_SIZE );
+                $footerText  = "Discover Kalamazoo";
+                $footerText .= "\n141 E. Michigan Avenue, Suite 100 | Kalamazoo, Michigan 49007 | 800.888.0509 | DiscoverKalamazoo.com";
+                $footer->setText($footerText);
+                $footer->setAlign('center');
+                $footer->setWidth(self::PDF_WIDTH);
+
+                foreach ( $this->pages as $page ) {
+                    $page->getCanvas()->draw()->line(self::PDF_LFT_COL_X, self::PDF_BOTTOM_Y - 40, self::PDF_WIDTH, self::PDF_BOTTOM_Y - 40);
+                    $footer->draw($page->getCanvas(), self::PDF_LFT_COL_X, self::PDF_BOTTOM_Y - 60);
+                }
                 $document->save()->finish();
 
             } catch(SetaPDF_Exception $e) {