Ejemplo n.º 1
0
 /**
  * Responder for event attend form
  */
 public function attendFormResponder()
 {
     if (!OW::getRequest()->isAjax() || !OW::getUser()->isAuthenticated()) {
         throw new Redirect404Exception();
     }
     $userId = OW::getUser()->getId();
     $respondArray = array('messageType' => 'error');
     if (!empty($_POST['attend_status']) && in_array((int) $_POST['attend_status'], array(1, 2, 3)) && !empty($_POST['eventId']) && $this->eventService->canUserView($_POST['eventId'], $userId)) {
         $event = $this->eventService->findEvent($_POST['eventId']);
         if ($event->getEndTimeStamp() < time()) {
             throw new Redirect404Exception();
         }
         $eventUser = $this->eventService->findEventUser($_POST['eventId'], $userId);
         if ($eventUser !== null && (int) $eventUser->getStatus() === (int) $_POST['attend_status']) {
             $respondArray['message'] = OW::getLanguage()->text('event', 'user_status_not_changed_error');
             exit(json_encode($respondArray));
         }
         if ($event->getUserId() == OW::getUser()->getId() && (int) $_POST['attend_status'] == EVENT_BOL_EventService::USER_STATUS_NO) {
             $respondArray['message'] = OW::getLanguage()->text('event', 'user_status_author_cant_leave_error');
             exit(json_encode($respondArray));
         }
         if ($eventUser === null) {
             $eventUser = new EVENT_BOL_EventUser();
             $eventUser->setUserId($userId);
             $eventUser->setEventId((int) $_POST['eventId']);
         }
         $eventUser->setStatus((int) $_POST['attend_status']);
         $eventUser->setTimeStamp(time());
         $this->eventService->saveEventUser($eventUser);
         $this->eventService->deleteUserEventInvites((int) $_POST['eventId'], OW::getUser()->getId());
         $e = new OW_Event(EVENT_BOL_EventService::EVENT_ON_CHANGE_USER_STATUS, array('eventId' => $event->id, 'userId' => $eventUser->userId));
         OW::getEventManager()->trigger($e);
         $respondArray['message'] = OW::getLanguage()->text('event', 'user_status_updated');
         $respondArray['messageType'] = 'info';
         $respondArray['currentLabel'] = OW::getLanguage()->text('event', 'user_status_label_' . $eventUser->getStatus());
         $respondArray['eventId'] = (int) $_POST['eventId'];
         //$eventUsersCmp = new EVENT_CMP_EventUsers((int) $_POST['eventId']);
         //$respondArray['eventUsersCmp'] = $eventUsersCmp->render();
         $respondArray['newInvCount'] = $this->eventService->findUserInvitedEventsCount(OW::getUser()->getId());
         if ($eventUser->getStatus() == EVENT_BOL_EventService::USER_STATUS_YES && $event->getWhoCanView() == EVENT_BOL_EventService::CAN_VIEW_ANYBODY) {
             //                $params = array(
             //                    'pluginKey' => 'event',
             //                    'entityType' => 'event_join',
             //                    'entityId' => $eventUser->getUserId(),
             //                    'userId' => $eventUser->getUserId()
             //                );
             //
             //                $url = OW::getRouter()->urlForRoute('event.view', array('eventId' => $event->getId()));
             //                $thumb = $this->eventService->generateImageUrl($event->getId(), true);
             //
             //
             //
             //                $dataValue = array(
             //                    'time' => $eventUser->getTimeStamp(),
             //                    'string' => OW::getLanguage()->text('event', 'feed_user_join_string'),
             //                    'content' => '<div class="clearfix"><div class="ow_newsfeed_item_picture">
             //                        <a href="' . $url . '"><img src="' . $thumb . '" /></a>
             //                        </div><div class="ow_newsfeed_item_content">
             //                        <a class="ow_newsfeed_item_title" href="' . $url . '">' . $event->getTitle() . '</a><div class="ow_remark">' . strip_tags($event->getDescription()) . '</div></div></div>',
             //                    'view' => array(
             //                        'iconClass' => 'ow_ic_calendar'
             //                    )
             //                );
             //
             //                $fEvent = new OW_Event('feed.action', $params, $dataValue);
             //                OW::getEventManager()->trigger($fEvent);
             $userName = BOL_UserService::getInstance()->getDisplayName($event->getUserId());
             $userUrl = BOL_UserService::getInstance()->getUserUrl($event->getUserId());
             $userEmbed = '<a href="' . $userUrl . '">' . $userName . '</a>';
             OW::getEventManager()->trigger(new OW_Event('feed.activity', array('activityType' => 'event-join', 'activityId' => $eventUser->getId(), 'entityId' => $event->getId(), 'entityType' => 'event', 'userId' => $eventUser->getUserId(), 'pluginKey' => 'event'), array('eventId' => $event->getId(), 'userId' => $eventUser->getUserId(), 'eventUserId' => $eventUser->getId(), 'string' => OW::getLanguage()->text('event', 'feed_actiovity_attend_string', array('user' => $userEmbed)), 'feature' => array())));
         }
     } else {
         $respondArray['message'] = OW::getLanguage()->text('event', 'user_status_update_error');
     }
     exit(json_encode($respondArray));
 }