Skip to content

Commit

Permalink
ENHANCEMENT: Search form
Browse files Browse the repository at this point in the history
  • Loading branch information
Uncle Cheese committed Aug 22, 2012
2 parents 395166a + bad301f commit 20aa885
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
56 changes: 47 additions & 9 deletions code/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class Calendar extends Page {
static $language = "EN";


static $jquery_included = false;



protected $eventClass_cache,
$announcementClass_cache,
$datetimeClass_cache,
Expand All @@ -77,6 +81,13 @@ class Calendar extends Page {



public static function set_jquery_included($bool = true) {
self::$jquery_included = $bool;
}




public function getCMSFields()
{

Expand Down Expand Up @@ -162,7 +173,7 @@ public function getDateToEventRelation() {



public function getEventList($start, $end, $filter = null, $limit = null) {
public function getEventList($start, $end, $filter = null, $limit = null, $announcement_filter = null) {
foreach($this->getAllCalendars() as $calendar) {
$eventList = new ArrayList();
if($events = $calendar->getStandardEvents($start, $end, $filter)) {
Expand All @@ -176,7 +187,7 @@ public function getEventList($start, $end, $filter = null, $limit = null) {
(EndDate BETWEEN '$start' AND '$end')
");
if($filter) {
$announcements->filter($filter);
$announcements->where($announcement_filter);
}

if($announcements) {
Expand Down Expand Up @@ -246,7 +257,7 @@ protected function getRecurringEvents($filter = null) {
->filter("ParentID", $this->ID)
->innerJoin($datetime_class, "\"{$datetime_class}\".{$relation} = \"SiteTree\".ID");
if($filter) {
$events->filter($filter);
$events->where($filter);
}
return $events;
}
Expand Down Expand Up @@ -379,6 +390,16 @@ public function CalendarWidget() {
}
return $calendar;
}

public function MonthJumpForm() {
$controller = Controller::curr();
if($controller->class == "Calendar_Controller" || is_subclass_of($controller, "Calendar_Controller")) {
return Controller::curr()->MonthJumpForm();
}
$c = new Calendar_Controller($this);
return $c->MonthJumpForm();
}




Expand Down Expand Up @@ -419,7 +440,9 @@ public function init() {
parent::init();
RSSFeed::linkToFeed($this->Link() . "rss", $this->RSSTitle ? $this->RSSTitle : $this->Title);
Requirements::themedCSS('calendar.css');
Requirements::javascript(THIRDPARTY_DIR.'/jquery/jquery.js');
if(!Calendar::$jquery_included) {
Requirements::javascript(THIRDPARTY_DIR.'/jquery/jquery.js');
}
Requirements::javascript('event_calendar/javascript/calendar.js');
}

Expand Down Expand Up @@ -520,7 +543,7 @@ public function respond() {
public function index(SS_HTTPRequest $r) {
switch($this->DefaultView) {
case "month":
return Director::redirect($this->Link('show/month'));
return $this->redirect($this->Link('show/month'));
break;

case "week":
Expand Down Expand Up @@ -731,7 +754,7 @@ public function ics(SS_HTTPRequest $r) {
return $result;
}
else {
Director::redirectBack();
$this->redirectBack();
}
}

Expand Down Expand Up @@ -775,9 +798,20 @@ public function parseURL(SS_HTTPRequest $r) {


public function Events() {
$event_filter = null;
$announcement_filter = null;
if($search = $this->getRequest()->getVar('s')) {
$s = Convert::raw2sql($search);
$event_filter = "\"SiteTree\".Title LIKE '%$s%' OR \"SiteTree\".Content LIKE '%$s%'";
$announcement_filter = "\"CalendarAnnouncement\".Title LIKE '%$s%' OR \"CalendarAnnouncement\".Content LIKE '%$s%'";
$this->SearchQuery = $search;
}
$all = $this->data()->getEventList(
$this->startDate->dump(),
$this->endDate->dump()
$this->endDate->dump(),
$event_filter,
null,
$announcement_filter
);
$list = $all->limit($this->EventsPerPage, $this->getOffset());
$next = $this->getOffset()+$this->EventsPerPage;
Expand Down Expand Up @@ -907,7 +941,7 @@ public function MonthJumpForm() {
$range = range(($dummy->subtractYear(3)->format('Y')), ($dummy->addYear(6)->format('Y')));
$year_map = array_combine($range, $range);
$f = new Form(
Controller::curr(),
$this,
"MonthJumpForm",
new FieldList (
$m = new DropdownField('Month','', CalendarUtil::get_months_map('%B')),
Expand All @@ -922,11 +956,15 @@ public function MonthJumpForm() {
$m->setValue($this->startDate->format('m'));
$y->setValue($this->startDate->format('Y'));
}
else {
$m->setValue(date('m'));
$y->setValue(date('Y'));
}
return $f;
}

public function doMonthJump($data, $form) {
return Director::redirect($this->Link('show').'/'.$data['Year'].$data['Month']);
return $this->redirect($this->Link('show').'/'.$data['Year'].$data['Month']);
}


Expand Down
11 changes: 7 additions & 4 deletions javascript/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ $(function() {
})
});


/*
$(window).scroll(function() {
if ($(window).scrollTop() >= ($(document).height() - $(window).height())) {
if ($('.calendar-view-more').length && !fetching) {
if($('.calendar-view-more').length && !fetching) {
var offset = $('.calendar-view-more').offset();
if($(window).scrollTop()+$(window).height() >= offset.top) {
$('.calendar-view-more').click();
}
}
}
});
*/

});

})(jQuery);

0 comments on commit 20aa885

Please sign in to comment.