diff options
author | Michael Weimann <mail@michael-weimann.eu> | 2019-12-03 20:09:45 +0100 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2019-12-07 21:29:11 +0100 |
commit | e16e0b2644172f098956f6c970e86581e2e758c1 (patch) | |
tree | 6218bff227b508df61c7184dbbcb287bf2612e8f /includes/view | |
parent | 4f63bbbaacd0db3636f1169f5ad29f1cfb21615b (diff) |
Migrate Question usages
Diffstat (limited to 'includes/view')
-rw-r--r-- | includes/view/Questions_view.php | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/includes/view/Questions_view.php b/includes/view/Questions_view.php index 4d57edf9..a4c3a452 100644 --- a/includes/view/Questions_view.php +++ b/includes/view/Questions_view.php @@ -1,27 +1,46 @@ <?php +use Engelsystem\Models\Question; + /** - * @param array[] $open_questions - * @param array[] $answered_questions + * @param Question[] $open_questions + * @param Question[] $answered_questions * @param string $ask_action * @return string */ -function Questions_view($open_questions, $answered_questions, $ask_action) +function Questions_view(array $open_questions, array $answered_questions, $ask_action) { - foreach ($open_questions as &$question) { - $question['actions'] = form([ - form_submit('submit', __('delete'), 'btn-default btn-xs') - ], page_link_to('user_questions', ['action' => 'delete', 'id' => $question['QID']])); - $question['Question'] = nl2br(htmlspecialchars($question['Question'])); - } + $open_questions = array_map( + static function (Question $question): array { + return [ + 'actions' => form( + [ + form_submit('submit', __('delete'), 'btn-default btn-xs') + ], + page_link_to('user_questions', ['action' => 'delete', 'id' => $question->id]) + ), + 'Question' => nl2br(htmlspecialchars($question->text)), + ]; + }, + $open_questions + ); - foreach ($answered_questions as &$question) { - $question['Question'] = nl2br(htmlspecialchars($question['Question'])); - $question['Answer'] = nl2br(htmlspecialchars($question['Answer'])); - $question['actions'] = form([ - form_submit('submit', __('delete'), 'btn-default btn-xs') - ], page_link_to('user_questions', ['action' => 'delete', 'id' => $question['QID']])); - } + $answered_questions = array_map( + static function (Question $question): array { + return [ + 'Question' => nl2br(htmlspecialchars($question->text)), + 'Answer' => nl2br(htmlspecialchars($question->answer)), + 'answer_user' => User_Nick_render($question->answerer), + 'actions' => form( + [ + form_submit('submit', __('delete'), 'btn-default btn-xs') + ], + page_link_to('user_questions', ['action' => 'delete', 'id' => $question->id]) + ), + ]; + }, + $answered_questions + ); return page_with_title(questions_title(), [ msg(), |