/** * Returns the rest resource of the stream regarding a stream a context-id and the parameters * stream-time, limit and offset (all in $this). * * @param BlubberStream $stream : the stream * @param $parameter : an array of context-parameter i.e. array('user_id' => $user_id) * * @return Array('collection' => array(...), 'pagination' => array()) */ private function getStreamBlubberRestResource($stream, $parameter) { $total = $stream->fetchNumberOfThreads(); $threads = $stream->fetchThreads((int) $this->offset, (int) $this->limit ?: null, $this->stream_time ?: null); $json = array(); foreach ($threads as $thread) { $url = $this->urlf('/blubber/posting/%s', array($thread->getId())); $json[$url] = $this->blubberPostingtoJSON($thread); } $this->etag(md5(serialize($json))); return $this->paginated($json, $total, $parameter); }
/** * Displays more postings in the same stream (global, forum oder profile-stream). * This action is used by infinity-scroll and displays a maximum of * $this->max_threads threads. * @throws AccessDeniedException */ public function more_postings_action() { $context_id = Request::option("context_id"); switch (Request::get("stream")) { case "global": $stream = BlubberStream::getGlobalStream(); break; case "course": $stream = BlubberStream::getCourseStream($context_id); break; case "profile": $stream = BlubberStream::getProfileStream($context_id); break; case "custom": $stream = new BlubberStream($context_id); break; } $output = array(); $offset = $this->max_threads * Request::int("offset"); $limit = $this->max_threads + 1; $stream_time = Request::int("stream_time"); $threads = $stream->fetchThreads($offset, $limit, $stream_time); $output['more'] = count($threads) > $this->max_threads; if ($output['more']) { $threads = array_slice($threads, 0, $this->max_threads); } $output['threads'] = array(); $factory = new Flexi_TemplateFactory($this->plugin->getPluginPath() . "/views"); foreach ($threads as $posting) { $template = $factory->open("streams/_blubber.php"); $template->set_attribute('thread', $posting); $template->set_attribute('course_id', $_SESSION['SessionSeminar']); $template->set_attribute('controller', $this); $output['threads'][] = array('content' => $template->render(), 'discussion_time' => $posting['discussion_time'], 'mkdate' => $posting['mkdate'], 'posting_id' => $posting->getId()); } $this->render_json($output); }