function getnext($recurrence, $last_xref, JRegistry $params = null) { $rule = RedeventHelperRecurrence::getRule($recurrence); if ($params === null) { $params =& JComponentHelper::getParams('com_redevent'); } $week_start = $params->get('week_start', 'SU'); // echo '<pre>';print_r($rule); echo '</pre>';exit; // print_r($last_xref); $new = false; // check the count if ($rule->until_type == 'count' && $last_xref->count >= $rule->count) { return false; } $days_name = array('SU' => 'sunday', 'MO' => 'monday', 'TU' => 'tuesday', 'WE' => 'wednesday', 'TH' => 'thursday', 'FR' => 'friday', 'SA' => 'saturday'); $days_number = array('SU' => 0, 'MO' => 1, 'TU' => 2, 'WE' => 3, 'TH' => 4, 'FR' => 5, 'SA' => 6, 'SU' => 7); $xref_start = strtotime($last_xref->dates); // get the next start timestamp switch ($rule->type) { case 'DAILY': $next_start = strtotime($last_xref->dates . " +" . $rule->interval . " day"); break; case 'WEEKLY': // calculate next dates for all set weekdays $next = array(); if (!$rule->weekdays || !count($rule->weekdays)) { // force to the day of previous session $rule->weekdays = array(array_search(date('N', strtotime($last_xref->dates)), $days_number)); } foreach ($rule->weekdays as $d) { if ($week_start == 'SU') { $current = strftime('%w', $xref_start); } else { $current = strftime('%u', $xref_start); } if ($days_number[$d] > $current) { $next[] = strtotime('+1 ' . $days_name[$d], strtotime($last_xref->dates)); } else { if ($days_number[$d] == $current) { // same day, look in next intervall, after this day $next[] = strtotime('+' . $rule->interval . ' ' . $days_name[$d], strtotime($last_xref->dates) + 3600 * 24); } else { // in next intervall $next[] = strtotime('+' . $rule->interval . ' ' . $days_name[$d], strtotime($last_xref->dates)); } } } // the next one is the lowest value $next_start = min($next); break; case 'MONTHLY': if ($rule->monthtype == 'byday') { // first day of this month $first_this = mktime(0, 0, 0, strftime('%m', $xref_start), 1, strftime('%Y', $xref_start)); // last day of this month $last_this = mktime(0, 0, 0, strftime('%m', $xref_start) + 1, 0, strftime('%Y', $xref_start)); // first day of +interval month $first_next_interval = mktime(0, 0, 0, strftime('%m', $xref_start) + $rule->interval, 1, strftime('%Y', $xref_start)); // last day of this month $last_next_interval = mktime(0, 0, 0, strftime('%m', $xref_start) + 1 + $rule->interval, 0, strftime('%Y', $xref_start)); $days = array(); // print_r($rule); foreach ($rule->weeks as $week) { foreach ($rule->weekdays as $day) { $int_day = strtotime($week . ' ' . $days_name[$day], $first_this); if ($int_day > $xref_start && $int_day <= $last_this) { $days[] = $int_day; } $int_day = strtotime($week . ' ' . $days_name[$day], $first_next_interval); if ($int_day > $xref_start && $int_day <= $last_next_interval) { $days[] = $int_day; } } } foreach ($rule->rweeks as $week) { foreach ($rule->rweekdays as $day) { $int_day = strtotime('-' . $week . ' ' . $days_name[$day], $last_this + 24 * 3600); if ($int_day > $xref_start && $int_day >= $first_this) { $days[] = $int_day; } $int_day = strtotime('-' . $week . ' ' . $days_name[$day], $last_next_interval + 24 * 3600); if ($int_day > $xref_start && $int_day >= $first_next_interval) { $days[] = $int_day; } } } $next_start = min($days); } else { $current = strftime('%d', strtotime($last_xref->dates)); if (!$rule->bydays || !count($rule->bydays)) { // force to the day of previous session $rule->bydays = array(date('d', strtotime($last_xref->dates))); } if (!$rule->reverse_bydays) { sort($rule->bydays); $next_day = null; foreach ($rule->bydays as $day) { if ($day > $current) { $next_day = $day; break; } } if ($next_day == null) { $year_month = strftime('%Y-%m', strtotime(date("Y-m-1", strtotime($last_xref->dates)) . ' + ' . $rule->interval . " months")); $next_start = strtotime($year_month . '-' . $rule->bydays[0]); } else { $year_month = strftime('%Y-%m', strtotime($last_xref->dates)); $next_start = strtotime($year_month . '-' . $next_day); } } else { $current_sec = strtotime($last_xref->dates); $next = array(); foreach ($rule->bydays as $day) { // we need to check the dates for this month, and the +interval month $dd = strtotime(date("Y-m-1", strtotime($last_xref->dates)) . ' + 1 months -' . $day . ' day'); if ($dd > $current_sec) { $next[] = $dd; } $dd = strtotime(date("Y-m-1", strtotime($last_xref->dates)) . ' +' . (1 + $rule->interval) . ' months -' . $day . ' days', strtotime($last_xref->dates)); if ($dd > $current_sec) { $next[] = $dd; } } // the next is the closest, lower value $next_start = min($next); } } break; case 'YEARLY': $current = strtotime($last_xref->dates); if (empty($rule->bydays)) { $next_start = mktime(0, 0, 0, strftime('%m', $current), strftime('%d', $current), strftime('%Y', $current) + $rule->interval); } else { if (!$rule->reverse_bydays) { sort($rule->bydays); $next_day = $rule->bydays[0]; foreach ($rule->bydays as $day) { if ($day > $current) { $next_day = $day; break; } } if ($next_day == $rule->bydays[0]) { $next_start = mktime(0, 0, 0, 1, $next_day, strftime('%Y', strtotime($last_xref->dates)) + 1); } else { $next_start = mktime(0, 0, 0, 1, $next_day, strftime('%Y', strtotime($last_xref->dates))); } } else { // total days in this year $total = strftime('%j', mktime(0, 0, 0, 1, 0, strftime('%Y', strtotime($last_xref->dates)) + 1)); $rev_days = array(); // get number in proper order rsort($rule->bydays); foreach ($rule->bydays as $day) { $rev_days[] = $total - $day + 1; } $next_day = null; foreach ($rev_days as $day) { if ($day > $current) { $next_day = $day; break; } } if ($next_day == null) { $next_start = mktime(0, 0, 0, 1, -$rule->bydays[0], strftime('%Y', strtotime($last_xref->dates)) + 1 + $rule->interval); } else { $next_start = mktime(0, 0, 0, 1, $next_day, strftime('%Y', strtotime($last_xref->dates))); } } } break; case 'NONE': default: break; } if (!isset($next_start) || !$next_start) { return false; } // check the until rule if ($rule->until_type == 'until' && strtotime(strftime('%Y-%m-%d', $next_start) . ' ' . $last_xref->times) > strtotime($rule->until)) { return false; } $delta = $next_start - strtotime($last_xref->dates); if (!$delta) { // no delta, so same session... return false; } // return the new occurence $new = clone $last_xref; unset($new->id); $new->dates = strftime('%Y-%m-%d', $next_start); if (strtotime($last_xref->enddates)) { $new->enddates = strftime('%Y-%m-%d', strtotime($last_xref->enddates) + $delta); } if (strtotime($last_xref->registrationend)) { $new->registrationend = strftime('%Y-%m-%d', strtotime($last_xref->registrationend) + $delta); } $new->count++; // echo '<pre>';print_r($new); echo '</pre>';exit; // print_r($new); // exit; return $new; }
/** * return details about session * * @param bool $no_check set true to skip acl check * @return multitype: */ function getSessionDetails($no_check = false) { $app =& JFactory::getApplication(); if (empty($this->_xrefdata)) { $acl =& UserAcl::getInstance(); if ($this->_xref) { if (!$no_check && !$acl->canEditXref($this->_xref)) { JError::raiseError(403, JText::_('COM_REDEVENT_NOT_ALLOWED')); } $this->_xrefdata = $this->_getXrefData($this->_xref); } else { if (!$no_check && !$acl->canAddXref()) { JError::raiseError(403, JText::_('COM_REDEVENT_NOT_ALLOWED')); } $template_xref = $app->getParams()->get('event_template', 0); if ($template_xref) { $obj = $this->_getXrefData($template_xref); } else { $obj = new stdclass(); $obj->groupid = 0; $obj->external_registration_url = null; $obj->details = null; $obj->maxattendees = 0; $obj->maxwaitinglist = 0; $obj->course_credit = 0; $obj->published = 1; } $obj->id = null; $obj->eventid = 0; $obj->title = null; $obj->venueid = 0; $obj->dates = null; $obj->enddates = null; $obj->times = null; $obj->endtimes = null; $obj->registrationend = null; $obj->recurrence_id = 0; $obj->count = 0; $obj->rrule = null; $this->_xrefdata = $obj; } } $this->_xrefdata->rrules = RedeventHelperRecurrence::getRule($this->_xrefdata->rrule); return $this->_xrefdata; }
/** * return xref from request * * @return unknown */ function getXref() { $xref = $this->_id; if ($xref) { $customs = $this->_getXCustomFields(); $query = ' SELECT x.*, v.venue, r.id as recurrence_id, r.rrule, rp.count '; // add the custom fields foreach ((array) $customs as $c) { $query .= ', x.custom' . $c->id; } $query .= ' FROM #__redevent_event_venue_xref AS x ' . ' LEFT JOIN #__redevent_venues AS v on v.id = x.venueid ' . ' LEFT JOIN #__redevent_repeats AS rp on rp.xref_id = x.id ' . ' LEFT JOIN #__redevent_recurrences AS r on r.id = rp.recurrence_id '; $query .= ' WHERE x.id = ' . $this->_db->Quote($xref); $this->_db->setQuery($query); $object = $this->_db->loadObject(); $object->rrules = RedeventHelperRecurrence::getRule($object->rrule); } else { $object = JTable::getInstance('RedEvent_eventvenuexref', ''); $object->id = null; $object->venue = 0; $object->recurrence_id = 0; $object->rrule = ''; $object->count = 0; $object->rrules = RedeventHelperRecurrence::getRule(); } return $object; }