Beispiel #1
0
 public function activity(OW_Event $activityEvent)
 {
     $params = $activityEvent->getParams();
     $data = $activityEvent->getData();
     $data = empty($data) ? array() : $data;
     $this->validateParams($params, array('activityType', 'activityId', 'entityType', 'entityId', 'userId', 'pluginKey'), array('activityType', 'activityId', 'actionId', 'userId', 'pluginKey'));
     $activityKey = "{$params['activityType']}.{$params['activityId']}:{$params['entityType']}.{$params['entityId']}:{$params['userId']}";
     if (!$this->testActivity($activityKey)) {
         return;
     }
     $actionId = empty($params['actionId']) ? null : $params['actionId'];
     $onEvent = new OW_Event('feed.on_activity', $activityEvent->getParams(), array('data' => $data));
     OW::getEventManager()->trigger($onEvent);
     $onData = $onEvent->getData();
     $data = $onData['data'];
     if (!empty($onData['params']) && is_array($onData['params'])) {
         $params = array_merge($params, $onData['params']);
     }
     if (!in_array($params['activityType'], NEWSFEED_BOL_Service::getInstance()->SYSTEM_ACTIVITIES) && empty($data['string'])) {
         return;
     }
     if (empty($actionId)) {
         $actionDto = $this->service->findAction($params['entityType'], $params['entityId']);
         if ($actionDto === null) {
             $actionEvent = new OW_Event('feed.action', array('pluginKey' => $params['pluginKey'], 'userId' => $params['userId'], 'entityType' => $params['entityType'], 'entityId' => $params['entityId']), array('data' => $data));
             $this->action($actionEvent);
             $actionDto = $this->service->findAction($params['entityType'], $params['entityId']);
         }
         if ($actionDto === null) {
             return;
         }
         $actionId = (int) $actionDto->id;
     }
     $activity = $this->service->findActivityItem($params['activityType'], $params['activityId'], $actionId);
     if ($activity === null) {
         $privacy = empty($params['privacy']) ? NEWSFEED_BOL_Service::PRIVACY_EVERYBODY : $params['privacy'];
         $activity = new NEWSFEED_BOL_Activity();
         $activity->activityType = $params['activityType'];
         $activity->activityId = $params['activityId'];
         $activity->actionId = $actionId;
         $activity->privacy = $privacy;
         $activity->userId = $params['userId'];
         $activity->visibility = empty($params['visibility']) ? NEWSFEED_BOL_Service::VISIBILITY_FULL : $params['visibility'];
         $activity->timeStamp = empty($params['time']) ? time() : $params['time'];
         $activity->data = json_encode($data);
     } else {
         $activity->privacy = empty($params['privacy']) ? $activity->privacy : $params['privacy'];
         $activity->timeStamp = empty($params['time']) ? $activity->timeStamp : $params['time'];
         $activity->visibility = empty($params['visibility']) ? $activity->visibility : $params['visibility'];
         $_data = array_merge(json_decode($activity->data, true), $data);
         $activity->data = json_encode($_data);
     }
     $this->service->saveActivity($activity);
     if (isset($params['subscribe']) && $params['subscribe']) {
         $subscribe = new NEWSFEED_BOL_Activity();
         $subscribe->actionId = $actionId;
         $subscribe->userId = $params['userId'];
         $subscribe->visibility = NEWSFEED_BOL_Service::VISIBILITY_FULL;
         $subscribe->privacy = NEWSFEED_BOL_Service::PRIVACY_EVERYBODY;
         $subscribe->timeStamp = empty($params['time']) ? time() : $params['time'];
         $subscribe->activityType = NEWSFEED_BOL_Service::SYSTEM_ACTIVITY_SUBSCRIBE;
         $subscribe->activityId = $params['userId'];
         $subscribe->data = json_encode(array());
         $this->service->saveActivity($subscribe);
     }
     if (isset($params['subscribe']) && !$params['subscribe']) {
         $this->service->removeActivity("subscribe.{$params['userId']}:{$actionId}");
     }
     if (!isset($params['postOnUserFeed']) || $params['postOnUserFeed']) {
         $this->service->addActivityToFeed($activity, 'user', $activity->userId);
     }
     if (isset($params['postOnUserFeed']) && !$params['postOnUserFeed']) {
         $this->service->deleteActivityFromFeed($activity->id, 'user', $activity->userId);
     }
     if (!empty($params['feedType']) && !empty($params['feedId'])) {
         $this->service->addActivityToFeed($activity, $params['feedType'], $params['feedId']);
     }
     $params = $activityEvent->getParams();
     $params['actionId'] = $actionId;
     $onEvent = new OW_Event('feed.after_activity', $params, array('data' => $data));
     OW::getEventManager()->trigger($onEvent);
 }