original_string: public function get_replies_to_post(
          stdClass $user,
          post_entity $post,
          bool $canseeprivatereplies,
          string $orderby = 'created ASC'
      ) : array {
          $alias = $this->get_table_alias();
  
          [
              'where' => $privatewhere,
              'params' => $privateparams,
          ] = $this->get_private_reply_sql($user, $canseeprivatereplies);
  
          $params = array_merge([
              'discussionid' => $post->get_discussion_id(),
              'created' => $post->get_time_created(),
              'excludepostid' => $post->get_id(),
          ], $privateparams);
  
          // Unfortunately the best we can do to filter down the query is ignore all posts
          // that were created before the given post (since they can't be replies).
          // We also filter to remove private replies if the user cannot vie them.
          $wheresql = "{$alias}.discussion = :discussionid
                   AND {$alias}.created >= :created {$privatewhere}
                   AND {$alias}.id != :excludepostid";
          $orderbysql = $alias . '.' . $orderby;
          $sql = $this->generate_get_records_sql($wheresql, $orderbysql);
          $records = $this->get_db()->get_records_sql($sql, $params);
          $posts = $this->transform_db_records_to_entities($records);
          $sorter = $this->get_entity_factory()->get_posts_sorter();
  
          // We need to sort all of the values into the replies tree in order to capture
          // the full list of descendants.
          $sortedposts = $sorter->sort_into_children($posts);
          $replies = [];
  
          // From the sorted list we can grab the first elements and check if they are replies
          // to the post we care about. If so we keep them.
          foreach ($sortedposts as $candidate) {
              [$candidatepost, $candidatereplies] = $candidate;
              if ($candidatepost->has_parent() && $candidatepost->get_parent_id() == $post->get_id()) {
                  $replies[] = $candidate;
              }
          }
  
          if (empty($replies)) {
              return $replies;
          }
  
          $getreplypostids = function($candidates) use (&$getreplypostids) {
              $ids = [];
  
              foreach ($candidates as $candidate) {
                  [$reply, $replies] = $candidate;
                  $ids = array_merge($ids, [$reply->get_id()], $getreplypostids($replies));
              }
  
              return $ids;
          };
          // Recursively build a list of the ids of all posts in the full reply tree.
          $replypostids = $getreplypostids($replies);
  
          // Now go back and filter the original result set down to just the posts that
          // we've flagged as in the reply tree. We need to filter the original set of values
          // so that we can maintain the requested sort order.
          return array_values(array_filter($posts, function($post) use ($replypostids) {
              return in_array($post->get_id(), $replypostids);
          }));
      }
code: public function get_replies_to_post(
          stdClass $user,
          post_entity $post,
          bool $canseeprivatereplies,
          string $orderby = 'created ASC'
      ) : array {
          $alias = $this->get_table_alias();
  
          [
              'where' => $privatewhere,
              'params' => $privateparams,
          ] = $this->get_private_reply_sql($user, $canseeprivatereplies);
  
          $params = array_merge([
              'discussionid' => $post->get_discussion_id(),
              'created' => $post->get_time_created(),
              'excludepostid' => $post->get_id(),
          ], $privateparams);
  
          // Unfortunately the best we can do to filter down the query is ignore all posts
          // that were created before the given post (since they can't be replies).
          // We also filter to remove private replies if the user cannot vie them.
          $wheresql = "{$alias}.discussion = :discussionid
                   AND {$alias}.created >= :created {$privatewhere}
                   AND {$alias}.id != :excludepostid";
          $orderbysql = $alias . '.' . $orderby;
          $sql = $this->generate_get_records_sql($wheresql, $orderbysql);
          $records = $this->get_db()->get_records_sql($sql, $params);
          $posts = $this->transform_db_records_to_entities($records);
          $sorter = $this->get_entity_factory()->get_posts_sorter();
  
          // We need to sort all of the values into the replies tree in order to capture
          // the full list of descendants.
          $sortedposts = $sorter->sort_into_children($posts);
          $replies = [];
  
          // From the sorted list we can grab the first elements and check if they are replies
          // to the post we care about. If so we keep them.
          foreach ($sortedposts as $candidate) {
              [$candidatepost, $candidatereplies] = $candidate;
              if ($candidatepost->has_parent() && $candidatepost->get_parent_id() == $post->get_id()) {
                  $replies[] = $candidate;
              }
          }
  
          if (empty($replies)) {
              return $replies;
          }
  
          $getreplypostids = function($candidates) use (&$getreplypostids) {
              $ids = [];
  
              foreach ($candidates as $candidate) {
                  [$reply, $replies] = $candidate;
                  $ids = array_merge($ids, [$reply->get_id()], $getreplypostids($replies));
              }
  
              return $ids;
          };
          // Recursively build a list of the ids of all posts in the full reply tree.
          $replypostids = $getreplypostids($replies);
  
          // Now go back and filter the original result set down to just the posts that
          // we've flagged as in the reply tree. We need to filter the original set of values
          // so that we can maintain the requested sort order.
          return array_values(array_filter($posts, function($post) use ($replypostids) {
              return in_array($post->get_id(), $replypostids);
          }));
      }
code_tokens: public function get_replies_to_post ( stdClass $ user , post_entity $ post , bool $ canseeprivatereplies , string $ orderby = 'created ASC' ) : array { $ alias = $ this -> get_table_alias ( ) ; [ 'where' => $ privatewhere , 'params' => $ privateparams , ] = $ this -> get_private_reply_sql ( $ user , $ canseeprivatereplies ) ; $ params = array_merge ( [ 'discussionid' => $ post -> get_discussion_id ( ) , 'created' => $ post -> get_time_created ( ) , 'excludepostid' => $ post -> get_id ( ) , ] , $ privateparams ) ; // Unfortunately the best we can do to filter down the query is ignore all posts // that were created before the given post (since they can't be replies). // We also filter to remove private replies if the user cannot vie them. $ wheresql = "{$alias}.discussion = :discussionid
                   AND {$alias}.created >= :created {$privatewhere}
                   AND {$alias}.id != :excludepostid" ; $ orderbysql = $ alias . '.' . $ orderby ; $ sql = $ this -> generate_get_records_sql ( $ wheresql , $ orderbysql ) ; $ records = $ this -> get_db ( ) -> get_records_sql ( $ sql , $ params ) ; $ posts = $ this -> transform_db_records_to_entities ( $ records ) ; $ sorter = $ this -> get_entity_factory ( ) -> get_posts_sorter ( ) ; // We need to sort all of the values into the replies tree in order to capture // the full list of descendants. $ sortedposts = $ sorter -> sort_into_children ( $ posts ) ; $ replies = [ ] ; // From the sorted list we can grab the first elements and check if they are replies // to the post we care about. If so we keep them. foreach ( $ sortedposts as $ candidate ) { [ $ candidatepost , $ candidatereplies ] = $ candidate ; if ( $ candidatepost -> has_parent ( ) && $ candidatepost -> get_parent_id ( ) == $ post -> get_id ( ) ) { $ replies [ ] = $ candidate ; } } if ( empty ( $ replies ) ) { return $ replies ; } $ getreplypostids = function ( $ candidates ) use ( & $ getreplypostids ) { $ ids = [ ] ; foreach ( $ candidates as $ candidate ) { [ $ reply , $ replies ] = $ candidate ; $ ids = array_merge ( $ ids , [ $ reply -> get_id ( ) ] , $ getreplypostids ( $ replies ) ) ; } return $ ids ; } ; // Recursively build a list of the ids of all posts in the full reply tree. $ replypostids = $ getreplypostids ( $ replies ) ; // Now go back and filter the original result set down to just the posts that // we've flagged as in the reply tree. We need to filter the original set of values // so that we can maintain the requested sort order. return array_values ( array_filter ( $ posts , function ( $ post ) use ( $ replypostids ) { return in_array ( $ post -> get_id ( ) , $ replypostids ) ; } ) ) ; }
docstring: Load a list of replies to the given post. This will load all descendants of the post.
  That is, all direct replies and replies to those replies etc.
  
  The return value will be a flat array of posts in the requested order.
  
  @param stdClass    $user The user to check the unread count for
  @param post_entity $post The post to load replies for
  @param bool        $canseeprivatereplies Whether this user can see all private replies or not
  @param string $orderby How to order the replies
  @return post_entity[]
docstring_tokens: Load a list of replies to the given post . This will load all descendants of the post . That is all direct replies and replies to those replies etc .