/** * Display content for dashboard * * @param object $course \Components\Courses\Models\Course * @param object $offering \Components\Courses\Models\Offering * @return string */ public function onCourseDashboard($course, $offering) { // Incoming $filters = array('authorized' => 1, 'scope' => 'course', 'scope_id' => $offering->get('id'), 'scope_sub_id' => $offering->section()->get('id'), 'search' => Request::getVar('search', ''), 'section_id' => 0, 'state' => Section::STATE_PUBLISHED, 'limit' => Request::getInt('limit', 500), 'start' => Request::getInt('limitstart', 0)); $post = Post::blank(); $post->set('scope', $filters['scope']); $post->set('scope_id', $filters['scope_id']); $post->set('scope_sub_id', $filters['scope_sub_id']); $sects = Section::all()->whereEquals('scope', $filters['scope'])->whereEquals('scope_id', $filters['scope_id'])->whereEquals('state', Section::STATE_PUBLISHED)->ordered()->rows(); $stats = new stdClass(); $stats->categories = 0; $stats->threads = 0; $stats->posts = 0; $sections = array(); foreach ($sects as $section) { $categories = $section->categories()->whereEquals('state', $filters['state'])->limit($filters['limit'])->rows(); $section->set('threads', 0); $section->set('categories', $categories); $stats->categories += $categories->count(); if ($categories->count()) { foreach ($categories as $category) { $threads = $category->threads()->whereEquals('scope_sub_id', $filters['scope_sub_id'])->whereEquals('state', $filters['state'])->total(); $posts = $category->posts()->whereEquals('scope_sub_id', $filters['scope_sub_id'])->whereEquals('state', $filters['state'])->total(); $section->set('threads', $section->get('threads') + $threads); $category->set('threads', $threads); $category->set('posts', $posts); $stats->threads += $threads; $stats->posts += $posts; } } $sections[] = $section; } $view = $this->view('dashboard', 'threads')->set('option', 'com_courses')->set('name', 'courses')->set('course', $course)->set('offering', $offering)->set('config', $course->config())->set('sections', $sections)->set('no_html', Request::getInt('no_html', 0))->set('thread', Request::getInt('thread', 0))->set('filters', $filters)->set('stats', $stats)->set('data', null)->setErrors($this->getErrors()); return $view->loadTemplate(); }
/** * Static method for formatting results * * @param object $row Database row * @return string HTML */ public static function out($row) { include_once Component::path('com_forum') . DS . 'models' . DS . 'post.php'; $row->scope = $row->rcount; $row->scope_id = $row->data3; $row->section = $row->data2; $row->category = $row->data1; $p = explode(':', $row->params); $row->thread = $p[0]; $row->parent = $p[1]; $row->comment = $row->ftext; $view = new \Hubzero\Plugin\View(array('folder' => 'tags', 'element' => 'forum', 'name' => 'result')); $view->post = \Components\Forum\Models\Post::blank()->set(array('id' => $row->id, 'title' => $row->title, 'alias' => $row->alias, 'comment' => $row->comment, 'state' => $row->state, 'created' => $row->created, 'created_by' => $row->created_by, 'scope' => $row->rcount, 'scope_id' => $row->data3, 'thread' => $row->thread, 'parent' => $row->parent, 'section' => $row->data2, 'category' => $row->data1)); return $view->loadTemplate(); }
/** * Create a thread or post in a thread * * @apiMethod POST * @apiUri /forum * @apiParameter { * "name": "category_id", * "description": "Category ID", * "type": "integer", * "required": true, * "default": 0 * } * @apiParameter { * "name": "scope", * "description": "Scope type (site, group, etc.)", * "type": "string", * "required": true, * "default": "site" * } * @apiParameter { * "name": "scope_id", * "description": "Scope object ID", * "type": "integer", * "required": true, * "default": "0" * } * @apiParameter { * "name": "title", * "description": "Entry title", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "comment", * "description": "Entry content", * "type": "string", * "required": true, * "default": null * } * @apiParameter { * "name": "created", * "description": "Created timestamp (YYYY-MM-DD HH:mm:ss)", * "type": "string", * "required": false, * "default": "now" * } * @apiParameter { * "name": "created_by", * "description": "User ID of entry creator", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "state", * "description": "Published state (0 = unpublished, 1 = published)", * "type": "integer", * "required": false, * "default": 1 * } * @apiParameter { * "name": "access", * "description": "Access level (1 = public, 2 = registered users, 5 = private)", * "type": "integer", * "required": false, * "default": 1 * } * @apiParameter { * "name": "anonymous", * "description": "Commentor is anonymous?", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "parent", * "description": "ID of the parent post this post is in reply to.", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "thread", * "description": "ID of the forum thread the post belongs to. 0 if new thread.", * "type": "string", * "required": false, * "default": 0 * } * @apiParameter { * "name": "sticky", * "description": "If the thread is sticky or not. Only applies to thread starter posts.", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "closed", * "description": "If the thread is closed (no more new posts) or not. Only applies to thread starter posts.", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "tags", * "description": "Comma-separated list of tags", * "type": "string", * "required": false, * "default": null * } * @return void */ public function createTask() { $this->requiresAuthentication(); $fields = array('category_id' => Request::getInt('category_id', 0, 'post'), 'title' => Request::getVar('title', null, 'post', 'none', 2), 'comment' => Request::getVar('comment', null, 'post', 'none', 2), 'created' => Request::getVar('created', new Date('now'), 'post'), 'created_by' => Request::getInt('created_by', 0, 'post'), 'state' => Request::getInt('state', Post::STATE_PUBLISHED, 'post'), 'sticky' => Request::getInt('sticky', 0, 'post'), 'parent' => Request::getInt('parent', 0, 'post'), 'scope' => Request::getVar('scope', 'site', 'post'), 'scope_id' => Request::getInt('scope_id', 0, 'post'), 'access' => Request::getInt('access', Post::ACCESS_PUBLIC, 'post'), 'anonymous' => Request::getInt('anonymous', 0, 'post'), 'thread' => Request::getInt('thread', 0, 'post'), 'closed' => Request::getInt('closed', 0, 'post'), 'hits' => Request::getInt('hits', 0, 'post')); if (!$fields['category_id']) { throw new Exception(Lang::txt('COM_FORUM_ERROR_CATEGORY_ID_MISSING'), 400); } $row = Post::blank(); if (!$row->set($fields)) { throw new Exception(Lang::txt('COM_FORUM_ERROR_BINDING_DATA'), 500); } $row->set('anonymous', $fields['anonymous'] ? 1 : 0); $category = Category::all()->whereEquals('id', $row->get('category_id'))->whereEquals('scope', $row->get('scope'))->whereEquals('scope_id', $row->get('scope_id'))->where('state', '!=', Category::STATE_DELETED)->row(); if (!$category->get('id')) { throw new Exception(Lang::txt('COM_FORUM_ERROR_CATEGORY_NOT_FOUND'), 400); } if (!$row->save()) { throw new Exception(Lang::txt('COM_FORUM_ERROR_SAVING_DATA'), 500); } if ($fields['created_by']) { $row->set('created_by', (int) $fields['created_by']); $row->save(); } if ($tags = Request::getVar('tags', null, 'post')) { if (!$row->tag($tags, User::get('id'))) { throw new Exception(Lang::txt('COM_FORUM_ERROR_SAVING_TAGS'), 500); } } // Record the activity $base = rtrim(Request::base(), '/'); $url = str_replace('/api', '', $base . '/' . ltrim(Route::url($row->link()), '/')); $recipients = array(['forum.site', 1], ['forum.section', $category->get('section_id')], ['user', $row->get('created_by')]); $type = 'thread'; $desc = Lang::txt('COM_FORUM_ACTIVITY_' . strtoupper($type) . '_CREATED', '<a href="' . $url . '">' . $row->get('title') . '</a>'); // If this is a post in a thread and not the thread starter... if ($row->get('parent')) { $thread = Post::oneOrFail($row->get('thread')); $thread->set('last_activity', $fields['id'] ? $row->get('modified') : $row->get('created')); $thread->save(); $type = 'post'; $desc = Lang::txt('COM_FORUM_ACTIVITY_' . strtoupper($type) . '_CREATED', $row->get('id'), '<a href="' . $url . '">' . $thread->get('title') . '</a>'); // If the parent post is not the same as the // thread starter (i.e., this is a reply) if ($row->get('parent') != $row->get('thread')) { $parent = Post::oneOrFail($row->get('parent')); $recipients[] = ['user', $parent->get('created_by')]; } } Event::trigger('system.logActivity', ['activity' => ['action' => 'created', 'scope' => 'forum.' . $type, 'scope_id' => $row->get('id'), 'anonymous' => $row->get('anonymous', 0), 'description' => $desc, 'details' => array('thread' => $row->get('thread'), 'url' => $url)], 'recipients' => $recipients]); $obj = $row->toObject(); $obj->creator = new stdClass(); $obj->creator->id = 0; $obj->creator->name = Lang::txt('COM_FORUM_ANONYMOUS'); if (!$row->get('anonymous')) { $obj->creator->id = $row->get('created_by'); $obj->creator->name = $row->creator->get('name'); } $this->send($obj); }