function write_new_or_update_attendees($dav_id, $attendees, $add_new = true) { // no remove all of attendee because we lost status about send invitation email // and will be send new invitation //$qry = new AwlQuery('DELETE FROM calendar_attendee WHERE dav_id = '.$dav_id ); //$qry->Exec('PUT',__LINE__,__FILE__); if (count($attendees) < 1) { return; } // create query for insert or update $sql = $add_new ? 'INSERT INTO calendar_attendee ( dav_id, status, partstat, cn, attendee, role, rsvp, params, is_remote, email_status ) VALUES( ' . $dav_id . ', :status, :partstat, :cn, :attendee, :role, :rsvp, :params, :is_remote, :email_status )' : 'UPDATE calendar_attendee SET status = :status, partstat = :partstat, cn = :cn,' . 'role=:role, rsvp=:rsvp, params=:params, is_remote=:is_remote, email_status=:email_status' . ' WHERE dav_id = ' . $dav_id . ' AND attendee=:attendee'; $qry = new AwlQuery($sql); $qry->Prepare(); $processed = array(); foreach ($attendees as $v) { $attendee = $v->Value(); $is_remote = isset($v->is_remote) && $v->is_remote; // for remote attendee set status 2 - Waiting for email // for normal attendee set status 1 - accepted $email_status = EMAIL_STATUS::NORMAL; if ($add_new === false && $is_remote) { // attendee is not new and remote // sent email about changed apointment $email_status = EMAIL_STATUS::WAITING_FOR_SCHEDULE_CHANGE_EMAIL; // wait for schedule changed sending } else { if ($is_remote) { // is_remote and new attendee -> send invitation email $email_status = EMAIL_STATUS::WAITING_FOR_INVITATION_EMAIL; // wait for invitation sending } } if (isset($processed[$attendee])) { dbg_error_log('LOG', 'Duplicate attendee "%s" in resource "%d"', $attendee, $dav_id); dbg_error_log('LOG', 'Original: "%s"', $processed[$attendee]); dbg_error_log('LOG', 'Duplicate: "%s"', $v->Render()); continue; /** @todo work out why we get duplicate ATTENDEE on one VEVENT */ } $params = ''; foreach ($v->Parameters() as $key => $param) { if (!empty($params)) { $params .= ';'; } $params .= $key . '=' . $param; } $qry->Bind(':attendee', $attendee); $qry->Bind(':status', $v->GetParameterValue('STATUS')); $qry->Bind(':partstat', $v->GetParameterValue('PARTSTAT')); $qry->Bind(':cn', $v->GetParameterValue('CN')); $qry->Bind(':role', $v->GetParameterValue('ROLE')); $qry->Bind(':rsvp', $v->GetParameterValue('RSVP')); $qry->Bind(':is_remote', $is_remote); $qry->Bind(':params', $params); $qry->Bind(':email_status', $email_status); $qry->Exec('PUT', __LINE__, __FILE__); $processed[$attendee] = $v->Render(); } }
/** * Parse out the attendee property and write a row to the * calendar_attendee table for each one. * @param int $dav_id The dav_id of the caldav_data we're processing * @param iCalComponent The VEVENT or VTODO containing the ATTENDEEs * @return null */ function write_attendees($dav_id, $ical) { $qry = new AwlQuery('DELETE FROM calendar_attendee WHERE dav_id = ' . $dav_id); $qry->Exec('PUT', __LINE__, __FILE__); $attendees = $ical->GetProperties('ATTENDEE'); if (count($attendees) < 1) { return; } $qry->SetSql('INSERT INTO calendar_attendee ( dav_id, status, partstat, cn, attendee, role, rsvp, property ) VALUES( ' . $dav_id . ', :status, :partstat, :cn, :attendee, :role, :rsvp, :property )'); $qry->Prepare(); $processed = array(); foreach ($attendees as $v) { $attendee = $v->Value(); if (isset($processed[$attendee])) { dbg_error_log('LOG', 'Duplicate attendee "%s" in resource "%d"', $attendee, $dav_id); dbg_error_log('LOG', 'Original: "%s"', $processed[$attendee]); dbg_error_log('LOG', 'Duplicate: "%s"', $v->Render()); continue; /** @TODO: work out why we get duplicate ATTENDEE on one VEVENT */ } $qry->Bind(':attendee', $attendee); $qry->Bind(':status', $v->GetParameterValue('STATUS')); $qry->Bind(':partstat', $v->GetParameterValue('PARTSTAT')); $qry->Bind(':cn', $v->GetParameterValue('CN')); $qry->Bind(':role', $v->GetParameterValue('ROLE')); $qry->Bind(':rsvp', $v->GetParameterValue('RSVP')); $qry->Bind(':property', $v->Render()); $qry->Exec('PUT', __LINE__, __FILE__); $processed[$attendee] = $v->Render(); } }