/** * @param string $projectId * @param string $textId * @param string $userId * @returns array - the DTO array */ public static function encode($projectId, $textId, $userId) { $user = new UserModel($userId); $project = new SfchecksProjectModel($projectId); $text = new TextModel($project, $textId); $questionList = new QuestionAnswersListModel($project, $textId); $questionList->read(); $data = array(); $data['text'] = JsonEncoder::encode($text); $data['archivedQuestions'] = array(); foreach ($questionList->entries as $questionData) { $question = new QuestionModel($project, $questionData['id']); if ($question->isArchived) { // Just want answer count, not whole list $questionData['answerCount'] = count($questionData['answers']); $responseCount = 0; // "Reponses" = answers + comments foreach ($questionData['answers'] as $a) { $commentCount = count($a['comments']); $responseCount += $commentCount + 1; // +1 for this answer } $questionData['responseCount'] = $responseCount; unset($questionData['answers']); $questionData['dateModified'] = $question->dateModified->asDateTimeInterface()->format(\DateTime::RFC2822); $data['archivedQuestions'][] = $questionData; } } $data['rights'] = RightsHelper::encode($user, $project); $data['bcs'] = BreadCrumbHelper::encode('settings', $project, $text, null); return $data; }
/** * @param string $projectId * @param string $userId * @returns array - the DTO array */ public static function encode($projectId, $userId) { $userModel = new UserModel($userId); $projectModel = new SfchecksProjectModel($projectId); $textList = new TextListModel($projectModel); $textList->read(); $list = $projectModel->listUsers(); $data = array(); $data['count'] = count($list->entries); $data['entries'] = array_values($list->entries); // re-index array $data['project'] = ProjectSettingsDtoEncoder::encode($projectModel); unset($data['project']['users']); $data['archivedTexts'] = array(); foreach ($textList->entries as $entry) { $textModel = new TextModel($projectModel, $entry['id']); if ($textModel->isArchived) { $questionList = $textModel->listQuestionsWithAnswers(); // Just want count of questions and responses, not whole list $entry['questionCount'] = $questionList->count; $responseCount = 0; // "Responses" = answers + comments foreach ($questionList->entries as $q) { foreach ($q['answers'] as $a) { $commentCount = count($a['comments']); $responseCount += $commentCount + 1; // +1 for this answer } } $entry['responseCount'] = $responseCount; $entry['dateModified'] = $textModel->dateModified->asDateTimeInterface()->format(\DateTime::RFC2822); $data['archivedTexts'][] = $entry; } } $data['rights'] = RightsHelper::encode($userModel, $projectModel); $data['bcs'] = BreadCrumbHelper::encode('settings', $projectModel, null, null); return $data; }