Exemplo n.º 1
0
    public function _get_post_count($topic_id)
    {
        $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
			WHERE topic_id = ' . (int) $topic_id . '
				AND post_access = ' . TITANIA_ACCESS_TEAMS . '
				AND post_deleted = 0
				AND post_approved = 1';
        $result = phpbb::$db->sql_query($sql);
        $teams = phpbb::$db->sql_fetchfield('cnt', $result);
        phpbb::$db->sql_freeresult($result);
        $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
			WHERE topic_id = ' . (int) $topic_id . '
				AND post_access = ' . TITANIA_ACCESS_AUTHORS . '
				AND post_deleted = 0
				AND post_approved = 1';
        $result = phpbb::$db->sql_query($sql);
        $authors = phpbb::$db->sql_fetchfield('cnt', $result);
        phpbb::$db->sql_freeresult($result);
        $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
			WHERE topic_id = ' . (int) $topic_id . '
				AND post_access = ' . TITANIA_ACCESS_PUBLIC . '
				AND post_deleted = 0
				AND post_approved = 1';
        $result = phpbb::$db->sql_query($sql);
        $public = phpbb::$db->sql_fetchfield('cnt', $result);
        phpbb::$db->sql_freeresult($result);
        $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
			WHERE topic_id = ' . (int) $topic_id . '
				AND post_deleted <> 0';
        $result = phpbb::$db->sql_query($sql);
        $deleted = phpbb::$db->sql_fetchfield('cnt', $result);
        phpbb::$db->sql_freeresult($result);
        $sql = 'SELECT COUNT(post_id) AS cnt FROM ' . TITANIA_POSTS_TABLE . '
			WHERE topic_id = ' . (int) $topic_id . '
				AND post_deleted = 0
				AND post_approved = 0';
        $result = phpbb::$db->sql_query($sql);
        $unapproved = phpbb::$db->sql_fetchfield('cnt', $result);
        phpbb::$db->sql_freeresult($result);
        return titania_count::to_db(array('teams' => $teams, 'authors' => $authors, 'public' => $public, 'deleted' => $deleted, 'unapproved' => $unapproved));
    }
Exemplo n.º 2
0
 /**
  * Update postcount on the parent topic
  */
 public function update_topic_postcount($hard_delete = false)
 {
     // shouldn't need to load through load() to delete it...
     if ($hard_delete && empty($this->sql_data)) {
         $this->sql_data = $this->__get_array();
     }
     if ($this->post_id && empty($this->sql_data)) {
         throw new exception('Modifying a post requires you load it through the load() function (we require the original information).');
     }
     // Get the current count
     $to_db = titania_count::from_db($this->topic->topic_posts, false);
     // Revert the old count from this post
     if ($this->post_id) {
         if ($this->sql_data['post_deleted'] != 0) {
             $to_db['deleted']--;
         } else {
             if (!$this->sql_data['post_approved']) {
                 $to_db['unapproved']--;
             } else {
                 switch ($this->sql_data['post_access']) {
                     case TITANIA_ACCESS_PUBLIC:
                         $to_db['public']--;
                         break;
                     case TITANIA_ACCESS_AUTHORS:
                         $to_db['authors']--;
                         break;
                     case TITANIA_ACCESS_TEAMS:
                         $to_db['teams']--;
                         break;
                 }
             }
         }
     }
     // Then recount those options for this post if we are not hard deleting it.
     if (!$hard_delete) {
         if ($this->post_deleted != 0) {
             $to_db['deleted']++;
         } else {
             if (!$this->post_approved) {
                 $to_db['unapproved']++;
             } else {
                 switch ($this->post_access) {
                     case TITANIA_ACCESS_PUBLIC:
                         $to_db['public']++;
                         break;
                     case TITANIA_ACCESS_AUTHORS:
                         $to_db['authors']++;
                         break;
                     case TITANIA_ACCESS_TEAMS:
                         $to_db['teams']++;
                         break;
                 }
             }
         }
     }
     // Update the field on the topic
     $this->topic->topic_posts = titania_count::to_db($to_db);
 }