Skip to content

Instantly share code, notes, and snippets.

@muskie9
Last active September 1, 2015 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muskie9/b2c2b3f0e617e7ce15ca to your computer and use it in GitHub Desktop.
Save muskie9/b2c2b3f0e617e7ce15ca to your computer and use it in GitHub Desktop.
<?php
/**
* function that gets the formatted
* string for event instances (gridview).
* It will format a recursion instance set
* or additional date set. If additional date set
* It will get either the base event's ID or it's
* own ID, if it's the base event.
*
* @return bool|string
*/
public function getDateRange(){
if($this->Recursion){
$dateRange = self::generateDaysString($this) . ' | ' . date('F jS',
strtotime($this->StartDate)) . ' - ' . date('F jS',
strtotime($this->RecursionEndDate)) . $this->getNiceStartTime();
if ($this->getNiceEndTime()) {
$dateRange .= ' to ' . $this->getNiceEndTime();
}
}else{
$id = ($this->BaseEventID) ? $this->BaseEventID : $this->ID;
$next = AdditionalDate::get()->filter(array(
'Date:GreaterThanOrEqual' => date('Y-m-d'),
'EventID' => $id
))->sort('Date')->first();
$nextID = $next->ID;//errors here
$otherDates = AdditionalDate::get()->filter(array(
'Date:GreaterThanOrEqual' => date('Y-m-d'),
'EventID' => $id
))->exclude(array('ID' => $nextID))->sort('Date');
$monthCheck = null;
$dateRange = '';
$find = ',';
$buildString = function ($date) use (&$monthCheck, &$dateRange, $find) {
if (date('m', strtotime($date->Date)) == $monthCheck) {
$dateRange .= ', ' . date('jS', strtotime($date->Date));
} else {
$dateRange = preg_replace('/(,(?!.*,))/', ' &', $dateRange);
$dateRange .= ($dateRange == '') ? date('F jS', strtotime($date->Date)) : ', ' . date('F jS',
strtotime($date->Date));
$monthCheck = date('m', strtotime($date->Date));
}
};
$otherDates->each($buildString);
}
return ($dateRange != '') ? $dateRange : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment