public function formatApi(Workflow $listWorkflow, array $found, IContextSource $ctx)
 {
     $roots = $revisions = $posts = $replies = array();
     foreach ($found as $formatterRow) {
         $serialized = $this->serializer->formatApi($formatterRow, $ctx);
         if (!$serialized) {
             continue;
         }
         $revisions[$serialized['revisionId']] = $serialized;
         $posts[$serialized['postId']][] = $serialized['revisionId'];
         if ($serialized['replyToId']) {
             $replies[$serialized['replyToId']][] = $serialized['postId'];
         } else {
             $roots[] = $serialized['postId'];
         }
     }
     foreach ($revisions as $i => $serialized) {
         $alpha = $serialized['postId'];
         $revisions[$i]['replies'] = isset($replies[$alpha]) ? $replies[$alpha] : array();
     }
     $alpha = $listWorkflow->getId()->getAlphadecimal();
     $workflows = array($alpha => $listWorkflow);
     if (isset($posts[$alpha])) {
         // Metadata that requires everything to be serialized first
         $metadata = $this->generateTopicMetadata($posts, $revisions, $workflows, $alpha);
         foreach ($posts[$alpha] as $revId) {
             $revisions[$revId] += $metadata;
         }
     }
     return array('roots' => $roots, 'posts' => $posts, 'revisions' => $revisions) + $this->getEmptyResult($listWorkflow);
 }
 /**
  * @param FormatterRow $row
  * @param IContextSource $ctx
  * @return array
  */
 public function formatApi(FormatterRow $row, IContextSource $ctx)
 {
     $res = $this->serializer->formatApi($row, $ctx);
     $res['rev_view_links'] = $this->buildLinks($row, $ctx);
     $res['human_timestamp'] = $this->getHumanTimestamp($res['timestamp']);
     if ($row->revision instanceof PostRevision) {
         $res['properties']['topic-of-post'] = $this->serializer->processParam('topic-of-post', $row->revision, $row->workflow->getId(), $ctx);
     }
     if ($row->revision instanceof PostSummary) {
         $res['properties']['post-of-summary'] = $this->serializer->processParam('post-of-summary', $row->revision, $row->workflow->getId(), $ctx);
     }
     return $res;
 }
 /**
  * Method is called from static::formatApi & ApiFlowSearch::formatApi, to ensure
  * both have similar output.
  *
  * @param Workflow[] $workflows
  * @param FormatterRow[] $found
  * @param IContextSource $ctx
  * @return array
  */
 public function buildResult(array $workflows, array $found, IContextSource $ctx)
 {
     $revisions = $posts = $replies = array();
     foreach ($found as $formatterRow) {
         $serialized = $this->serializer->formatApi($formatterRow, $ctx);
         if (!$serialized) {
             continue;
         }
         $revisions[$serialized['revisionId']] = $serialized;
         $posts[$serialized['postId']][] = $serialized['revisionId'];
         $replies[$serialized['replyToId']][] = $serialized['postId'];
     }
     foreach ($revisions as $i => $serialized) {
         $alpha = $serialized['postId'];
         $revisions[$i]['replies'] = isset($replies[$alpha]) ? $replies[$alpha] : array();
     }
     $list = array();
     if ($workflows) {
         $orig = $workflows;
         $workflows = array();
         foreach ($orig as $workflow) {
             $alpha = $workflow->getId()->getAlphadecimal();
             if (isset($posts[$alpha])) {
                 $list[] = $alpha;
                 $workflows[$alpha] = $workflow;
             } else {
                 wfDebugLog('Flow', __METHOD__ . ": No matching root post for workflow {$alpha}");
             }
         }
         foreach ($list as $alpha) {
             // Metadata that requires everything to be serialied first
             $metadata = $this->generateTopicMetadata($posts, $revisions, $workflows, $alpha, $ctx);
             foreach ($posts[$alpha] as $revId) {
                 $revisions[$revId] += $metadata;
             }
         }
     }
     return array('roots' => $list, 'posts' => $posts, 'revisions' => $revisions);
 }