public static function exportCommentsForText($projectId, $textId, $params) { $project = new ProjectModel($projectId); $text = new TextModel($project, $textId); $usxHelper = new UsxHelper($text->content); $textInfo = $usxHelper->getMetadata(); $questionlist = new QuestionAnswersListModel($project, $textId); $questionlist->read(); $dl = array('complete' => true, 'inprogress' => false, 'answerCount' => 0, 'commentCount' => 0, 'totalCount' => 0, 'xml' => "<CommentList>\n"); foreach ($questionlist->entries as $question) { if (!array_key_exists('isArchived', $question) || !$question['isArchived']) { foreach ($question['answers'] as $answerId => $answer) { if (!$params['exportFlagged'] || array_key_exists('isToBeExported', $answer) && $answer['isToBeExported']) { // if the answer is tagged with an export tag $dl['answerCount']++; $dl['xml'] .= self::makeCommentXml($answer['tags'], $answer['score'], $textInfo, $answerId, $answer); if ($params['exportComments']) { foreach ($answer['comments'] as $commentId => $comment) { $dl['xml'] .= self::makeCommentXml(array(), 0, $textInfo, $commentId, $comment); $dl['commentCount']++; } } } } } } $dl['totalCount'] = $dl['answerCount'] + $dl['commentCount']; $dl['xml'] .= "</CommentList>"; $dl['filename'] = 'Comments_sf_' . date('Ymd_Gi') . '.xml'; //$dl['filename'] = preg_replace("([^\w\d\-]|[\.]{2,})", '_', $filename) . '.xml'; return $dl; }
public function testGetMetadata_Ok() { $usx = MongoTestEnvironment::usxSample(); $usxHelper = new UsxHelper($usx); $info = $usxHelper->getMetadata(); $this->assertEqual($info['bookCode'], 'JHN'); $this->assertEqual($info['startChapter'], 1); $this->assertEqual($info['endChapter'], 21); $this->assertEqual($info['startVerse'], 1); $this->assertEqual($info['endVerse'], 25); }