Conditions | 5 |
Paths | 9 |
Total Lines | 25 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
9 | public function getAnswersByQuestionsById(array $questions): array |
||
10 | { |
||
11 | if (empty($questions)) { |
||
12 | return []; |
||
13 | } |
||
14 | |||
15 | $where = ''; |
||
16 | foreach ($questions as $key => $value) { |
||
17 | $where .= ' OR question_id = :question_id_'.md5($value['id']); |
||
18 | } |
||
19 | |||
20 | $stmt = $this->db->prepare('SELECT * FROM answers WHERE '.trim($where, ' OR ')); |
||
21 | foreach ($questions as $key => $value) { |
||
22 | $stmt->bindValue(':question_id_'.md5($value['id']), $value['id'], PDO::PARAM_INT); |
||
23 | } |
||
24 | |||
25 | $stmt->execute(); |
||
26 | |||
27 | $array = []; |
||
28 | foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $key => $value) { |
||
29 | $array[$value['question_id']][] = $value; |
||
30 | } |
||
31 | |||
32 | return $array; |
||
33 | } |
||
34 | |||
44 |