Ejemplo n.º 1
0
 /**
  * Display all sections
  *
  * @return  void
  */
 public function displayTask()
 {
     // Filters
     $filters = array('state' => Request::getState($this->_option . '.' . $this->_controller . '.state', 'state', '-1', 'int'), 'access' => Request::getState($this->_option . '.' . $this->_controller . '.access', 'access', '-1', 'int'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'id'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'), 'search' => Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''), 'scopeinfo' => Request::getState($this->_option . '.' . $this->_controller . '.scopeinfo', 'scopeinfo', ''));
     if (strstr($filters['scopeinfo'], ':')) {
         $bits = explode(':', $filters['scopeinfo']);
         $filters['scope'] = $bits[0];
         $filters['scope_id'] = intval(end($bits));
     } else {
         $filters['scope'] = '';
         $filters['scope_id'] = -1;
     }
     $entries = Section::all()->including(['categories', function ($category) {
         $category->select('id')->select('section_id');
     }]);
     if ($filters['search']) {
         $entries->whereLike('title', strtolower((string) $filters['search']));
     }
     if ($filters['scope']) {
         $entries->whereEquals('scope', $filters['scope']);
     }
     if ($filters['scope_id'] >= 0) {
         $entries->whereEquals('scope_id', (int) $filters['scope_id']);
     }
     if ($filters['state'] >= 0) {
         $entries->whereEquals('state', (int) $filters['state']);
     }
     if ($filters['access'] >= 0) {
         $entries->whereEquals('access', (int) $filters['access']);
     }
     // Get records
     $rows = $entries->ordered('filter_order', 'filter_order_Dir')->paginated('limitstart', 'limit')->rows();
     $forum = new Manager($filters['scope'], $filters['scope_id']);
     // Output the HTML
     $this->view->set('rows', $rows)->set('filters', $filters)->set('scopes', $forum->scopes())->display();
 }
Ejemplo n.º 2
0
 /**
  * Deletes a section and redirects to main page afterwards
  *
  * @return  void
  */
 public function deleteTask()
 {
     // Is the user logged in?
     if (User::isGuest()) {
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode(Route::url('index.php?option=' . $this->_option, false, true))), Lang::txt('COM_FORUM_LOGIN_NOTICE'), 'warning');
         return;
     }
     $this->_authorize('section');
     // Load the section
     $section = Section::all()->whereEquals('alias', Request::getVar('section'))->whereEquals('scope', $this->forum->get('scope'))->whereEquals('scope_id', $this->forum->get('scope_id'))->where('state', '!=', Section::STATE_DELETED)->row();
     // Make the sure the section exist
     if (!$section->get('id')) {
         App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_FORUM_MISSING_ID'), 'error');
         return;
     }
     // Check if user is authorized to delete entries
     $this->_authorize('section', $section->get('id'));
     if (!$this->config->get('access-delete-section')) {
         App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_FORUM_NOT_AUTHORIZED'), 'warning');
         return;
     }
     // Set the section to "deleted"
     $section->set('state', $section::STATE_DELETED);
     if (!$section->save()) {
         Notify::error($section->getError());
     } else {
         Notify::success(Lang::txt('COM_FORUM_SECTION_DELETED'));
     }
     // Log activity
     Event::trigger('system.logActivity', ['activity' => ['action' => 'deleted', 'scope' => 'forum.section', 'scope_id' => $section->get('id'), 'description' => Lang::txt('PLG_GROUPS_FORUM_ACTIVITY_SECTION_DELETED', '<a href="' . Route::url('index.php?option=' . $this->_option) . '">' . $section->get('title') . '</a>'), 'details' => array('title' => $section->get('title'), 'url' => Route::url('index.php?option=' . $this->_option))], 'recipients' => array(['forum.site', 1], ['forum.section', $section->get('id')], ['user', $section->get('created_by')])]);
     // Redirect to main listing
     App::redirect(Route::url('index.php?option=' . $this->_option));
 }
Ejemplo n.º 3
0
 /**
  * Displays a question response for editing
  *
  * @param   object  $category
  * @return  void
  */
 public function editTask($category = null)
 {
     Request::setVar('hidemainmenu', 1);
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $section = Section::oneOrNew(Request::getInt('section_id', 0));
     if (!is_object($category)) {
         $id = Request::getVar('id', array(0));
         if (is_array($id)) {
             $id = !empty($id) ? intval($id[0]) : 0;
         }
         $category = Category::oneOrNew($id);
     }
     if ($category->isNew()) {
         $category->set('created_by', User::get('id'));
         $category->set('section_id', $section->get('id'));
         $category->set('scope', $section->get('scope'));
         $category->set('scope_id', $section->get('scope_id'));
     }
     $data = Section::all()->ordered()->rows();
     $sections = array();
     foreach ($data as $s) {
         $ky = $s->scope . ' (' . $s->scope_id . ')';
         if ($s->scope == 'site') {
             $ky = '[ site ]';
         }
         if (!isset($sections[$ky])) {
             $sections[$ky] = array();
         }
         $sections[$ky][] = $s;
         asort($sections[$ky]);
     }
     User::setState('com_forum.edit.category.data', array('id' => $category->get('id'), 'asset_id' => $category->get('asset_id')));
     $m = new AdminCategory();
     // Output the HTML
     $this->view->set('row', $category)->set('section', $section)->set('sections', $sections)->set('form', $m->getForm())->setLayout('edit')->display();
 }
Ejemplo n.º 4
0
 /**
  * Get a list of sections for a forum
  *
  * @param   array    $filters  Filters to apply to data fetch
  * @return  object
  */
 public function sections($filters = array())
 {
     if (!isset($filters['scope'])) {
         $filters['scope'] = (string) $this->get('scope');
     }
     if (!isset($filters['scope_id'])) {
         $filters['scope_id'] = (int) $this->get('scope_id');
     }
     $model = Section::all();
     if ($filters['scope']) {
         $model->whereEquals('scope', $filters['scope']);
     }
     if ($filters['scope_id'] >= 0) {
         $model->whereEquals('scope_id', $filters['scope_id']);
     }
     if (isset($filters['state']) && $filters['state'] >= 0) {
         $model->whereEquals('state', (int) $filters['state']);
     }
     if (isset($filters['state'])) {
         $model->whereEquals('state', $filters['state']);
     }
     if (isset($filters['access'])) {
         if (!is_array($filters['access'])) {
             $filters['access'] = array($filters['access']);
         }
         $model->whereIn('access', $filters['access']);
     }
     return $model;
 }
Ejemplo n.º 5
0
 /**
  * Displays a question response for editing
  *
  * @param   mixed  $post
  * @return  void
  */
 public function editTask($post = null)
 {
     Request::setVar('hidemainmenu', 1);
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $parent = Request::getInt('parent', 0);
     if (!is_object($post)) {
         $id = Request::getVar('id', array(0));
         if (is_array($id)) {
             $id = intval($id[0]);
         }
         $post = Post::oneOrNew($id);
     }
     if ($post->isNew()) {
         $post->set('parent', $parent);
         $post->set('created_by', User::get('id'));
     }
     if ($post->get('parent')) {
         $threads = Post::all()->whereEquals('category_id', $post->get('category_id'))->whereEquals('parent', 0)->ordered()->rows();
     }
     // Get the category
     $category = Category::oneOrNew($post->get('category_id'));
     $categories = array();
     foreach (Category::all()->rows() as $c) {
         if (!isset($categories[$c->section_id])) {
             $categories[$c->section_id] = array();
         }
         $categories[$c->section_id][] = $c;
         asort($categories[$c->section_id]);
     }
     // Get the section
     $section = Section::oneOrNew($category->get('section_id'));
     // Get the sections for this group
     $sections = array();
     foreach (Section::all()->rows() as $s) {
         $ky = $s->scope . ' (' . $s->scope_id . ')';
         if ($s->scope == 'site') {
             $ky = '[ site ]';
         }
         if (!isset($sections[$ky])) {
             $sections[$ky] = array();
         }
         $s->categories = isset($categories[$s->id]) ? $categories[$s->id] : array();
         $sections[$ky][] = $s;
         asort($sections[$ky]);
     }
     User::setState('com_forum.edit.thread.data', array('id' => $post->get('id'), 'asset_id' => $post->get('asset_id')));
     $m = new AdminThread();
     $form = $m->getForm();
     // Get tags on this article
     $this->view->set('row', $post)->set('sections', $sections)->set('categories', $categories)->set('form', $form)->setLayout('edit')->display();
 }
Ejemplo n.º 6
0
 /**
  * Show a form for editing an entry
  *
  * @param   mixed  $post
  * @return  void
  */
 public function editTask($post = null)
 {
     $id = Request::getInt('thread', 0);
     $category = Request::getCmd('category', '');
     $section = Request::getCmd('section', '');
     if (User::isGuest()) {
         $return = Route::url('index.php?option=' . $this->_option . '&section=' . $section . '&category=' . $category . '&task=new');
         if ($id) {
             $return = Route::url('index.php?option=' . $this->_option . '&section=' . $section . '&category=' . $category . '&thread=' . $id . '&task=edit');
         }
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($return)) . Lang::txt('COM_FORUM_LOGIN_NOTICE'), 'warning');
     }
     // Section
     $section = Section::all()->whereEquals('alias', $section)->whereEquals('scope', $this->forum->get('scope'))->whereEquals('scope_id', $this->forum->get('scope_id'))->where('state', '!=', Section::STATE_DELETED)->row();
     if (!$section->get('id')) {
         App::abort(404, Lang::txt('COM_FORUM_SECTION_NOT_FOUND'));
     }
     // Get the category
     $category = Category::all()->whereEquals('alias', $category)->whereEquals('scope', $this->forum->get('scope'))->whereEquals('scope_id', $this->forum->get('scope_id'))->where('state', '!=', Category::STATE_DELETED)->row();
     if (!$category->get('id')) {
         App::abort(404, Lang::txt('COM_FORUM_CATEGORY_NOT_FOUND'));
     }
     // Incoming
     if (!is_object($post)) {
         $post = Post::oneOrNew($id);
     }
     $this->_authorize('thread', $id);
     if ($post->isNew()) {
         $post->set('scope', $this->forum->get('scope'));
         $post->set('created_by', User::get('id'));
     } elseif ($post->get('created_by') != User::get('id') && !$this->config->get('access-edit-thread')) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&section=' . $section . '&category=' . $category), Lang::txt('COM_FORUM_NOT_AUTHORIZED'), 'warning');
     }
     // Set the page title
     $this->buildTitle($section, $category, $post);
     // Set the pathway
     $this->buildPathway($section, $category, $post);
     $this->view->set('config', $this->config)->set('forum', $this->forum)->set('section', $section)->set('category', $category)->set('post', $post)->setErrors($this->getErrors())->setLayout('edit')->display();
 }
Ejemplo n.º 7
0
 /**
  * Remove all items associated with the gorup being deleted
  *
  * @param   object  $course  Course being deleted
  * @return  string  Log of items removed
  */
 public function onCourseDelete($course)
 {
     if (!$course->exists()) {
         return '';
     }
     $log = Lang::txt('PLG_COURSES_FORUM') . ': ';
     $sections = array();
     foreach ($course->offerings() as $offering) {
         if (!$offering->exists()) {
             continue;
         }
         $sec = Section::all()->whereEquals('scope', 'course')->whereEquals('scope_id', $offering->get('id'))->rows();
         foreach ($sec as $s) {
             $sections[] = $s;
         }
     }
     // Do we have any IDs?
     if (count($sections) > 0) {
         // Loop through each ID
         foreach ($sections as $section) {
             // Get the categories in this section
             $categories = $section->categories()->rows();
             if ($categories->count()) {
                 // Build a list of category IDs
                 foreach ($categories as $category) {
                     $log .= 'forum.section.' . $section->get('id') . '.category.' . $category->get('id') . '.post' . "\n";
                     $log .= 'forum.section.' . $section->get('id') . '.category.' . $category->get('id') . "\n";
                 }
             }
             $log .= 'forum.section.' . $section->get('id') . ' ' . "\n";
             // Set the section to "deleted"
             // Set all the categories to "deleted"
             // Set all the threads/posts in all the categories to "deleted"
             $section->set('state', $section::STATE_DELETED);
             if (!$section->save()) {
                 $this->setError($sModel->getError());
                 return '';
             }
         }
     } else {
         $log .= Lang::txt('PLG_COURSES_DISCUSSIONS_NO_RESULTS') . "\n";
     }
     return $log;
 }
Ejemplo n.º 8
0
 /**
  * Display categories for a section
  *
  * @apiMethod GET
  * @apiUri    /forum/categories
  * @apiParameter {
  * 		"name":          "limit",
  * 		"description":   "Number of result to return.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       25
  * }
  * @apiParameter {
  * 		"name":          "limitstart",
  * 		"description":   "Number of where to start returning results.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       0
  * }
  * @apiParameter {
  * 		"name":          "section",
  * 		"description":   "Section ID",
  * 		"type":          "integer",
  * 		"required":      true,
  *      "default":       0
  * }
  * @apiParameter {
  * 		"name":          "search",
  * 		"description":   "A word or phrase to search for.",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       ""
  * }
  * @apiParameter {
  * 		"name":          "scope",
  * 		"description":   "Scope (site, groups, members, etc.)",
  * 		"type":          "string",
  * 		"required":      false,
  *      "default":       "site"
  * }
  * @apiParameter {
  * 		"name":          "scope_id",
  * 		"description":   "Scope ID",
  * 		"type":          "integer",
  * 		"required":      false,
  *      "default":       0
  * }
  * @apiParameter {
  * 		"name":          "closed",
  * 		"description":   "If the category is marked as closed (1) or not (0). NULL to return all.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       null
  * }
  * @return    void
  */
 public function categoriesTask()
 {
     $filters = array('limit' => Request::getInt('limit', 25), 'start' => Request::getInt('limitstart', 0), 'section_id' => Request::getInt('section', 0), 'search' => Request::getVar('search', ''), 'scope' => Request::getWord('scope', 'site'), 'scope_id' => Request::getInt('scope_id', 0), 'state' => Category::STATE_PUBLISHED, 'closed' => Request::getVar('closed', null), 'access' => User::getAuthorisedViewLevels());
     if ($filters['scope'] == 'group') {
         $group = \Hubzero\User\Group::getInstance($filters['scope_id']);
         if ($group && in_array(User::get('id'), $group->get('members'))) {
             $filters['access'][] = 5;
             // Private
         }
     }
     $forum = new Manager($filters['scope'], $filters['scope_id']);
     $response = new stdClass();
     $response->categories = array();
     if ($filters['section_id']) {
         // Make sure the section exists and is available
         $section = Section::oneOrFail($filters['section_id']);
         if (!$section->get('id')) {
             throw new Exception(Lang::txt('COM_FORUM_ERROR_SECTION_NOT_FOUND'), 404);
         }
         if ($section->get('state') == Section::STATE_DELETED) {
             throw new Exception(Lang::txt('COM_FORUM_ERROR_SECTION_NOT_FOUND'), 404);
         }
         $response->section = new stdClass();
         $response->section->id = $section->get('id');
         $response->section->title = $section->get('title');
         $response->section->alias = $section->get('alias');
         $response->section->created = with(new Date($section->get('created')))->format('Y-m-d\\TH:i:s\\Z');
         $response->section->scope = $section->get('scope');
         $response->section->scope_id = $section->get('scope_id');
     } else {
         $sections = Section::all()->whereEquals('scope', $filters['scope'])->whereEquals('scope_id', $filters['scope_id'])->whereEquals('state', $filters['state'])->whereIn('access', $filters['access'])->rows();
         $filters['section_id'] = array();
         foreach ($sections as $section) {
             $filters['section_id'][] = $section->get('id');
         }
     }
     $entries = Category::all()->whereIn('section_id', (array) $filters['section_id'])->whereEquals('state', $filters['state'])->whereIn('access', $filters['access']);
     if (is_int($filters['closed'])) {
         $entries->whereEquals('closed', $filters['closed']);
     }
     if ($filters['search']) {
         $entries->whereLike('description', $filters['search'], 1)->orWhereLike('title', $filters['search'], 1)->resetDepth();
     }
     $categories = $entries->ordered()->paginated()->rows();
     $response->total = $categories->count();
     if ($response->total) {
         $base = rtrim(Request::base(), '/');
         foreach ($categories as $category) {
             $obj = new stdClass();
             $obj->id = (int) $category->get('id');
             $obj->title = $category->get('title');
             $obj->alias = $category->get('alias');
             $obj->description = $category->get('description');
             $obj->created = with(new Date($category->get('created')))->format('Y-m-d\\TH:i:s\\Z');
             $obj->closed = (int) $category->get('closed');
             $obj->scope = $category->get('scope');
             $obj->scope_id = (int) $category->get('scope_id');
             $obj->section_id = (int) $category->get('section_id');
             $obj->threads = $category->threads()->whereEquals('state', $filters['state'])->whereIn('access', $filters['access'])->total();
             $obj->posts = $category->posts()->whereEquals('state', $filters['state'])->whereIn('access', $filters['access'])->total();
             $obj->url = str_replace('/api', '', $base . '/' . ltrim(Route::url($category->link()), '/'));
             $response->categories[] = $obj;
         }
     }
     $response->success = true;
     $this->send($response);
 }
Ejemplo n.º 9
0
 /**
  * Show a form for editing an entry
  *
  * @param   object  $category
  * @return  void
  */
 public function editTask($category = null)
 {
     if (User::isGuest()) {
         $return = Route::url('index.php?option=' . $this->_option, false, true);
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($return)));
     }
     // Get the section
     $section = Section::all()->whereEquals('alias', Request::getVar('section', ''))->whereEquals('scope', $this->forum->get('scope'))->whereEquals('scope_id', $this->forum->get('scope_id'))->where('state', '!=', Section::STATE_DELETED)->row();
     if (!$section->get('id')) {
         App::abort(404, Lang::txt('COM_FORUM_SECTION_NOT_FOUND'));
     }
     // Incoming
     if (!is_object($category)) {
         $category = Category::all()->whereEquals('alias', Request::getVar('category', ''))->whereEquals('scope', $this->forum->get('scope'))->whereEquals('scope_id', $this->forum->get('scope_id'))->whereEquals('section_id', $section->get('id'))->where('state', '!=', Category::STATE_DELETED)->row();
     }
     $this->_authorize('category', $category->get('id'));
     if ($category->isNew()) {
         $category->set('created_by', User::get('id'));
         $category->set('section_id', $section->get('id'));
     } elseif ($category->get('created_by') != User::get('id') && !$this->config->get('access-create-category')) {
         App::redirect(Route::url('index.php?option=' . $this->_option));
     }
     // Output the view
     $this->view->set('config', $this->config)->set('forum', $this->forum)->set('category', $category)->set('section', $section)->setLayout('edit')->display();
 }
Ejemplo n.º 10
0
 /**
  * Reorder a section
  *
  * @param   integer  $dir  Direction
  * @return  void
  */
 public function reorder($dir = 1)
 {
     if (User::isGuest()) {
         $this->setError(Lang::txt('GROUPS_LOGIN_NOTICE'));
         return;
     }
     if ($this->authorized != 'manager' && $this->authorized != 'admin') {
         $this->setError(Lang::txt('PLG_GROUPS_FORUM_NOT_AUTHORIZED'));
         return $this->sections();
     }
     // Get the section
     $section = Section::all()->whereEquals('alias', Request::getVar('section', ''))->whereEquals('scope', $this->forum->get('scope'))->whereEquals('scope_id', $this->forum->get('scope_id'))->row();
     // Move the section
     if (!$section->move($dir)) {
         Notify::error($section->getError());
     } else {
         // Record the activity
         $recipients = array(['group', $this->group->get('gidNumber')], ['forum.' . $this->forum->get('scope'), $this->forum->get('scope_id')], ['forum.section', $section->get('id')]);
         foreach ($this->group->get('managers') as $recipient) {
             $recipients[] = ['user', $recipient];
         }
         Event::trigger('system.logActivity', ['activity' => ['action' => 'reordered', 'scope' => 'forum.section', 'scope_id' => $section->get('id'), 'description' => Lang::txt('PLG_GROUPS_FORUM_ACTIVITY_SECTION_REORDERED', '<a href="' . Route::url($this->base) . '">' . $section->get('title') . '</a>'), 'details' => array('title' => $section->get('title'), 'url' => Route::url($this->base))], 'recipients' => $recipients]);
     }
     // Redirect to main lsiting
     App::redirect(Route::url($this->base));
 }