* @version 0.1
*/
-/*
+require_once GLM_MEMBERS_EVENTS_PLUGIN_PATH . '/models/front/events/list.php';
+/**
* Steve Note...
*
* You can get to this using the following URL.
// Load Members data abstract
// require_once(GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php');
-/*
+/**
* This class performs the work of handling images passed to it via
* an AJAX call that goes through the WorPress AJAX Handler.
*
*/
-class GlmMembersAdmin_ajax_pdfOutput // extends GlmDataImages
+class GlmMembersAdmin_ajax_pdfOutput extends GlmMembersFront_events_list
{
/**
*/
public $config;
- /*
- * Constructor
- *
- * This contructor sets up this model. At this time that only includes
- * storing away the WordPress data object.
- *
- * @return object Class object
- *
- */
- public function __construct ($wpdb, $config)
- {
-
- // Save WordPress Database object
- $this->wpdb = $wpdb;
-
- // Save plugin configuration object
- $this->config = $config;
-
- // Run constructor for members data class
-// parent::__construct(false, false);
-
- }
-
- /*
- * Perform Model Action
- *
- * This modelAction takes an AJAX image upload and stores the image in the
- * media/images directory of the plugin.
- *
- * This model action does not return, it simply does it's work then calls die();
- *
- * @param $actionData
- *
- * Echos JSON string as response and does not return
- */
- public function modelAction ($actionData = false)
- {
- echo "Parmeter Stuff in my Events pdfOutput model = ".$_REQUEST['mystuff']."<br>";
- die();
- }
-
-
}
*/
class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction
{
+ const PDF_TOP_Y = 750;
+ const PDF_BOTTOM_Y = 60;
+ const LINE_HEIGHT = 12;
/**
* 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';
+ //include '/var/www/localhost/htdocs/pdfTest/index.php';
//echo '<pre>$_REQUEST: ' . print_r($_REQUEST, true) . '</pre>';
- exit;
+ //exit;
}
if ( isset($_REQUEST['glm_event_from']) ) {
$fromDate = filter_var($_REQUEST['glm_event_from'], FILTER_SANITIZE_STRING);
$view = 'agenda.html';
break;
case 'pdf':
- include '/var/www/localhost/htdocs/pdfTest/index.php';
+ include_once '/var/www/localhost/Setasign/SetaPDF-Core_2.18.0.817_Ioncubed-PHP5.4/library/SetaPDF/Autoload.php';
$events = $this->getModelEventsData($categoryId);
- echo '<pre>$events: ' . print_r($events, true) . '</pre>';
+ //echo '<pre>$events: ' . print_r($events, true) . '</pre>';
+ //exit;
+ try {
+ $pdfY = self::PDF_TOP_Y;
+ $writer = new SetaPDF_Core_Writer_Http('events.pdf', true);
+ $document = new SetaPDF_Core_Document($writer);
+ // logo for PDF
+ $img = SetaPDF_Core_Image::getByPath('../assets/logoPdf.png');
+ $xObject = $img->toXObject($document);
+
+ $font = SetaPDF_Core_Font_Standard_Helvetica::create($document);
+ $boldFont = SetaPDF_Core_Font_Standard_HelveticaBold::create($document);
+
+ $pages = $document->getCatalog()->getPages();
+ $page = $pages->create(SetaPDF_Core_PageFormats::A4);
+
+ // add logo to top of the page
+ $xObject->draw($page->getCanvas(), 20, 770, 500, 60);
+
+ $totalEvents = count($events);
+ $index = 0;
+
+ foreach ( $events as $eventId => $event ) {
+ // dates
+ $dates = new SetaPDF_Core_Text_Block( $boldFont, 8 );
+ $dates->setText($event['dates']);
+ $lineCount = $dates->getLineCount();
+ //echo '<pre>dates $lineCount: ' . print_r($lineCount, true) . '</pre>';
+ $dates->draw($page->getCanvas(), 20, $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->setText($event['name']);
+ $lineCount = $title->getLineCount();
+ //echo '<pre>title $lineCount: ' . print_r($lineCount, true) . '</pre>';
+ $title->draw($page->getCanvas(), 20, $pdfY);
+
+ $pdfY -= self::LINE_HEIGHT * $lineCount + 10;
+ //echo '<pre>title $pdfY: ' . print_r($pdfY, true) . '</pre>';
+
+ if ( isset($event['intro']) && $event['intro'] ) {
+ // text
+ $intro = new SetaPDF_Core_Text_Block( $font, 8 );
+ $introText = html_entity_decode(
+ $this->cleanText( $event['intro'] ),
+ ENT_HTML5
+ );
+ $intro->setText($introText);
+ $intro->setWidth(500);
+ $lineCount = $intro->getLineCount();
+ //echo '<pre>intro $lineCount: ' . print_r($lineCount, true) . '</pre>';
+ $intro->draw($page->getCanvas(), 20, $pdfY);
+
+ $pdfY -= self::LINE_HEIGHT * $lineCount;
+ if ( $lineCount == 1 ) {
+ $pdfY -= self::LINE_HEIGHT;
+ }
+ //echo '<pre>intro $pdfY: ' . print_r($pdfY, true) . '</pre>';
+ }
+ ++$index;
+
+ //$pdfY -= self::LINE_HEIGHT;
+ //echo '<pre>$pdfY: ' . print_r($pdfY, true) . '</pre>';
+
+ if ( $pdfY <= self::PDF_BOTTOM_Y && !( $totalEvents == $index ) ) {
+ $pdfY = self::PDF_TOP_Y;
+ $page = $pages->create(SetaPDF_Core_PageFormats::A4);
+ // add logo to top of the page
+ $xObject->draw($page->getCanvas(), 20, 770, 500, 60);
+ }
+ }
+
+
+ $document->save()->finish();
+
+ } catch(SetaPDF_Exception $e) {
+ echo '<p>SetaPDF_Exception: ' . $e->getMessage() . '</p>';
+ } catch(Exception $e) {
+ echo '<p>Exception: ' . $e->getMessage() . '</p>';
+ echo '<pre>' . print_r( $e, true ) . '</pre>';
+ }
exit;
break;
default:
'settings' => $settings
);
}
+
+ public function cleanText($text)
+ {
+ $text = str_replace(' ', ' ', $text);
+ $text = str_replace('–', '-', $text);
+ $text = str_replace(''', "'", $text);
+ $text = str_replace("\n", '', $text);
+ return $text;
+ }
}