/** * @NoAdminRequired * * @param int $page * @param string $filter * @param string $objecttype * @param int $objectid * @return JSONResponse */ public function fetch($page, $filter = 'all', $objecttype = '', $objectid = 0) { $pageOffset = $page - 1; $filter = $this->data->validateFilter($filter); $activities = $this->data->read($this->helper, $this->settings, $pageOffset * self::DEFAULT_PAGE_SIZE, self::DEFAULT_PAGE_SIZE, $filter, '', $objecttype, $objectid); $preparedActivities = []; foreach ($activities as $activity) { if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) { // We do not link the subject as we create links for the parameters instead $activity['link'] = ''; } $activity['previews'] = []; if ($activity['object_type'] === 'files' && !empty($activity['files'])) { foreach ($activity['files'] as $objectId => $objectName) { if ((int) $objectId === 0 || $objectName === '') { // No file, no preview continue; } $activity['previews'][] = $this->getPreview($activity['affecteduser'], (int) $objectId, $objectName); if (sizeof($activity['previews']) >= self::MAX_NUM_THUMBNAILS) { // Don't want to clutter the page, so we stop after a few thumbnails break; } } } else { if ($activity['object_type'] === 'files' && $activity['object_id']) { $activity['previews'][] = $this->getPreview($activity['affecteduser'], (int) $activity['object_id'], $activity['file']); } } $preparedActivities[] = $activity; } return new JSONResponse($preparedActivities); }
/** * @param array $parameters * @throws InvalidFilterException when the filter is invalid * @throws \OutOfBoundsException when no user is given */ protected function readParameters(array $parameters) { $this->filter = isset($parameters['filter']) && is_string($parameters['filter']) ? (string) $parameters['filter'] : 'all'; if ($this->filter !== $this->data->validateFilter($this->filter)) { throw new InvalidFilterException(); } $this->since = (int) $this->request->getParam('since', 0); $this->limit = (int) $this->request->getParam('limit', 50); $this->loadPreviews = $this->request->getParam('previews', 'false') === 'true'; $this->objectType = (string) $this->request->getParam('object_type', ''); $this->objectId = (int) $this->request->getParam('object_id', 0); $this->sort = (string) $this->request->getParam('sort', ''); $this->sort = in_array($this->sort, ['asc', 'desc']) ? $this->sort : 'desc'; if ($this->objectType !== '' && $this->objectId === 0 || $this->objectType === '' && $this->objectId !== 0) { // Only allowed together $this->objectType = ''; $this->objectId = 0; } $user = $this->userSession->getUser(); if ($user instanceof IUser) { $this->user = $user->getUID(); } else { // No user logged in throw new \OutOfBoundsException(); } }
/** * @dataProvider validateFilterData * * @param string $filter * @param string $expected */ public function testValidateFilter($filter, $expected) { $this->assertEquals($expected, $this->data->validateFilter($filter)); }
/** * @NoAdminRequired * * @param int $page * @param string $filter * @return TemplateResponse */ public function fetch($page, $filter = 'all') { $pageOffset = $page - 1; $filter = $this->data->validateFilter($filter); return new TemplateResponse('activity', 'activities.part', ['activity' => $this->data->read($this->helper, $this->settings, $pageOffset * self::DEFAULT_PAGE_SIZE, self::DEFAULT_PAGE_SIZE, $filter)], ''); }
/** * @NoAdminRequired * @NoCSRFRequired * * @param string $filter * @return TemplateResponse */ public function showList($filter = 'all') { $filter = $this->data->validateFilter($filter); return new TemplateResponse('activity', 'stream.body', ['appNavigation' => $this->navigation->getTemplate($filter), 'avatars' => $this->config->getSystemValue('enable_avatars', true) ? 'yes' : 'no', 'filter' => $filter]); }
/** * @NoAdminRequired * * @param int $page * @param string $filter * @return TemplateResponse */ public function fetch($page, $filter = 'all') { $pageOffset = $page - 1; $filter = $this->data->validateFilter($filter); return new TemplateResponse('activity', 'stream.list', ['activity' => $this->data->read($this->helper, $this->settings, $pageOffset * self::DEFAULT_PAGE_SIZE, self::DEFAULT_PAGE_SIZE, $filter), 'displayHelper' => $this->display, 'dateTimeFormatter' => $this->dateTimeFormatter], ''); }
/** * @NoAdminRequired * @NoCSRFRequired * * @param string $filter * @return TemplateResponse */ public function showList($filter = 'all') { $filter = $this->data->validateFilter($filter); return new TemplateResponse('activity', 'stream.body', ['appNavigation' => $this->navigation->getTemplate($filter), 'filter' => $filter]); }