2011-11-15 01:52:34 +04:00
|
|
|
<?php
|
2012-04-14 13:29:44 +04:00
|
|
|
class OC_Search_Provider_Calendar extends OC_Search_Provider{
|
|
|
|
function search($query){
|
2012-06-15 03:51:26 +04:00
|
|
|
$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser(), true);
|
2012-05-02 02:50:26 +04:00
|
|
|
if(count($calendars)==0 || !OCP\App::isEnabled('calendar')){
|
2011-11-15 01:52:34 +04:00
|
|
|
//return false;
|
|
|
|
}
|
|
|
|
$results=array();
|
|
|
|
$searchquery=array();
|
|
|
|
if(substr_count($query, ' ') > 0){
|
|
|
|
$searchquery = explode(' ', $query);
|
|
|
|
}else{
|
|
|
|
$searchquery[] = $query;
|
|
|
|
}
|
2012-05-02 17:54:34 +04:00
|
|
|
$user_timezone = OCP\Config::getUserValue(OCP\USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
|
2012-01-06 17:36:24 +04:00
|
|
|
$l = new OC_l10n('calendar');
|
2011-11-15 01:52:34 +04:00
|
|
|
foreach($calendars as $calendar){
|
|
|
|
$objects = OC_Calendar_Object::all($calendar['id']);
|
|
|
|
foreach($objects as $object){
|
2012-06-21 22:51:23 +04:00
|
|
|
if($object['objecttype']!='VEVENT') {
|
|
|
|
continue;
|
|
|
|
}
|
2012-01-06 17:36:24 +04:00
|
|
|
if(substr_count(strtolower($object['summary']), strtolower($query)) > 0){
|
|
|
|
$calendardata = OC_VObject::parse($object['calendardata']);
|
|
|
|
$vevent = $calendardata->VEVENT;
|
|
|
|
$dtstart = $vevent->DTSTART;
|
|
|
|
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
|
|
|
|
$start_dt = $dtstart->getDateTime();
|
|
|
|
$start_dt->setTimezone(new DateTimeZone($user_timezone));
|
|
|
|
$end_dt = $dtend->getDateTime();
|
|
|
|
$end_dt->setTimezone(new DateTimeZone($user_timezone));
|
2012-02-25 01:20:40 +04:00
|
|
|
if ($dtstart->getDateType() == Sabre_VObject_Property_DateTime::DATE){
|
2012-01-06 17:36:24 +04:00
|
|
|
$end_dt->modify('-1 sec');
|
|
|
|
if($start_dt->format('d.m.Y') != $end_dt->format('d.m.Y')){
|
|
|
|
$info = $l->t('Date') . ': ' . $start_dt->format('d.m.Y') . ' - ' . $end_dt->format('d.m.Y');
|
|
|
|
}else{
|
|
|
|
$info = $l->t('Date') . ': ' . $start_dt->format('d.m.Y');
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$info = $l->t('Date') . ': ' . $start_dt->format('d.m.y H:i') . ' - ' . $end_dt->format('d.m.y H:i');
|
|
|
|
}
|
2012-05-02 01:19:39 +04:00
|
|
|
$link = OCP\Util::linkTo('calendar', 'index.php').'?showevent='.urlencode($object['id']);
|
2012-06-21 22:51:23 +04:00
|
|
|
$results[]=new OC_Search_Result($object['summary'],$info, $link,(string)$l->t('Cal.'));//$name,$text,$link,$type
|
2011-11-15 01:52:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
}
|