Exemplo n.º 1
0
 function onGroupCreate($group)
 {
     if (!self::kunenaOnline()) {
         return;
     }
     if (JRequest::getInt('kunenaforum', 0) < 0) {
         return;
     }
     $catid = self::getForumCategory($group->categoryid);
     if ($catid === false) {
         return;
     }
     $category = new KunenaForumCategory();
     $category->set('parent_id', $catid);
     $category->set('name', $group->name);
     $category->set('description', $group->description);
     $category->set('headerdesc', $group->description);
     $category->set('accesstype', 'jomsocial');
     $category->set('access', $group->id);
     $category->set('published', $group->published);
     $success = $category->save();
     if (!$success) {
         JFactory::getApplication()->enqueueMessage(JText::sprintf('PLG_COMMUNITY_KUNENAGROUPS_GROUP_CREATE_FAILED', 'notice'));
         return;
     }
     $category->setModerator($group->ownerid, 1);
 }
Exemplo n.º 2
0
 /**
  * @param   KunenaForumCategory $instance
  * @internal
  */
 public static function register($instance)
 {
     if ($instance->exists()) {
         $instance->level = isset(self::$_instances[$instance->parent_id]) ? self::$_instances[$instance->parent_id]->level + 1 : 0;
         self::$_instances[$instance->id] = $instance;
         if (!isset(self::$_tree[(int) $instance->id])) {
             self::$_tree[$instance->id] = array();
             self::$_tree[$instance->parent_id][$instance->id] =& self::$_tree[$instance->id];
         }
     } else {
         unset(self::$_instances[$instance->id]);
         unset(self::$_tree[$instance->id], self::$_tree[$instance->parent_id][$instance->id]);
     }
 }
Exemplo n.º 3
0
 /**
  * Prepare message actions display.
  *
  * @return void
  */
 protected function before()
 {
     parent::before();
     $catid = $this->input->getInt('id');
     $me = KunenaUserHelper::getMyself();
     $this->category = KunenaForumCategory::getInstance($catid);
     $token = JSession::getFormToken();
     $task = "index.php?option=com_kunena&view=category&task=%s&catid={$catid}&{$token}=1";
     $layout = "index.php?option=com_kunena&view=topic&layout=%s&catid={$catid}";
     $this->template = KunenaFactory::getTemplate();
     $this->categoryButtons = new JObject();
     // Is user allowed to post new topic?
     if ($this->category->getNewTopicCategory()->exists()) {
         $this->categoryButtons->set('create', $this->getButton(sprintf($layout, 'create'), 'create', 'topic', 'communication', true));
     }
     // Is user allowed to mark forums as read?
     if ($me->exists()) {
         $this->categoryButtons->set('markread', $this->getButton(sprintf($task, 'markread'), 'markread', 'category', 'user', true));
     }
     // Is user allowed to subscribe category?
     if ($this->category->isAuthorised('subscribe')) {
         $subscribed = $this->category->getSubscribed($me->userid);
         if (!$subscribed) {
             $this->categoryButtons->set('subscribe', $this->getButton(sprintf($task, 'subscribe'), 'subscribe', 'category', 'user', true));
         } else {
             $this->categoryButtons->set('unsubscribe', $this->getButton(sprintf($task, 'unsubscribe'), 'unsubscribe', 'category', 'user', true));
         }
     }
     JPluginHelper::importPlugin('kunena');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onKunenaGetButtons', array('category.action', $this->categoryButtons, $this));
 }
Exemplo n.º 4
0
 function shKUCategoryName($catid, $option, $shLangIso, $shLangName)
 {
     global $sh_LANG;
     static $cats = null;
     $sefConfig =& Sh404sefFactory::getConfig();
     if (empty($catid) || !$sefConfig->shFbInsertCategoryName) {
         return '';
     }
     if (class_exists('KunenaForum')) {
         // Kunena 2.0 support
         $category = KunenaForumCategory::getInstance($catid);
         $catname = $category->name;
     } elseif (class_exists('KunenaRouter')) {
         if (KunenaRouter::$catidcache === null) {
             KunenaRouter::loadCategories();
         }
         // Kunena 1.6 support
         $catname = empty(KunenaRouter::$catidcache[$catid]) ? '' : KunenaRouter::$catidcache[$catid]['name'];
     } else {
         // Kunena 1.0 / 1.5 support
         if (is_null($cats)) {
             try {
                 $cats = ShlDbHelper::selectObjectList('#__fb_categories', array('id', 'name'));
             } catch (Exception $e) {
                 ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
             }
         }
         $catname = empty($cats[$catid]) ? null : $cats[$catid]->name;
     }
     $shCat = empty($catname) ? $sh_LANG[$shLangIso]['COM_SH404SEF_KU_CATEGORY'] . $sefConfig->replacement . $catid : ($sefConfig->shFbInsertCategoryId ? $catid . $sefConfig->replacement : '') . $catname;
     // if name, put ID only if requested
     return $shCat;
 }
Exemplo n.º 5
0
	/**
	 * Create section and 3 categories
	 */
	public function testCreateCategories() {
		$section = new KunenaForumCategory();
		$section->name = 'Section';
		$section->published = 1;
		$this->assertTrue($section->save(), $section->getError());
		$this->checkCategory($section);
		for ($i=1; $i<=3; $i++) {
			$category = new KunenaForumCategory();
			$category->name = "Category $i";
			$category->parent_id = $section->id;
			$category->published = 1;
			$this->assertTrue($category->save(), $category->getError());
			self::$category[$i] = $category;
			$this->checkCategory($category);
		}
	}
Exemplo n.º 6
0
	/**
	 * returns the forum category url
	 *
	 * @return null|string
	 */
	public function url()
	{
		if ( ! $this->_category ) {
			return null;
		}

		return $this->_category->getUrl();
	}
Exemplo n.º 7
0
	/**
	 * Prepare document.
	 *
	 * @return void
	 */
	protected function prepareDocument()
	{
		$page         = $this->pagination->pagesCurrent;
		$pages        = $this->pagination->pagesTotal;
		$pagesText    = $page > 1 ? " ({$page}/{$pages})" : '';
		$parentText   = $this->category->getParent()->displayField('name');
		$categoryText = $this->category->displayField('name');

		$app       = JFactory::getApplication();
		$menu_item = $app->getMenu()->getActive(); // get the active item

		if ($menu_item)
		{
			$params             = $menu_item->params; // get the params
			$params_title       = $params->get('page_title');
			$params_keywords    = $params->get('menu-meta_keywords');
			$params_description = $params->get('menu-meta_description');

			if (!empty($params_title))
			{
				$title = $params->get('page_title');
				$this->setTitle($title);
			}
			else
			{
				$title = JText::sprintf('COM_KUNENA_VIEW_CATEGORY_DEFAULT', "{$parentText} / {$categoryText}{$pagesText}");
				$this->setTitle($title);
			}

			if (!empty($params_keywords))
			{
				$keywords = $params->get('menu-meta_keywords');
				$this->setKeywords($keywords);
			}
			else
			{
				$keywords = JText::_('COM_KUNENA_CATEGORIES') . ", {$parentText}, {$categoryText}, {$this->config->board_title}";
				$this->setKeywords($keywords);
			}

			if (!empty($params_description))
			{
				$description = $params->get('menu-meta_description');
				$this->setDescription($description);
			}
			else
			{
				$description = "{$parentText} - {$categoryText}{$pagesText} - {$this->config->board_title}";
				$this->setDescription($description);
			}
		}
	}
Exemplo n.º 8
0
 /**
  * Prepare document.
  *
  * @return void
  */
 protected function prepareDocument()
 {
     $page = $this->pagination->pagesCurrent;
     $pages = $this->pagination->pagesTotal;
     $pagesText = $page > 1 ? " ({$page}/{$pages})" : '';
     $parentText = $this->category->getParent()->displayField('name');
     $categoryText = $this->category->displayField('name');
     $title = JText::sprintf('COM_KUNENA_VIEW_CATEGORY_DEFAULT', "{$parentText} / {$categoryText}{$pagesText}");
     $this->setTitle($title);
     $keywords = JText::_('COM_KUNENA_CATEGORIES') . ", {$parentText}, {$categoryText}, {$this->config->board_title}";
     $this->setKeywords($keywords);
     $description = "{$parentText} - {$categoryText}{$pagesText} - {$this->config->board_title}";
     $this->setDescription($description);
 }
Exemplo n.º 9
0
 function shKUCategoryName($catid, $option, $shLangIso, $shLangName)
 {
     global $sh_LANG;
     static $cats = null;
     $sefConfig =& shRouter::shGetConfig();
     if (empty($catid) || !$sefConfig->shFbInsertCategoryName) {
         return '';
     }
     if (class_exists('KunenaForum')) {
         // Kunena 2.0 support
         $category = KunenaForumCategory::getInstance($catid);
         $catname = $category->name;
     } elseif (class_exists('KunenaRouter')) {
         if (KunenaRouter::$catidcache === null) {
             KunenaRouter::loadCategories();
         }
         // Kunena 1.6 support
         $catname = empty(KunenaRouter::$catidcache[$catid]) ? '' : KunenaRouter::$catidcache[$catid]['name'];
     } else {
         // Kunena 1.0 / 1.5 support
         if (is_null($cats)) {
             $database =& JFactory::getDBO();
             $query = 'SELECT id, name FROM #__fb_categories';
             $database->setQuery($query);
             if (!shTranslateUrl($option, $shLangName)) {
                 $cats = $database->loadObjectList('id', false);
             } else {
                 $cats = $database->loadObjectList('id');
             }
         }
         $catname = empty($cats[$catid]) ? null : $cats[$catid]->name;
     }
     $shCat = empty($catname) ? $sh_LANG[$shLangIso]['COM_SH404SEF_KU_CATEGORY'] . $sefConfig->replacement . $catid : ($sefConfig->shFbInsertCategoryId ? $catid . $sefConfig->replacement : '') . $catname;
     // if name, put ID only if requested
     return $shCat;
 }
Exemplo n.º 10
0
 /**
  * Prepare topic display.
  *
  * @return void
  *
  * @throws KunenaExceptionAuthorise
  */
 protected function before()
 {
     parent::before();
     $catid = $this->input->getInt('catid', 0);
     $id = $this->input->getInt('id', 0);
     $mesid = $this->input->getInt('mesid', 0);
     $start = $this->input->getInt('limitstart', 0);
     $limit = $this->input->getInt('limit', 0);
     if ($limit < 1 || $limit > 100) {
         $limit = $this->config->messages_per_page;
     }
     $this->me = KunenaUserHelper::getMyself();
     // Load topic and message.
     if ($mesid) {
         // If message was set, use it to find the current topic.
         $this->message = KunenaForumMessageHelper::get($mesid);
         $this->topic = $this->message->getTopic();
     } else {
         // Note that redirect loops throw RuntimeException because of we added KunenaForumTopic::getTopic() call!
         $this->topic = KunenaForumTopicHelper::get($id)->getTopic();
         $this->message = KunenaForumMessageHelper::get($this->topic->first_post_id);
     }
     // Load also category (prefer the URI variable if available).
     if ($catid && $catid != $this->topic->category_id) {
         $this->category = KunenaForumCategoryHelper::get($catid);
         $this->category->tryAuthorise();
     } else {
         $this->category = $this->topic->getCategory();
     }
     // Access check.
     $this->message->tryAuthorise();
     // Check if we need to redirect (category or topic mismatch, or resolve permanent URL).
     if ($this->primary) {
         $channels = $this->category->getChannels();
         if ($this->message->thread != $this->topic->id || $this->topic->category_id != $this->category->id && !isset($channels[$this->topic->category_id]) || $mesid && $this->layout != 'threaded') {
             while (@ob_end_clean()) {
             }
             $this->app->redirect($this->message->getUrl(null, false));
         }
     }
     // Load messages from the current page and set the pagination.
     $hold = KunenaAccess::getInstance()->getAllowedHold($this->me, $this->category->id, false);
     $finder = new KunenaForumMessageFinder();
     $finder->where('thread', '=', $this->topic->id)->filterByHold($hold);
     $start = $mesid ? $this->topic->getPostLocation($mesid) : $start;
     $this->pagination = new KunenaPagination($finder->count(), $start, $limit);
     $this->messages = $finder->order('time', $this->me->getMessageOrdering() == 'asc' ? 1 : -1)->start($this->pagination->limitstart)->limit($this->pagination->limit)->find();
     $this->prepareMessages($mesid);
     // Run events.
     $params = new JRegistry();
     $params->set('ksource', 'kunena');
     $params->set('kunena_view', 'topic');
     $params->set('kunena_layout', 'default');
     $dispatcher = JEventDispatcher::getInstance();
     JPluginHelper::importPlugin('kunena');
     $dispatcher->trigger('onKunenaPrepare', array('kunena.topic', &$this->topic, &$params, 0));
     $dispatcher->trigger('onKunenaPrepare', array('kunena.messages', &$this->messages, &$params, 0));
     // Get user data, captcha & quick reply.
     $this->userTopic = $this->topic->getUserTopic();
     $this->quickReply = $this->topic->isAuthorised('reply') && $this->me->exists();
     $this->headerText = JText::_('COM_KUNENA_TOPIC') . ' ' . html_entity_decode($this->topic->displayField('subject'));
 }
Exemplo n.º 11
0
 /**
  * @param KunenaForumCategory $category
  * @param KunenaForumTopic    $topic
  *
  * @return bool
  */
 protected function canPost(KunenaForumCategory $category, KunenaForumTopic $topic)
 {
     if ($topic->exists()) {
         return $topic->authorise('reply');
     } else {
         return $category->authorise('topic.reply');
     }
 }
Exemplo n.º 12
0
 /**
  * a $item -ben adott temakor rekordhoz kapcsolodó kunena fórum kategória
  * létrehozása vagy modositása
  * @param mysql record object  $item 
  * @return boolean     
  */
 protected function storeKunenaCategory($newId, $item)
 {
     $result = true;
     $db = JFactory::getDBO();
     // $temakor GroupId meghatározása láthatóságtól függ lehet nulla is.
     $db->setQuery('SELECT id FROM #__usergroups WHERE title like "[' . $newId . ']%"');
     $res = $db->loadObject();
     if ($db->getErrorNum() > 0) {
         $db->stderr();
     }
     if ($res) {
         $gr = $res->id;
     } else {
         $gr = 1;
     }
     if ($item->lathatosag == 0) {
         $gr = 1;
         $params = '{"access_post":["6","2","8"],"access_reply":["6","2","8"]}';
     }
     if ($item->lathatosag == 1) {
         $gr = 2;
         $params = '{"access_post":["6","2","8"],"access_reply":["6","2","8"]}';
     }
     if ($item->lathatosag == 2) {
         $params = '{"access_post":["6","' . $gr . '",8"],"access_reply":["6","' . $gr . '",8"]}';
     }
     // szülő elérése
     $db->setQuery('SELECT id FROM #__kunena_categories WHERE alias="T' . $item->szulo . '"');
     $res = $db->loadObject();
     if ($res) {
         $parentId = $res->id;
     } else {
         $parentId = 85;
     }
     //li-de témakörök
     // meglévő rekord elérése
     $db->setQuery('SELECT id FROM #__kunena_categories WHERE alias="T' . $item->id . '"');
     $res = $db->loadObject();
     if ($db->getErrorNum() > 0) {
         $db->stderr();
     }
     // forum kategoria rekord összeállítása
     $data = array();
     if ($res) {
         $data['id'] = $res->id;
     } else {
         $data['id'] = 0;
     }
     $data['parent_id'] = $parentId;
     $data['name'] = strip_tags($item->megnevezes);
     $data['description'] = strip_tags($item->leiras);
     $data['pub_acces'] = $gr;
     $data['access_type'] = 'joomla.group';
     $data['access'] = 1;
     $data['alias'] = 'T' . $newId;
     $data['params'] = $params;
     $data['admin_access'] = 0;
     $data['admin_recurse'] = 1;
     $data['pub_recurse'] = 1;
     $data['published'] = 1;
     // 2015.05.08 tapasztalat: a kunena fórum nem kultiválja ahtml entity-ket
     $data['description'] = html_entity_decode($data['description'], ENT_COMPAT, 'UTF-8');
     $data['name'] = html_entity_decode($data['name'], ENT_COMPAT, 'UTF-8');
     // fórum kategoria rekord tárolása
     $category = new KunenaForumCategory($data);
     if ($data['id'] > 0) {
         $db->setQuery('UPDATE #__kunena_categories
    SET name="' . mysql_escape_string($data['name']) . '",
    description="' . mysql_escape_string($data['description']) . '",
    pub_access="' . $gr . '",
    params = "' . mysql_escape_string($params) . '"
    WHERE id="' . $data['id'] . '"');
         $db->query();
         // DEBUG
         // echo $item->leiras.'<hr>'.$db->getQuery(); exit();
     } else {
         $category->save();
     }
     return $result;
 }
Exemplo n.º 13
0
 /**
  * @param   KunenaForumCategory $category
  * @param   null                $content
  * @param   null                $title
  * @param   null                $class
  *
  * @return mixed
  */
 public function getCategoryLink(KunenaForumCategory $category, $content = null, $title = null, $class = null)
 {
     KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     if (!$content) {
         $content = $this->escape($category->name);
     }
     if ($title === null) {
         $title = JText::sprintf('COM_KUNENA_VIEW_CATEGORY_LIST_CATEGORY_TITLE', $this->escape($category->name));
     }
     $link = JHtml::_('kunenaforum.link', $category->getUrl(), $content, $title, $class, 'follow');
     KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     return $link;
 }
Exemplo n.º 14
0
	public function permdelete() {
		$app = JFactory::getApplication ();
		if (! JRequest::checkToken ('get')) {
			$app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
			$this->redirectBack ();
		}

		if ($this->mesid) {
			// Delete message
			$target = KunenaForumMessageHelper::get($this->mesid);
			$msg = JText::_ ( 'COM_KUNENA_POST_SUCCESS_DELETE' );
			$url = $target->getUrl($this->return, false);
		} else {
			// Delete topic
			$target = KunenaForumTopicHelper::get($this->id);
			$msg = JText::_ ( 'COM_KUNENA_TOPIC_SUCCESS_DELETE' );
			$url = KunenaForumCategory::getInstance($this->return)->getUrl(null, false);
		}
		if ($target->authorise('permdelete') && $target->delete()) {
			$app->enqueueMessage ( $msg );
		} else {
			$app->enqueueMessage ( $target->getError(), 'notice' );
		}
		$app->redirect ( $url );
	}
Exemplo n.º 15
0
 /**
  * a $item -ben adott temakor rekordhoz kapcsolodó kunena fórum kategória
  * létrehozása vagy modositása
  * @param mysql record object  $item 
  * @return boolean     
  */
 protected function storeKunenaCategory($newId, $item)
 {
     $result = true;
     $db = JFactory::getDBO();
     $user = JFactory::getUser($item->user_id);
     $gr = 1;
     $params = '{"access_post":["6","2","8"],"access_reply":["6","2","8"]}';
     // szülő beállítása
     $parentId = 86;
     // meglévő rekord elérése
     $db->setQuery('SELECT id FROM #__kunena_categories WHERE alias="K' . $newId . '"');
     $res = $db->loadObject();
     if ($db->getErrorNum() > 0) {
         $db->stderr();
     }
     // forum kategoria rekord összeállítása
     $data = array();
     if ($res) {
         $data['id'] = $res->id;
     } else {
         $data['id'] = 0;
     }
     $data['parent_id'] = $parentId;
     $data['name'] = strip_tags($user->name);
     $data['description'] = '';
     $data['pub_acces'] = $gr;
     $data['access_type'] = 'joomla.group';
     $data['access'] = 1;
     $data['alias'] = 'K' . $newId;
     $data['params'] = $params;
     $data['admin_access'] = 0;
     $data['admin_recurse'] = 1;
     $data['pub_recurse'] = 1;
     $data['published'] = 1;
     // fórum kategoria rekord tárolása
     $category = new KunenaForumCategory($data);
     if ($data['id'] > 0) {
         $db->setQuery('UPDATE #__kunena_categories
    SET name="' . mysql_escape_string($data['name']) . '",
    description="' . mysql_escape_string($data['description']) . '",
    pub_access="' . $gr . '",
    params = "' . mysql_escape_string($params) . '"
    WHERE id="' . $data['id'] . '"');
         $db->query();
     } else {
         $category->save();
     }
     return $result;
 }
Exemplo n.º 16
0
 protected static function loadCategories()
 {
     KUNENA_PROFILER ? KunenaProfiler::instance()->start('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
     $db = JFactory::getDBO();
     $query = "SELECT * FROM #__kunena_categories ORDER BY ordering, name";
     $db->setQuery($query);
     $results = (array) $db->loadAssocList();
     KunenaError::checkDatabaseError();
     self::$_instances = array();
     self::$_tree = array();
     if (empty($results)) {
         KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
         return;
     }
     foreach ($results as $category) {
         $instance = new KunenaForumCategory($category);
         $instance->exists(true);
         self::$_instances[$instance->id] = $instance;
         if (!isset(self::$_tree[(int) $instance->id])) {
             self::$_tree[$instance->id] = array();
         }
         self::$_tree[$instance->parent_id][$instance->id] =& self::$_tree[(int) $instance->id];
     }
     unset($results);
     // TODO: remove this by adding level into table
     $heap = array(0);
     while (($parent = array_shift($heap)) !== null) {
         foreach (self::$_tree[$parent] as $id => $children) {
             if (!empty($children)) {
                 array_push($heap, $id);
             }
             self::$_instances[$id]->level = $parent ? self::$_instances[$parent]->level + 1 : 0;
         }
     }
     KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function ' . __CLASS__ . '::' . __FUNCTION__ . '()') : null;
 }
Exemplo n.º 17
0
 public function getCategoryLink(KunenaForumCategory $category, $content = null, $title = null, $class = null)
 {
     if (!$content) {
         $content = $this->escape($category->name);
     }
     if ($title === null) {
         $title = JText::sprintf('COM_KUNENA_VIEW_CATEGORY_LIST_CATEGORY_TITLE', $this->escape($category->name));
     }
     return JHtml::_('kunenaforum.link', $category->getUri(), $content, $title, $class, 'follow');
 }
Exemplo n.º 18
0
 /**
  * Method to get the last post link
  *
  * @param   KunenaForumCategory $category The KunenaCategory object
  * @param   string              $content  The content of last topic subject
  * @param   string              $title    The title of the link
  * @param   string              $class    The class attribute of the link
  *
  * @see KunenaLayout::getLastPostLink()
  *
  * @return string
  */
 public function getLastPostLink($category, $content = null, $title = null, $class = null, $length = 20)
 {
     $lastTopic = $category->getLastTopic();
     $channels = $category->getChannels();
     if (!isset($channels[$lastTopic->category_id])) {
         $category = $lastTopic->getCategory();
     }
     $uri = $lastTopic->getUri($category, 'last');
     if (!$content) {
         $content = KunenaHtmlParser::parseText($category->getLastTopic()->subject, $length);
     }
     if ($title === null) {
         $title = JText::sprintf('COM_KUNENA_TOPIC_LAST_LINK_TITLE', $this->escape($category->getLastTopic()->subject));
     }
     return JHtml::_('kunenaforum.link', $uri, $content, $title, $class, 'nofollow');
 }
Exemplo n.º 19
0
 /**
  * Checks if user has moderator permissions in the category.
  *
  * If no category is given or it doesn't exist, check will be done against global moderator permissions.
  *
  * @param KunenaForumCategory $category
  *
  * @return bool
  */
 public function isModerator(KunenaForumCategory $category = null)
 {
     return KunenaAccess::getInstance()->isModerator($this, $category && $category->exists() ? $category->id : null);
 }
Exemplo n.º 20
0
 /**
  * Assign user as moderator or resign him.
  *
  * @param KunenaForumCategory $category
  * @param mixed $user
  * @param bool $status
  *
  * @return bool
  *
  * @example if ($category->authorise('admin')) $category->setModerator($user, true);
  */
 public function setModerator($category, $user = null, $status = true)
 {
     // Check if category exists
     if ($category && !$category->exists()) {
         return false;
     }
     $category_id = $category ? $category->id : 0;
     $status = intval($status);
     // Check if user exists
     $user = KunenaUserHelper::get($user);
     if (!$user->exists()) {
         return false;
     }
     $success = true;
     $usercategory = KunenaForumCategoryUserHelper::get($category_id, $user);
     if ($usercategory->role == 0 && $status || $usercategory->role == 1 && !$status) {
         $usercategory->role = $status;
         $success = $usercategory->save();
         // Clear role cache
         $this->clearCache();
         // Change user moderator status
         $moderator = $this->getModeratorStatus($user);
         if ($user->moderator != !empty($moderator)) {
             $user->moderator = intval(!empty($moderator));
             $success = $user->save();
         }
     }
     return $success;
 }
Exemplo n.º 21
0
 static function remove_forum_k2($course_id, $forum_id)
 {
     $kunena_forum_id = JoomdleHelperForum::get_kunena_forum_id($course_id, $forum_id);
     $category = KunenaForumCategory::getInstance($kunena_forum_id);
     $category->delete();
     $db = JFactory::getDBO();
     $query = 'DELETE ' . ' FROM #__joomdle_course_forums' . " WHERE course_id = " . $db->Quote($course_id);
     $query .= " AND moodle_forum_id = " . $db->Quote($forum_id);
     $db->setQuery($query);
     $db->query();
 }
Exemplo n.º 22
0
	/**
	 * Test delete()
	 *
	 * @param KunenaForumCategory $category
	 * @depends testRemoveModerator
	 */
	public function testDelete(KunenaForumCategory $category) {
		$this->assertTrue($category->delete(), $category->getError());
		$this->assertFalse($category->exists(), 'Check that deleted category does not exist');
		$this->assertNull($category->id, 'Check that deleted category id is null');
	}