added a new table to mxcalendar for the repeating-events:
CREATE TABLE `modx_mxcalendar_repeatings` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`repeating` DATE NULL DEFAULT NULL,
`eventid` INT(10) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `repeating` (`repeating`)
)
COLLATE='latin1_swedish_ci'
ENGINE=MyISAM
ROW_FORMAT=DEFAULT
and this bit of code at the end of mxcalendars _saveEvent - function.
$rep_table=$modx->getFullTablename('mxcalendar_repeatings');
$modx->db->delete($rep_table,'eventid='.$NID);
$repeatings = explode(',',$reOcc);
if (count($repeatings)>0){
$repeatings = array_merge(array($fields['startdate']),$repeatings);
foreach ($repeatings as $rep){
$fields = array();
$fields['eventid'] = $NID;
$fields['repeating'] = $rep;
$modx->db->insert($fields, $rep_table);
}
}
now its possible to get all events including the repeatings in one query sorted, limited(for pagination), what you want with this function:
function getMxEvents($timestart, $timeend, $limit = 0, $category = '')
{
global $modx;
$tablename = $modx->getFullTableName('mxcalendar_events');
$table2 = $modx->getFullTableName('mxcalendar_categories');
$where = 'e.active = 1';
if (!empty($category)) {
$where .= ' and e.category = ' . $category;
}
//-- Front end: returns logged in user's webgroup assignments [webgroup = web group id's user belongs to]
if ($modx->getLoginUserID()) {
$userInfo = $modx->db->makeArray($modx->db->select('webgroup', $modx->getFullTableName('web_groups'), '`webuser`=' . $modx->getLoginUserID()));
//-- Web View Permission Where Builder
foreach ($userInfo as $wu) {
foreach ($wu as $wp) $WHERE_WGP[] = 'FIND_IN_SET(' . $wp['0'] . ',E.restrictedwebusergroup)';
}
}
$query = "select e.* ";
$query .= " ,c.name as cat_name, c.foregroundcss as cat_fg , c.backgroundcss as cat_bg ,c.inlinecss as cat_css";
$query .= " , UNIX_TIMESTAMP(IF(eventid is not null,CONCAT(repeating,' ',e.starttime) ,start )) AS Time";
$query .= " , UNIX_TIMESTAMP(IF(eventid is not null,ADDTIME(repeating,TIMEDIFF(e.end, CAST(e.startdate as datetime))),end)) AS Timeend";
$query .= " ,(SELECT TIMESTAMPDIFF(SECOND,e.start,e.end)) as DurationSeconds";
$query .= " from " . $tablename . "e";
$query .= " left join $table2 c ON c.id=e.category";
$query .= " left join modx_mxcalendar_repeatings r on r.eventid = e.id ";
$query .= " where " . $where;
$query .= ' AND ' . ($WHERE_WGP && count($WHERE_WGP) ? '(' . implode(' OR ', $WHERE_WGP) . ' OR ( e.restrictedwebusergroup = \'\' OR e.restrictedwebusergroup <=> NULL ))' :
'( e.restrictedwebusergroup = \'\' OR e.restrictedwebusergroup <=> NULL )');
//Terminbeginn innerhalb der Zeitspanne
$query .= " having(( Time >= '$timestart' and Time <= '$timeend') ";
$query .= " or ";
//oder Terminende innerhalb der Zeitspanne
$query .= "(Timeend >= '$timestart' and Timeend <= '$timeend') ";
$query .= " or ";
//oder abgefragte Zeitspanne beginnt innerbalb des Terminzeitraums
$query .= "('$timestart' >= Time and '$timestart' <= Timeend) ";
$query .= " ) ";
$query .= " order by Time {$orderDir}";
if ($limit) {
$query .= ' LIMIT ' . $limit;
}
//echo $query;
$rs = $modx->db->query($query);
$events = $modx->db->makeArray($rs);
//echo '<pre>' . print_r($events, true) . '</pre>';
return $events;
}
I use it for a minicalendar, generated with bloX. bloX can generate calendar-views out of a given array of events.
you can see a test-installation here:
http://www.webcmsolutions.de/minical.html