function get_topic($all_posts = false) { if (!$this->_topic) { if ($this->post_id) { //existing post, load existing topic $this->_topic = topic::get($this->topic_id, $all_posts); //insert $this into topic->posts array if ($all_posts) { //this post was also loaded from database, replace it with $this for ($i = 0; $i < sizeof($this->_topic->posts); $i++) { if ($this->_topic->posts[$i]->post_id == $this->post_id) { //found it $this->_topic->posts[$i] =& $this; break; } } } else { //no posts were loaded in topic::get(), add our post to topic->posts $this->_topic->posts[] =& $this; } } else { //new post, generate topic $this->_topic = topic::from_post($this); } } return $this->_topic; }
/** * * @param array $post * @return boolean|\Gn36\OoPostingApi\topic */ static function from_post(post $post) { if ($post->topic_id != NULL) { return topic::get($post->topic_id); } $topic = new topic(); $topic->topic_id = $post->topic_id; $topic->forum_id = $post->forum_id; $topic->topic_title = $post->post_subject; $topic->topic_poster = $post->poster_id; $topic->topic_time = $post->post_time; $topic->icon_id = $post->icon_id; $topic->topic_attachment = $post->post_attachment; $topic->topic_posts_approved = $post->post_visibility == ITEM_APPROVED ? 1 : 0; $topic->topic_posts_unapproved = $post->post_visibility == ITEM_UNAPPROVED ? 1 : 0; $topic->topic_posts_softdeleted = $post->post_visibility == ITEM_DELETED ? 1 : 0; $topic->topic_delete_user = $post->post_delete_user; $topic->topic_delete_reason = $post->post_delete_reason; $topic->topic_delete_time = $post->post_delete_time; $topic->topic_reported = $post->post_reported; $topic->topic_first_post_id = $post->post_id; $topic->topic_first_poster_colour = ''; $topic->topic_first_poster_name = ''; $topic->topic_last_post_subject = $post->post_subject; $topic->topic_last_post_time = $post->post_time; $topic->topic_last_poster_colour = ''; $topic->topic_last_poster_id = $post->poster_id; $topic->topic_last_poster_name = ''; $topic->topic_last_view_time = time(); $topic->posts[] =& $post; return $topic; }