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
*
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 ) {
$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>';
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 {
$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(
$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;
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(),
}
+ // 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) {