getAcl()->check('Calendar')) { throw new Forbidden(); } $from = $request->get('from'); $to = $request->get('to'); if (empty($from) || empty($to)) { throw new BadRequest(); } if (strtotime($to) - strtotime($from) > $this->maxCalendarRange * 24 * 3600) { throw new Forbidden('Too long range.'); } $service = $this->getService('Activities'); $scopeList = null; if ($request->get('scopeList') !== null) { $scopeList = explode(',', $request->get('scopeList')); } $userId = $request->get('userId'); $userIdList = $request->get('userIdList'); $teamIdList = $request->get('teamIdList'); if ($teamIdList) { $teamIdList = explode(',', $teamIdList); return $userResultList = $service->getTeamsEventList($teamIdList, $from, $to, $scopeList); } if ($userIdList) { $userIdList = explode(',', $userIdList); return $service->getUsersEventList($userIdList, $from, $to, $scopeList); } else { if (!$userId) { $userId = $this->getUser()->id; } } return $service->getEventList($userId, $from, $to, $scopeList); } public function getActionGetTimeline($params, $data, $request) { if (!$this->getAcl()->check('Calendar')) { throw new Forbidden(); } $from = $request->get('from'); $to = $request->get('to'); if (empty($from) || empty($to)) { throw new BadRequest(); } if (strtotime($to) - strtotime($from) > $this->maxCalendarRange * 24 * 3600) { throw new Forbidden('Too long range.'); } $service = $this->getService('Activities'); $scopeList = null; if ($request->get('scopeList') !== null) { $scopeList = explode(',', $request->get('scopeList')); } $userId = $request->get('userId'); $userIdList = $request->get('userIdList'); if ($userIdList) { $userIdList = explode(',', $userIdList); } else { $userIdList = []; } if ($userId) { $userIdList[] = $userId; } return $service->getUsersTimeline($userIdList, $from, $to, $scopeList); } public function actionListUpcoming($params, $data, $request) { $service = $this->getService('Activities'); $userId = $request->get('userId'); if (!$userId) { $userId = $this->getUser()->id; } $offset = intval($request->get('offset')); $maxSize = intval($request->get('maxSize')); $entityTypeList = $request->get('entityTypeList'); $futureDays = intval($request->get('futureDays')); $maxSizeLimit = $this->getConfig()->get('recordListMaxSizeLimit', self::MAX_SIZE_LIMIT); if (empty($maxSize)) { $maxSize = $maxSizeLimit; } if (!empty($maxSize) && $maxSize > $maxSizeLimit) { throw new Forbidden("Max should should not exceed " . $maxSizeLimit . ". Use offset and limit."); } return $service->getUpcomingActivities($userId, array( 'offset' => $offset, 'maxSize' => $maxSize ), $entityTypeList, $futureDays); } public function actionPopupNotifications() { $userId = $this->getUser()->id; return $this->getService('Activities')->getPopupNotifications($userId); } public function actionRemovePopupNotification($params, $data, $request) { if (!$request->isPost()) { throw new BadRequest(); } if (empty($data->id)) { throw new BadRequest(); } $id = $data->id; return $this->getService('Activities')->removeReminder($id); } public function actionList($params, $data, $request) { if (!$this->getAcl()->check('Activities')) { throw new Forbidden(); } $name = $params['name']; if (!in_array($name, ['activities', 'history'])) { throw new BadRequest(); } if (empty($params['scope'])) { throw new BadRequest(); } if (empty($params['id'])) { throw new BadRequest(); } $entityType = $params['scope']; $id = $params['id']; $offset = intval($request->get('offset')); $maxSize = intval($request->get('maxSize')); $order = $request->get('order'); $orderBy = $request->get('orderBy'); $where = $request->get('where'); $maxSizeLimit = $this->getConfig()->get('recordListMaxSizeLimit', self::MAX_SIZE_LIMIT); if (empty($maxSize)) { $maxSize = $maxSizeLimit; } if (!empty($maxSize) && $maxSize > $maxSizeLimit) { throw new Forbidden("Max should should not exceed " . $maxSizeLimit . ". Use offset and limit."); } $scope = null; if (is_array($where) && !empty($where[0]) && $where[0] !== 'false') { $scope = $where[0]; } $service = $this->getService('Activities'); $methodName = 'get' . ucfirst($name); return $service->$methodName($entityType, $id, [ 'scope' => $scope, 'offset' => $offset, 'maxSize' => $maxSize, 'order' => $order, 'orderBy' => $orderBy, ]); } public function getActionEntityTypeList($params, $data, $request) { if (empty($params['scope'])) throw new BadRequest(); if (empty($params['id'])) throw new BadRequest(); if (empty($params['name'])) throw new BadRequest(); if (empty($params['entityType'])) throw new BadRequest(); $scope = $params['scope']; $id = $params['id']; $name = $params['name']; $entityType = $params['entityType']; if ($name === 'activities') { $isHistory = false; } else if ($name === 'history') { $isHistory = true; } else { throw new BadRequest(); } $params = []; \Espo\Core\Utils\ControllerUtil::fetchListParamsFromRequest($params, $request, $data); $maxSizeLimit = $this->getConfig()->get('recordListMaxSizeLimit', 200); if (empty($params['maxSize'])) { $params['maxSize'] = $maxSizeLimit; } if (!empty($params['maxSize']) && $params['maxSize'] > $maxSizeLimit) { throw new Forbidden("Max size should should not exceed " . $maxSizeLimit . ". Use offset and limit."); } $service = $this->getService('Activities'); $result = $service->findActivitiyEntityType($scope, $id, $entityType, $isHistory, $params); return (object) [ 'total' => $result->total, 'list' => $result->collection->getValueMapList() ]; } }