Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions _build/data/transport.snippets.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,60 @@ function getSnippetContent($filename) {
$snippets[1]= $modx->newObject('modSnippet');
$snippets[1]->fromArray(array(
'id' => 1,
'name' => 'mxcalendar',
'name' => 'mxCalendar',
'description' => 'Displays events in either calendar, list, or detail view.',
'snippet' => getSnippetContent($sources['elements'].'snippets/snippet.mxcalendars.php'),
'snippet' => getSnippetContent($sources['elements'].'snippets/snippet.mxcalendar.php'),
),'',true,true);
$properties = include $sources['data'].'properties/properties.mxcalendars.php';
$properties = include $sources['data'].'properties/properties.mxcalendar.php';
$snippets[1]->setProperties($properties);
unset($properties);

//-- Add init snippet (2)
$snippets[2]= $modx->newObject('modSnippet');
$snippets[2]->fromArray(array(
'id' => 2,
'name' => 'mxCalendarInit',
'description' => 'Init mxCalendar service.',
'snippet' => getSnippetContent($sources['elements'].'snippets/mxcalendarinit.php'),
),'',true,true);
$properties = include $sources['data'].'properties/properties.mxcalendarinit.php';
$snippets[2]->setProperties($properties);
unset($properties);

//-- Add getEvents snippet (3)
$snippets[3]= $modx->newObject('modSnippet');
$snippets[3]->fromArray(array(
'id' => 3,
'name' => 'mxCalendarGetEvents',
'description' => 'Get events (retrieved from database together with generated on-the-fly by repeat template).',
'snippet' => getSnippetContent($sources['elements'].'snippets/snippet.mxcalendargetevents.php'),
),'',true,true);
$properties = include $sources['data'].'properties/properties.mxcalendargetevents.php';
$snippets[3]->setProperties($properties);
unset($properties);

//-- Add sort snippet (4)
$snippets[4]= $modx->newObject('modSnippet');
$snippets[4]->fromArray(array(
'id' => 4,
'name' => 'mxCalendarSort',
'description' => 'Sort events.',
'snippet' => getSnippetContent($sources['elements'].'snippets/snippet.mxcalendarsort.php'),
),'',true,true);
$properties = include $sources['data'].'properties/properties.mxcalendarsort.php';
$snippets[4]->setProperties($properties);
unset($properties);

//-- Add prepare for render snippet (5)
$snippets[5]= $modx->newObject('modSnippet');
$snippets[5]->fromArray(array(
'id' => 5,
'name' => 'mxCalendarPrerender',
'description' => 'Prepare events for render.',
'snippet' => getSnippetContent($sources['elements'].'snippets/snippet.mxcalendarprerender.php'),
),'',true,true);
$properties = include $sources['data'].'properties/properties.mxcalendarprerender.php';
$snippets[5]->setProperties($properties);
unset($properties);

return $snippets;
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
// SAMPLE EVENT SUBMISSION HOOK FOR mxFormBuilder


$mxcal = $modx->getService('mxcalendars','mxCalendars',$modx->getOption('mxcalendars.core_path',null,$modx->getOption('core_path').'components/mxcalendars/').'model/mxcalendars/',$scriptProperties);
if (!($mxcal instanceof mxCalendars)) return 'Error loading instance of mxCalendars.';

include_once($modx->getOption('mxcalendars.core_path',null,$modx->getOption('core_path').'components/mxcalendars/').'processors/mgr/mxcHelper.php');
/**
* SAMPLE EVENT SUBMISSION HOOK FOR mxFormBuilder
*
* @var $modx modX
* @var $scriptProperties array
*/

/** @var $mxCal mxCalendars */
$mxCal = $modx->runSnippet('mxCalendar.init', $scriptProperties);


$allFormFields = $hook->getProperties();
Expand Down
322 changes: 322 additions & 0 deletions core/components/mxcalendars/elements/snippets/snippet.mxcalendar.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
/**
* Get an array of mxCalendar events - retrieved from database together with generated on-the-fly.
*
* @var $modx modX
* @var $scriptProperties array
*
* @var $criteria xPDOQuery
* @var $debug bool
*
* @return array(
* 'events', // unsorted array of events (retrieved from database together with generated by repeat template)
* 'debugOutput', // string, containing information, valuable for debugging
* )
*/
/** @var $mxCal mxCalendars */
$mxCal = $modx->runSnippet('mxCalendarInit', $scriptProperties);

$debugOutput = '';
$debug = $modx->getOption('debug', $scriptProperties);
$criteria = $modx->getOption('criteria', $scriptProperties, $modx->newQuery('mxCalendarEvents')->select(array(
'mxCalendarEvents.*',
)));
$criteria->prepare();
if($debug) $debugOutput .= '<br /><br />Filtering calendar date SQL range with: '.strftime('%m/%d/%Y', $elStartDate).' through '.strftime('%m/%d/%Y', $elEndDate).'<br /><br />';
if($debug) $debugOutput .= 'SQL: '.$criteria->toSql().'<br /><br />';
$queryTimer = new makeProcessTime(null,$debug);
$mxcalendars = $modx->getCollection('mxCalendarEvents',$criteria);
$queryTimer->end('mxCalendars Query');
if($debug) $debugOutput .= "<br />Returned Events: ".count($mxcalendars).'<br />';
$resultLoopTimer = new makeProcessTime(null,$debug);
$arrEventDates = array();
/** @var $mxc mxCalendarEvents */
foreach ($mxcalendars as $mxc) {
//-- Convert the object to an array
$mxcArray = $mxc->toArray();

$eStart = new DateTime(date('Y-m-d H:i:s',$mxc->get('startdate')));
$eEnd = new DateTime(date('Y-m-d H:i:s',$mxc->get('enddate')));

$isNew = (version_compare(PHP_VERSION, '5.3.0') >= 0);
$diff = $isNew ? $eStart->diff($eEnd) : (object)$mxCal->datediff($mxc->get('startdate'),$mxc->get('enddate'),true);
$durYear = $isNew ? $diff->format('%y') : $diff->years;
$durMonth = $isNew ? $diff->format('%m') : $diff->months;
$durDay = $isNew ? $diff->format('%d') : $diff->days;
$durHour = $isNew ? $diff->format('%h') : $diff->hours;
$durMin = $isNew ? $diff->format('%i') : $diff->minutes;
$durSec = $isNew ? $diff->format('%s') : $diff->seconds;

//-- return event duration values
$mxcArray['durYear'] = !empty($durYear) ? $durYear : null;
$mxcArray['durMonth'] = !empty($durMonth) ? $durMonth : null;
$mxcArray['durDay'] = !empty($durDay) ? $durDay : null;
$mxcArray['durHour'] = !empty($durHour) ? $durHour : null;
$mxcArray['durMin'] = !empty($durMin) ? $durMin : null;
$mxcArray['durSec'] = !empty($durSec) ? $durSec : null;
$mxcArray['mxcmodalClass'] = ($modalView && $ajaxResourceId || isset($_REQUEST['imajax']) ? 'mxcmodal' : '');

$arrEventsDetail[$mxcArray['id']] = $mxcArray;
$arrEventDates[$mxcArray['id']] = array(
'date'=>$mxcArray['startdate'],
'eventId'=>$mxcArray['id'],
'repeatId'=>0,
);

//-- If we have repeating dates and repeating is enabled lets add those to the array
if ($mxcArray['repeating'] && ($repeatDates = explode(',', $mxcArray['repeatdates']))) {
if($debug) $debugOutput .= 'Repeating Event: '.$mxcArray['title'].'<br />';
if($debug) $debugOutput .= '&nbsp;&nbsp;&nbsp;++(0)&nbsp;&nbsp;'.strftime($dateFormat.' '.$timeFormat, $mxcArray['startdate']).'<br>';
$rid = 1;
foreach ($repeatDates AS $rDate) {
if (empty($rDate)) {
continue;
}
$arrEventDates[$mxcArray['id'].'-'.$rid] = array(
'date'=>$rDate,
'eventId'=>$mxcArray['id'],
'repeatId'=>$rid,
);
if($debug) $debugOutput .= '&nbsp;&nbsp;&nbsp;++('.$rid.')&nbsp;&nbsp;'.strftime($dateFormat.' '.$timeFormat, $rDate).'<br>';
$rid++;
}
}

// Add date for each day in a multiple day event ( #127 )
if($mxcArray['durDay'] !== null && $mxcArray['durDay'] >= 1){
if($debug) $debugOutput .= 'Multiple Day Event: '.$mxcArray['title'].'<br />';

/*
$i = 1;
$endDate = $mxc->get('enddate');
while(strtotime('+'.$i.' day', $mxcArray['startdate']) < $endDate){
$theSpanDate = strtotime('+'.$i.' day', $mxcArray['startdate']);
$arrEventDates[$mxcArray['id'].'_'.$i] = array('date'=>$theSpanDate, 'eventId'=>$mxcArray['id'],'repeatId'=>null);
if($debug) $debugOutput .= '&nbsp;&nbsp;&nbsp;++('.$i.')&nbsp;&nbsp;'.strftime($dateFormat.' '.$timeFormat, $theSpanDate).'<br>';
$i++;
}
*
*/

for ($i = 1; $i<=$mxcArray['durDay']; $i++) {
$theSpanDate = strtotime('+'.$i.' day', $mxcArray['startdate']);
$arrEventDates[$mxcArray['id'].'_'.$i] = array(
'date'=>$theSpanDate,
'eventId'=>$mxcArray['id'],
'repeatId'=>null,
);
if($debug) $debugOutput .= '&nbsp;&nbsp;&nbsp;++('.$i.')&nbsp;&nbsp;'.strftime($dateFormat.' '.$timeFormat, $theSpanDate).'<br>';
}
}

//$output .= $mxCal->getChunk($tpl,$mxcArray);
}
$resultLoopTimer->end('mxc result set loop');

// Indexed array - in order to be used with list().
return array($arrEventDates,$debugOutput);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* mxCalendar initialization.
* Run this snippet before using mxCalendar.
*
* @var $modx modX
* @var $scriptProperties array
*
* @return $mxCal mxCalendars
*/
$corePath = $modx->getOption('core_path');
$mxCalendarCorePath = $modx->getOption('mxcalendars.core_path',null,"{$corePath}components/mxcalendars/");
$mxCal = $modx->getService('mxcalendars','mxCalendars',$mxCalendarCorePath.'model/mxcalendars/',$scriptProperties);
if (!($mxCal instanceof mxCalendars)) throw new Exception('Error loading instance of mxCalendars.');
include_once "{$mxCalendarCorePath}processors/mgr/mxcHelper.php";
return $mxCal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* mxCalendar prepare for render.
*
* @var $modx modX
* @var $scriptProperties array
*
* @var $events array array of events to prepare
* @var $elStartDate int event list start date timestamp
* @var $elEndDate int event list end date timestamp
* @var $displayType string
* @var $elDirectional bool
* @var $limit int
* @var $debug bool
*
* @return array(
* 'events', // sorted array of events
* 'debugOutput', // string, containing information, valuable for debugging
*/
$mxCal = $modx->runSnippet('mxCalendarInit', $scriptProperties);

$debugOutput = '';
$debug = $modx->getOption('debug', $scriptProperties);
$eventsRaw = $modx->getOption('events', $scriptProperties, array());
if (empty($eventsRaw)) {
$debugOutput .= "No data to prepare for render.\n";
}
$elStartDate = $modx->getOption('elStartDate', $scriptProperties);
$elEndDate = $modx->getOption('elEndDate', $scriptProperties);
$displayType = $modx->getOption('displayType', $scriptProperties);
$elDirectional = $modx->getOption('elDirectional',$scriptProperties, false);
$limit = $modx->getOption('limit',$scriptProperties,'99');

if($debug) $debugOutput .= 'Looping through events list of '.count($arrEventDates).' total.<br />';
$ulimit=0;

$arrayEventTimer = new makeProcessTime(null,$debug);

$cnt = 1;
$events = [];
foreach ($eventsRaw AS $k=>$e) {
$oDetails = $arrEventsDetail[$e['eventId']]; //Get original event (parent) details
$oDetails['startdate'] = $e['date'];
$oDetails['enddate'] = strtotime('+'.($arrEventsDetail[$e['eventId']]['durDay'] ? $arrEventsDetail[$e['eventId']]['durDay'].' days ' :'').($arrEventsDetail[$e['eventId']]['durHour'] ? $arrEventsDetail[$e['eventId']]['durHour'].' hour ' :'').($arrEventsDetail[$e['eventId']]['durMin'] ? $arrEventsDetail[$e['eventId']]['durMin'].' minute' :''), $e['date']);//$e['date'];//repeatenddate
if((
(
($oDetails['startdate']>=$elStartDate || $oDetails['enddate'] >= $elStartDate)
&&
$oDetails['enddate']<=$elEndDate
)
||
$displayType=='detail' || $displayType=='calendar' || $displayType == 'mini'
||
$elDirectional
)){

$oDetails['startdate_fstamp'] = $e['date'];
$oDetails['enddate_fstamp'] = $arrEventsDetail[$e['eventId']]['enddate'];

$oDetails['detailURL'] = $modx->makeUrl((!empty($ajaxResourceId) && (bool)$modalView === true ? $ajaxResourceId : $resourceId),'',array('detail' => $e['eventId'], 'r'=>$e['repeatId']));
$events[strftime('%Y-%m-%d', $e['date'])][] = $oDetails;
$ulimit++;
if($debug) $debugOutput .= $cnt.')&nbsp;&nbsp;&nbsp;&nbsp;'.$ulimit.'['.$limit.']) '.strftime($dateFormat,$e['date']).' '.$e['eventId'].'<br />';
if($ulimit >= $limit && $displayType=='list' ) break;
$cnt++;
}
}
$arrayEventTimer->end('arrEventDates');

// Indexed array - in order to be used with list().
return array($events,$debugOutput);
Loading