mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-03 04:29:28 +01:00
Use custom query for last/next event instead of search
This commit is contained in:
parent
522b30c62e
commit
16ddefcecf
@ -1674,67 +1674,84 @@ class Contacts extends Contacts\Storage
|
|||||||
if (!$GLOBALS['egw_info']['user']['apps']['calendar']) return array();
|
if (!$GLOBALS['egw_info']['user']['apps']['calendar']) return array();
|
||||||
|
|
||||||
$bocal = new calendar_bo();
|
$bocal = new calendar_bo();
|
||||||
$events = $bocal->search(array(
|
$sql = 'SELECT n_fn,org_name,contact_id,
|
||||||
'start' => strtotime('2 years ago'),
|
(
|
||||||
'end' => strtotime('2 years from now'),
|
select concat(cal_start,":",egw_cal_user.cal_id,":",cal_title)
|
||||||
'users' => $uids,
|
from egw_cal_user
|
||||||
'enum_recuring' => true,
|
JOIN egw_cal_dates on egw_cal_dates.cal_id=egw_cal_user.cal_id and (cal_recur_date=0 or cal_recur_date=cal_start)
|
||||||
));
|
JOIN egw_cal ON egw_cal.cal_id=egw_cal_user.cal_id
|
||||||
if (!$events) return array();
|
WHERE cal_user_type="c" and cal_user_id=contact_id and cal_start < unix_timestamp(now())';
|
||||||
|
if ( !$GLOBALS['egw_info']['user']['preferences']['calendar']['show_rejected'])
|
||||||
|
{
|
||||||
|
$sql .= ' AND egw_cal_user.cal_status != "R"';
|
||||||
|
}
|
||||||
|
$sql .= '
|
||||||
|
order by cal_start DESC Limit 1
|
||||||
|
) as last_event,
|
||||||
|
(
|
||||||
|
select concat(cal_start,":",egw_cal_user.cal_id,":",cal_title)
|
||||||
|
FROM egw_cal_user
|
||||||
|
JOIN egw_cal_dates on egw_cal_dates.cal_id=egw_cal_user.cal_id and (cal_recur_date=0 or cal_recur_date=cal_start)
|
||||||
|
JOIN egw_cal ON egw_cal.cal_id=egw_cal_user.cal_id
|
||||||
|
WHERE cal_user_type="c" and cal_user_id=contact_id and cal_start > unix_timestamp(now())';
|
||||||
|
if ( !$GLOBALS['egw_info']['user']['preferences']['calendar']['show_rejected'])
|
||||||
|
{
|
||||||
|
$sql .= ' AND egw_cal_user.cal_status != "R"';
|
||||||
|
}
|
||||||
|
$sql .= 'order by cal_start DESC Limit 1
|
||||||
|
|
||||||
|
) as next_event
|
||||||
|
FROM egw_addressbook
|
||||||
|
WHERE CONCAT("c",contact_id) IN ('.implode(',', array_map(array($this->db, 'quote'), $uids)).')';
|
||||||
|
|
||||||
|
|
||||||
|
$contacts =& $this->db->query($sql, __LINE__, __FILE__);
|
||||||
|
|
||||||
|
if (!$contacts) return array();
|
||||||
|
|
||||||
//_debug_array($events);
|
//_debug_array($events);
|
||||||
$calendars = array();
|
$calendars = array();
|
||||||
foreach($events as $event)
|
foreach($contacts as $contact)
|
||||||
{
|
{
|
||||||
foreach($event['participants'] as $uid => $status)
|
if($contact['last_event'])
|
||||||
{
|
{
|
||||||
if ($status == 'R' && !$GLOBALS['egw_info']['user']['preferences']['calendar']['show_rejected'])
|
list($start, $cal_id, $title) = explode(':', $contact['last_event']);
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($event['start'] < $this->now_su) // past event --> check for last event
|
$link = array(
|
||||||
|
'id' => $cal_id,
|
||||||
|
'app' => 'calendar',
|
||||||
|
'title' => $bocal->link_title($cal_id),
|
||||||
|
'extra_args' => array(
|
||||||
|
'date' => date('Ymd',$start),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if ($extra_title)
|
||||||
{
|
{
|
||||||
if (!isset($calendars[$uid]['last_event']) || $event['start'] > $calendars[$uid]['last_event'])
|
$link['extra_title'] = $link['title'];
|
||||||
{
|
$link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$start);
|
||||||
$calendars[$uid]['last_event'] = $event['start'];
|
|
||||||
$link = array(
|
|
||||||
'id' => $event['id'],
|
|
||||||
'app' => 'calendar',
|
|
||||||
'title' => $bocal->link_title($event),
|
|
||||||
'extra_args' => array(
|
|
||||||
'date' => date('Ymd',$event['start']),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if ($extra_title)
|
|
||||||
{
|
|
||||||
$link['extra_title'] = $link['title'];
|
|
||||||
$link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$event['start']);
|
|
||||||
}
|
|
||||||
$calendars[$uid]['last_link'] = $link;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else // future event --> check for next event
|
$calendars['c'.$contact['contact_id']]['last_event'] = $start;
|
||||||
|
$calendars['c'.$contact['contact_id']]['last_link'] = $link;
|
||||||
|
}
|
||||||
|
if($contact['next_event'])
|
||||||
|
{
|
||||||
|
list($start, $cal_id, $title) = explode(':', $contact['next_event']);
|
||||||
|
|
||||||
|
$link = array(
|
||||||
|
'id' => $cal_id,
|
||||||
|
'app' => 'calendar',
|
||||||
|
'title' => $bocal->link_title($cal_id),
|
||||||
|
'extra_args' => array(
|
||||||
|
'date' => date('Ymd',$start),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if ($extra_title)
|
||||||
{
|
{
|
||||||
if (!isset($calendars[$uid]['next_event']) || $event['start'] < $calendars[$uid]['next_event'])
|
$link['extra_title'] = $link['title'];
|
||||||
{
|
$link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$start);
|
||||||
$calendars[$uid]['next_event'] = $event['start'];
|
|
||||||
$link = array(
|
|
||||||
'id' => $event['id'],
|
|
||||||
'app' => 'calendar',
|
|
||||||
'title' => $bocal->link_title($event),
|
|
||||||
'extra_args' => array(
|
|
||||||
'date' => date('Ymd',$event['start']),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if ($extra_title)
|
|
||||||
{
|
|
||||||
$link['extra_title'] = $link['title'];
|
|
||||||
$link['title'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],$event['start']);
|
|
||||||
}
|
|
||||||
$calendars[$uid]['next_link'] = $link;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$calendars['c'.$contact['contact_id']]['next_event'] = $start;
|
||||||
|
$calendars['c'.$contact['contact_id']]['next_link'] = $link;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $calendars;
|
return $calendars;
|
||||||
|
Loading…
Reference in New Issue
Block a user