Skip to content

Instantly share code, notes, and snippets.

@thyseus
Created May 15, 2013 10:18
Show Gist options
  • Select an option

  • Save thyseus/5582980 to your computer and use it in GitHub Desktop.

Select an option

Save thyseus/5582980 to your computer and use it in GitHub Desktop.
if($courses) {
$criteria = new CDbCriteria();
$criteria->addCondition(
sprintf(
"course_range_end >= '%s' and course_range_begin <= '%s' ",
$year.'-'.$month.'-01',
$year.'-'.$month.'-31'
));
if($course_area)
$criteria->addCondition(sprintf("course_area_id = %d",
$course_area
));
$criteria->addCondition('highlight = 1');
$courses_without_season = Course::model()->findAll($criteria);
$criteria = new CDbCriteria();
$criteria->with = array('courseArea');
$criteria->addCondition(
sprintf(
"courseArea.end >= '%s' and courseArea.begin <= '%s' ",
$year.'-'.$month.'-01',
$year.'-'.$month.'-31'
));
if($course_area)
$criteria->addCondition(sprintf("course_area_id = %d",
$course_area
));
$criteria->addCondition('highlight = 1');
$criteria->addCondition('season = 1');
$courses_within_season = Course::model()->findAll($criteria);
foreach($courses_within_season as $key => $course) {
$courses_within_season[$key]->course_range_begin = $courses_within_season[$key]->courseArea->begin;
$courses_within_season[$key]->course_range_end = $courses_within_season[$key]->courseArea->end;
}
$all_courses = array_merge($courses_without_season, $courses_within_season);
foreach($all_courses as $course) {
$firstcolspanexplode = explode('-', Ks::setDate($course->course_range_begin));
if(isset($firstcolspanexplode[2])) {
echo '<tr>';
if($firstcolspanexplode[1] == $month) {
$firstcolspan = $firstcolspanexplode[2] - 1;
for($i = 1; $i <= $firstcolspan; $i++)
printf( '<td class="empty %s %s">&nbsp;</td>', is_today($i, $month, $year) ? 'today' : '', is_weekend($i, $month, $year) ? 'weekend' : '');
}
else
$firstcolspan = 0;
if($firstcolspanexplode[1] == $month)
$diff = abs(
(strtotime($course->course_range_begin)
- strtotime($course->course_range_end))
/ (60 * 60 * 24)) + 1;
else
$diff = abs(
(strtotime($year.'-'.$month.'-01')
- strtotime($course->course_range_end))
/ (60 * 60 * 24)) + 1;
$lastcolspan = $lengthOfMonth - ($firstcolspan + $diff);
printf('<td class="course" colspan="%d">%s</td>',
$diff,
CHtml::link( $course->title, '', array(
'onClick' => 'getCourseInfo('.$course->id.')',
'style' => 'cursor:pointer;')),
$lastcolspan
);
for($j = $firstcolspan + $diff + 1; $j <= $lengthOfMonth; $j++)
printf( '<td class="empty %s %s">&nbsp;</td>', is_today($j, $month, $year) ? 'today' : '', is_weekend($j, $month, $year) ? 'weekend' : '');
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment