public function actionSetUserEventParticipation()
 {
     $objValidator = new helpers\Validation();
     $params = array('event', 'user_token', 'participation');
     try {
         $isRequestValid = $objValidator->validateRequest($params);
         if ($isRequestValid) {
             $userToken = $this->_request->getPost('user_token', null);
             $objUserMdl = new \models\Users();
             $eventId = $this->_request->getPost('event', null);
             $dataToInsert = array('events_id' => $eventId, 'participation_id' => $this->_request->getPost('participation', null));
             // check if user is valid or not
             $userDetails = $objUserMdl->getUserFromToken($userToken);
             if (!$userDetails) {
                 $this->_request->sendErrorResponse(403, 403, 'User token invalid');
             }
             $objUsersEventParticipation = new \models\UsersEventsParticipation();
             $dataToInsert['users_id'] = $userDetails->id;
             $isStatusSaved = $objUsersEventParticipation->insertUserEventParticipation($dataToInsert, $userDetails);
             if ($isStatusSaved) {
                 // send push notification
                 $objNotifier = new \models\Pushnotifications();
                 $objNotifier->participationNotifications($eventId, $userDetails);
                 $this->_request->sendSuccessResponse('Status Saved');
             } else {
                 $this->_request->sendErrorResponse(404, 404, 'Error saving status');
             }
         } else {
             $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated');
         }
     } catch (\Exception $e) {
         $this->_request->sendErrorResponse(404, 404, $e->getMessage());
     }
 }
 /**
  * Function to update event
  * **/
 public function actionEventUpdate()
 {
     $objValidator = new helpers\Validation();
     $params = array('user_token', 'eventid', 'updates');
     try {
         $isRequestValid = $objValidator->validateRequest($params);
         if ($isRequestValid) {
             $userToken = $this->_request->getPost('user_token', null);
             $eventId = $this->_request->getPost('eventid', null);
             $objUserAuthMdl = new \models\Users();
             $objEventsModel = new \models\Events();
             $userDetails = $objUserAuthMdl->getUserFromToken($userToken);
             if (!$userDetails) {
                 $this->_request->sendErrorResponse(403, 403, 'User token invalid');
             }
             //check if event exists or not
             $eventRow = $objEventsModel->findEventById($eventId);
             if (!$eventRow) {
                 $this->_request->sendErrorResponse(403, 403, 'Invalid Event');
             }
             // check if event is owned by user
             $isUserEventOwner = $eventRow->users_id == $userDetails->id ? true : false;
             if (!$isUserEventOwner) {
                 $this->_request->sendErrorResponse(403, 403, 'User is not authenticated to edit event');
             }
             $updates = $this->_request->getPost('updates', null);
             $updateArr = json_decode($updates, true);
             // check if update data is valid json or not
             if (!$updateArr) {
                 $this->_request->sendErrorResponse(403, 403, 'Invalid update data');
             }
             $isEventUpdated = $objEventsModel->updateEvent($eventRow, $updateArr);
             if ($isEventUpdated) {
                 // send push notification
                 $objNotifier = new \models\Pushnotifications();
                 $objNotifier->participationNotifications($eventRow, $userDetails);
                 $this->_request->sendSuccessResponse('Event Successfully updated');
             } else {
                 $this->_request->sendErrorResponse(404, 404, 'Error updating event');
             }
         } else {
             $this->_request->sendErrorResponse(403, 403, 'Request cannot be validated');
         }
     } catch (\Exception $e) {
         $this->_request->sendErrorResponse(404, 404, $e->getMessage());
     }
 }