public function actionReload($params) { $event = empty($params['event_id']) ? false : \GO\Calendar\Model\Event::model()->findByPk($params['event_id']); $participantAttrs = json_decode($params['participants']); $store = new \GO\Base\Data\ArrayStore(); foreach ($participantAttrs as $participantAttr) { $participant = new \GO\Calendar\Model\Participant(); $participant->setAttributes($participantAttr); if ($event) { $participant->event_id = $event->id; } $store->addRecord($participant->toJsonArray($params['start_time'], $params['end_time'])); } return $store->getData(); }
private function _saveParticipants($params, \GO\Calendar\Model\Event $event, &$response) { $response['participants'] = array(); $ids = array(); if (!empty($params['participants'])) { //we don't need an organizer if there are no participants so default to true here. $hasOrganizer = true; $participants = json_decode($params['participants'], true); //don't save a single organizer participant if (count($participants) > 1) { $hasOrganizer = false; foreach ($participants as $p) { $participant = \GO\Calendar\Model\Participant::model()->findSingleByAttributes(array('email' => $p['email'], 'event_id' => $event->id)); if ($participant && !empty($p['contact_id']) && $p['contact_id'] != $participant->contact_id) { $participant->delete(); $participant = false; } if (!$participant) { $participant = new \GO\Calendar\Model\Participant(); //ask for meeting request because there's a new participant $response['askForMeetingRequest'] = true; } unset($p['id']); $participant->setAttributes($p); $participant->event_id = $event->id; if (!$participant->save()) { throw new \Exception("Could not save participant " . var_export($participant->getValidationErrors(), true)); } if (!$hasOrganizer) { $hasOrganizer = $participant->is_organizer; } $ids[] = $participant->id; $response['participants'][] = $participant->toJsonArray($event->start_time, $event->end_time); } } $stmt = \GO\Calendar\Model\Participant::model()->find(\GO\Base\Db\FindParams::newInstance()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addInCondition('id', $ids, 't', true, true)->addCondition('event_id', $event->id))); $stmt->callOnEach('delete'); if (!$hasOrganizer) { $organizer = $event->getDefaultOrganizerParticipant(); $existing = $event->participants(\GO\Base\Db\FindParams::newInstance()->single()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('email', $organizer->email))); if ($existing) { $existing->is_organizer = true; $existing->save(); } else { $organizer->save(); } } } if (empty($response['participants'])) { $organizer = $event->getDefaultOrganizerParticipant(); $response['participants'] = array($organizer->toJsonArray($event->start_time, $event->end_time)); } }