/** * Return data on a course view (this will be some form of HTML) * * @param object $course Current course * @param object $offering Name of the component * @param boolean $describe Return plugin description only? * @return object */ public function onCourse($course, $offering, $describe = false) { $response = with(new \Hubzero\Base\Object())->set('name', $this->_name)->set('title', Lang::txt('PLG_COURSES_' . strtoupper($this->_name)))->set('description', JText::_('PLG_COURSES_' . strtoupper($this->_name) . '_BLURB'))->set('default_access', $this->params->get('plugin_access', 'members'))->set('display_menu_tab', true)->set('icon', 'f086'); if ($describe) { return $response; } if (!($active = Request::getVar('active'))) { Request::setVar('active', $active = $this->_name); } $this->config = $course->config(); $this->course = $course; $this->offering = $offering; $this->database = App::get('db'); $this->params->merge(new \Hubzero\Config\Registry($offering->section()->get('params'))); // Determine if we need to return any HTML (meaning this is the active plugin) if ($response->get('name') == $active) { $this->_active = $this->_name; $this->section = new \Components\Forum\Tables\Section($this->database); $this->sections = $this->section->getRecords(array('state' => 1, 'scope' => 'course', 'scope_id' => $this->offering->get('id'), 'sort_Dir' => 'DESC', 'sort' => 'ordering ASC, created ASC, title')); //option and paging vars $this->option = 'com_courses'; $this->name = 'courses'; $this->limitstart = Request::getInt('limitstart', 0); $this->limit = Request::getInt('limit', 500); $action = ''; $u = strtolower(Request::getWord('unit', '')); if ($u == 'manage') { $action = 'sections'; $b = Request::getVar('group', ''); if ($b) { Request::setVar('section', $b); } $c = Request::getVar('asset', ''); switch ($c) { case 'orderdown': $action = 'orderdown'; break; case 'orderup': $action = 'orderup'; break; case 'edit': $action = 'editsection'; break; case 'delete': $action = 'deletesection'; break; case 'new': $action = 'editcategory'; break; default: if ($c) { Request::setVar('category', $c); $action = 'editcategory'; } $d = Request::getVar('d', ''); switch ($d) { case 'edit': $action = 'editcategory'; break; case 'delete': $action = 'deletecategory'; break; default: //$d = Request::setVar('thread', $c); //$action = 'threads'; break; } break; } } if (Request::getVar('file', '')) { $action = 'download'; } $action = Request::getVar('action', $action, 'post'); if (!$action) { $action = Request::getVar('action', $action, 'get'); } if ($action == 'edit' && Request::getInt('post', 0)) { $action = 'editthread'; } //push the stylesheet to the view $this->css(); $this->base = $this->offering->link() . '&active=' . $this->_name; Pathway::append(Lang::txt('PLG_COURSES_' . strtoupper($this->_name)), $this->base); switch ($action) { case 'sections': $response->set('html', $this->sections()); break; case 'newsection': $response->set('html', $this->sections()); break; case 'editsection': $response->set('html', $this->sections()); break; case 'savesection': $response->set('html', $this->savesection()); break; case 'deletesection': $response->set('html', $this->deletesection()); break; case 'categories': $response->set('html', $this->categories()); break; case 'savecategory': $response->set('html', $this->savecategory()); break; case 'newcategory': $response->set('html', $this->editcategory()); break; case 'editcategory': $response->set('html', $this->editcategory()); break; case 'deletecategory': $response->set('html', $this->deletecategory()); break; case 'threads': $response->set('html', $this->threads()); break; case 'savethread': $response->set('html', $this->savethread()); break; case 'editthread': $response->set('html', $this->editthread()); break; case 'deletethread': $response->set('html', $this->deletethread()); break; case 'orderup': $response->set('html', $this->orderup()); break; case 'orderdown': $response->set('html', $this->orderdown()); break; case 'download': $response->set('html', $this->download()); break; case 'search': $response->set('html', $this->panel()); break; default: $response->set('html', $this->panel()); break; } } $tModel = new \Components\Forum\Tables\Post($this->database); $response->set('meta_count', $tModel->getCount(array('scope' => 'course', 'scope_id' => $offering->get('id'), 'state' => array(1, 3), 'parent' => 0, 'scope_sub_id' => $this->params->get('discussions_threads', 'all') != 'all' ? $course->offering()->section()->get('id') : null))); // Return the output return $response; }
/** * Get a count of all forum posts * * @param integer $gid Group ID * @param string $authorized Authorization level * @param string $state State of threads * @return integer */ public static function getForumCount($gid = NULL, $authorized, $state = '') { if (!$gid) { return 0; } $database = App::get('db'); include_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'tables' . DS . 'post.php'; $filters = array(); $filters['authorized'] = $authorized; switch ($state) { case 'sticky': $filters['sticky'] = 1; break; case 'closed': $filters['state'] = 2; break; case 'open': default: $filters['state'] = 1; break; } $filters['start'] = 0; $filters['group'] = $gid; $forum = new \Components\Forum\Tables\Post($database); return $forum->getCount($filters); }