/**
  * Constructs a post object and (recursively) all of its children from
  * information retrieved from the database.
  * @param $posts Array of post ID => fields from DB query
  * @param $children Array of post ID => array of child IDs
  * @param $id ID of post to construct
  * @param $parent Parent post or NULL if none
  * @return forum_post Newly-created post
  * @throws forum_exception If ID is invalid
  */
 private function build_posts(&$posts, &$children, $id, $parent)
 {
     if (!array_key_exists($id, $posts)) {
         $msg = "No such post: {$id} (discussion " . $this->get_id() . '); ' . 'posts';
         foreach ($posts as $id => $junk) {
             $msg .= ' ' . $id;
         }
         $msg .= '; children';
         foreach ($children as $id => $junk) {
             $msg .= ' ' . $id;
         }
         throw new forum_exception($msg);
     }
     $post = new forum_post($this, $posts[$id], $parent);
     $post->init_children();
     if (array_key_exists($id, $children)) {
         foreach ($children[$id] as $childid) {
             $post->add_child($this->build_posts($posts, $children, $childid, $post));
         }
     }
     return $post;
 }