From b4a61ade3519f13fa4ea517bbae8f815160d0cbb Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 31 Mar 2016 16:17:50 -0400 Subject: [PATCH] WIP for pdf event output --- classes/data/dataEvents.php | 13 +++ classes/data/dataRecurrences.php | 6 +- classes/data/dataTimes.php | 2 +- models/front/events/list.php | 131 +++++++++++++++++++++++++++---- 4 files changed, 132 insertions(+), 20 deletions(-) diff --git a/classes/data/dataEvents.php b/classes/data/dataEvents.php index be46841..59290fc 100644 --- a/classes/data/dataEvents.php +++ b/classes/data/dataEvents.php @@ -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; } diff --git a/classes/data/dataRecurrences.php b/classes/data/dataRecurrences.php index 49ceb02..0ecf4d7 100644 --- a/classes/data/dataRecurrences.php +++ b/classes/data/dataRecurrences.php @@ -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 diff --git a/classes/data/dataTimes.php b/classes/data/dataTimes.php index 4748ff5..56546f3 100644 --- a/classes/data/dataTimes.php +++ b/classes/data/dataTimes.php @@ -213,7 +213,7 @@ class GlmDataEventsTimes extends GlmDataAbstract } - /* + /** * Entry Post Processing Call-Back Method * * Perform post-processing for all result entries. diff --git a/models/front/events/list.php b/models/front/events/list.php index e4cf5aa..de98fdd 100644 --- a/models/front/events/list.php +++ b/models/front/events/list.php @@ -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 '
$_REQUEST: ' . print_r($_REQUEST, true) . '
'; - //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 '
$this->dateRange: ' . print_r($this->dateRange, true) . '
'; @@ -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 '
$events: ' . print_r($events, true) . '
'; //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 '
dates $lineCount: ' . print_r($lineCount, true) . '
'; - $dates->draw($page->getCanvas(), 20, $pdfY); + $dates->draw($page->getCanvas(), self::PDF_LFT_COL_X, $pdfY); $pdfY -= self::LINE_HEIGHT * $lineCount; //echo '
dates $pdfY: ' . print_r($pdfY, true) . '
'; // 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 '
title $lineCount: ' . print_r($lineCount, true) . '
'; - $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 '
title $pdfY: ' . print_r($pdfY, true) . '
'; 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 '
intro $lineCount: ' . print_r($lineCount, true) . '
'; - $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 '
intro $pdfY: ' . print_r($pdfY, true) . '
'; } + // 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) { -- 2.17.1