/**
  * Test topic creation
  *
  * @param KunenaForumTopic $topic
  * @return KunenaForumTopic
  * @depends testNew
  */
 public function testCreate(KunenaForumTopic $topic)
 {
     // Creation should fail if there's not enough data
     $this->assertFalse($topic->save());
     $this->assertFalse($topic->exists());
     $this->assertNull($topic->id);
     /*		$topic->category_id = 2;
     		$topic->subject = 'Topic';
     		$this->assertTrue($topic->save());
     		$this->assertTrue($topic->exists());
     		$this->assertGreaterThan(1, $topic->id);
     		$topic2 = KunenaForumTopic::getInstance($topic->id);
     		// TODO: Do we want this?
     		//$this->assertSame($topic, $topic2);
     		$this->assertSame($topic->id, $topic2->id);
     		$this->assertSame($topic->name, $topic2->name);
     		return $topic2;*/
 }
예제 #2
0
 /**
  * @param array $ids
  */
 protected static function loadTopics(array $ids)
 {
     foreach ($ids as $i => $id) {
         $id = intval($id);
         if (!$id || isset(self::$_instances[$id])) {
             unset($ids[$i]);
         }
     }
     if (empty($ids)) {
         return;
     }
     $idlist = implode(',', $ids);
     $db = JFactory::getDBO();
     $query = "SELECT * FROM #__kunena_topics WHERE id IN ({$idlist})";
     $db->setQuery($query);
     $results = (array) $db->loadAssocList('id');
     KunenaError::checkDatabaseError();
     foreach ($ids as $id) {
         if (isset($results[$id])) {
             $instance = new KunenaForumTopic($results[$id]);
             $instance->exists(true);
             self::$_instances[$id] = $instance;
         } else {
             self::$_instances[$id] = null;
         }
     }
     unset($results);
 }
예제 #3
0
 /**
  * @param KunenaForumTopic $topic
  * @param int $topicdelta
  * @param int $postdelta
  *
  * @return bool
  */
 public function update($topic, $topicdelta = 0, $postdelta = 0)
 {
     if (!$topic->id) {
         return false;
     }
     $update = false;
     if ($topicdelta || $postdelta) {
         // Update topic and post count
         $this->numTopics += (int) $topicdelta;
         $this->numPosts += (int) $postdelta;
         $update = true;
     }
     if ($topic->exists() && $topic->hold == 0 && $topic->moved_id == 0 && $topic->category_id == $this->id && ($this->last_post_time < $topic->last_post_time || $this->last_post_time == $topic->last_post_time && $this->last_post_id <= $topic->last_post_id)) {
         // If topic has new post or last topic changed, we need to update cache
         $this->last_topic_id = $topic->id;
         $this->last_post_id = $topic->last_post_id;
         $this->last_post_time = $topic->last_post_time;
         $update = true;
     } elseif ($this->last_topic_id == $topic->id) {
         // If last topic/post got moved or deleted, we need to find last post
         $db = JFactory::getDBO();
         $query = "SELECT * FROM #__kunena_topics WHERE category_id={$db->quote($this->id)} AND hold=0 AND moved_id=0 ORDER BY last_post_time DESC, last_post_id DESC";
         $db->setQuery($query, 0, 1);
         $topic = $db->loadObject();
         KunenaError::checkDatabaseError();
         if ($topic) {
             $this->last_topic_id = $topic->id;
             $this->last_post_id = $topic->last_post_id;
             $this->last_post_time = $topic->last_post_time;
             $update = true;
         } else {
             $this->numTopics = 0;
             $this->numPosts = 0;
             $this->last_topic_id = 0;
             $this->last_post_id = 0;
             $this->last_post_time = 0;
             $update = true;
         }
     }
     if (!$update) {
         return true;
     }
     // TODO: remove this hack...
     $this->_noreorder = true;
     return $this->save();
 }
예제 #4
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');
     }
 }