/**
  * appends sql to given select statement
  *
  * @param  Zend_Db_Select                    $_select
  * @param  Tinebase_Backend_Sql_Abstract     $_backend
  */
 public function appendFilterSql($_select, $_backend)
 {
     if ($this->_value === 'all') {
         $_select->where('1=1');
         return;
     }
     $gs = new Tinebase_Backend_Sql_Filter_GroupSelect($_select);
     $adapter = $_backend->getAdapter();
     //if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . ' (' . __LINE__ . ') value: ' . print_r($this->_value, true));
     foreach ($this->_value as $attenderValue) {
         if (in_array($attenderValue['user_type'], array(Calendar_Model_Attender::USERTYPE_USER, Calendar_Model_Attender::USERTYPE_GROUPMEMBER))) {
             // @todo user_id might contain filter in the future -> get userids from adressbook controller with contact filter
             // transform CURRENTCONTACT
             $attenderValue['user_id'] = $attenderValue['user_id'] == Addressbook_Model_Contact::CURRENTCONTACT ? Tinebase_Core::getUser()->contact_id : $attenderValue['user_id'];
             $attendee = array(array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $attenderValue['user_id']), array('user_type' => Calendar_Model_Attender::USERTYPE_GROUPMEMBER, 'user_id' => $attenderValue['user_id']));
         } else {
             if ($attenderValue['user_type'] == self::USERTYPE_MEMBEROF) {
                 // resolve group members
                 $group = Tinebase_Group::getInstance()->getGroupById($attenderValue['user_id']);
                 $attendee = array();
                 // fetch list only if list_id is not NULL, otherwise we get back an empty list object
                 if (!empty($group->list_id)) {
                     $contactList = Addressbook_Controller_List::getInstance()->get($group->list_id);
                     foreach ($contactList->members as $member) {
                         $attendee[] = array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $member);
                         $attendee[] = array('user_type' => Calendar_Model_Attender::USERTYPE_GROUPMEMBER, 'user_id' => $member);
                     }
                 }
             } else {
                 $attendee = array($attenderValue);
             }
         }
         foreach ($attendee as $attender) {
             $gs->orWhere($adapter->quoteInto($adapter->quoteIdentifier('attendee.user_type') . ' = ?', $attender['user_type']) . ' AND ' . $adapter->quoteInto($adapter->quoteIdentifier('attendee.user_id') . ' = ?', $attender['user_id']));
         }
     }
     if (substr($this->_operator, 0, 3) === 'not') {
         // join attendee to be excluded as a new column. records having this column NULL don't have the attendee
         $dname = 'attendee-not-' . Tinebase_Record_Abstract::generateUID(5);
         $_select->joinLeft(array($dname => $_backend->getTablePrefix() . 'cal_attendee'), $adapter->quoteIdentifier($dname . '.cal_event_id') . ' = ' . $adapter->quoteIdentifier($_backend->getTableName() . '.id') . ' AND ' . $gs->getSQL(), array($dname => $_backend->getDbCommand()->getAggregate($dname . '.id')));
         $_select->having($_backend->getDbCommand()->getAggregate($dname . '.id') . ' IS NULL');
     } else {
         $gs->appendWhere(Zend_Db_Select::SQL_OR);
     }
 }