From da950325050567d948353273b3107441764ed061 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sat, 9 Apr 2011 14:41:15 +0000 Subject: [PATCH] fixed some problems with r34529: move all filtering into SQL query - group-calendar empty - owner-too filter fixed - events with multiple users with differnt status and group invitation fixed --- calendar/inc/class.calendar_bo.inc.php | 5 ++++- calendar/inc/class.calendar_so.inc.php | 17 +++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/calendar/inc/class.calendar_bo.inc.php b/calendar/inc/class.calendar_bo.inc.php index cc129ad892..3ec1fe1033 100644 --- a/calendar/inc/class.calendar_bo.inc.php +++ b/calendar/inc/class.calendar_bo.inc.php @@ -448,7 +448,10 @@ class calendar_bo $offset = isset($params['offset']) && $params['offset'] !== false ? (int) $params['offset'] : false; // socal::search() returns rejected group-invitations, as only the user not also the group is rejected // as we cant remove them efficiantly in SQL, we kick them out here, but only if just one user is displayed - $remove_rejected_by_user = !in_array($filter,array('all','rejected','owner')) && count($params['users']) == 1 ? $params['users'][0] : null; + $users_in = (array)$params_in['users']; + $remove_rejected_by_user = !in_array($filter,array('all','rejected')) && + count($users_in) == 1 && $users_in[0] > 0 ? $users_in[0] : null; + //error_log(__METHOD__.'('.array2string($params_in).", $sql_filter) params[users]=".array2string($params['users']).' --> remove_rejected_by_user='.array2string($remove_rejected_by_user)); if ($this->debug && ($this->debug > 1 || $this->debug == 'search')) { diff --git a/calendar/inc/class.calendar_so.inc.php b/calendar/inc/class.calendar_so.inc.php index 30429ebf0f..79c362030f 100644 --- a/calendar/inc/class.calendar_so.inc.php +++ b/calendar/inc/class.calendar_so.inc.php @@ -520,14 +520,19 @@ class calendar_so if ($remove_rejected_by_user) { - $rejected_by_user_join = "JOIN $this->user_table rejected_by_user". + $rejected_by_user_join = "LEFT JOIN $this->user_table rejected_by_user". " ON $this->cal_table.cal_id=rejected_by_user.cal_id". " AND rejected_by_user.cal_user_type='u'". " AND rejected_by_user.cal_user_id=".$this->db->quote($remove_rejected_by_user). - " AND rejected_by_user.cal_status!='R'"; - $where[] = "(recur_type IS NULL AND rejected_by_user.cal_recur_date=0 OR cal_start=rejected_by_user.cal_recur_date)"; + " AND (recur_type IS NULL AND rejected_by_user.cal_recur_date=0 OR cal_start=rejected_by_user.cal_recur_date)"; + $or_required = array( + 'rejected_by_user.cal_status IS NULL', + "rejected_by_user.cal_status!='R'", + ); + if ($filter == 'owner') $or_required[] = 'cal_owner='.(int)$remove_rejected_by_user; + $where[] = '('.implode(' OR ',$or_required).')'; } -//$starttime = microtime(true); + //$starttime = microtime(true); if ($useUnionQuery) { // allow apps to supply participants and/or icons @@ -536,7 +541,7 @@ class calendar_so // changed the original OR in the query into a union, to speed up the query execution under MySQL 5 $select = array( 'table' => $this->cal_table, - 'join' => "JOIN $this->dates_table ON $this->cal_table.cal_id=$this->dates_table.cal_id JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id $rejected_by_user_join LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id", + 'join' => "JOIN $this->dates_table ON $this->cal_table.cal_id=$this->dates_table.cal_id JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id $rejected_by_user_join", 'cols' => $cols, 'where' => $where, 'app' => 'calendar', @@ -623,7 +628,7 @@ class calendar_so $where,__LINE__,__FILE__,$offset,$params['append'].' ORDER BY '.$params['order'],'calendar',$num_rows, "JOIN $this->dates_table ON $this->cal_table.cal_id=$this->dates_table.cal_id JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id $rejected_by_user_join LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id"); } -//error_log(__METHOD__."() useUnionQuery=$useUnionQuery --> query took ".(microtime(true)-$starttime)); + //error_log(__METHOD__."() useUnionQuery=$useUnionQuery --> query took ".(microtime(true)-$starttime)); if (isset($params['cols'])) { return $rs; // if colums are specified we return the recordset / iterator