Completed
Push — work-fleets ( d7065d...1ee481 )
by SuperNova.WS
08:22
created

DBStaticSurveyAnswer::db_survey_answer_insert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 2
rs 9.4285
1
<?php
2
3
namespace DBStatic;
4
use classSupernova;
5
use mysqli_result;
6
7
class DBStaticSurveyAnswer {
8
9
  public static function db_survey_answer_insert($survey_id, $survey_answer_text_unsafe) {
10
    classSupernova::$db->doInsertSet(TABLE_SURVEY_ANSWERS, array(
11
      'survey_parent_id'   => $survey_id,
12
      'survey_answer_text' => $survey_answer_text_unsafe,
13
    ));
14
  }
15
16
  public static function db_survey_answer_text_select_by_news($announce) {
17
    return classSupernova::$db->doSelect("SELECT survey_answer_text FROM {{survey_answers}} WHERE survey_parent_id = {$announce['survey_id']};");
18
  }
19
20
  /**
21
   * @param $announce
22
   *
23
   * @return array|bool|mysqli_result|null
24
   */
25
  public static function db_survey_answers_get_list_by_parent($announce) {
26
    $survey_query = classSupernova::$db->doSelect("SELECT * FROM {{survey_answers}} WHERE survey_parent_id  = {$announce['survey_id']} ORDER BY survey_answer_id;");
27
28
    return $survey_query;
29
  }
30
31
  /**
32
   * @param $announce
33
   *
34
   * @return array|bool|mysqli_result|null
35
   */
36
  public static function db_survey_get_answer_texts($announce) {
37
    $survey_query = classSupernova::$db->doSelect(
38
      "SELECT survey_answer_text AS `TEXT`, count(DISTINCT survey_vote_id) AS `VOTES`
39
          FROM `{{survey_answers}}` AS sa
40
            LEFT JOIN `{{survey_votes}}` AS sv ON sv.survey_parent_answer_id = sa.survey_answer_id
41
          WHERE sa.survey_parent_id = {$announce['survey_id']}
42
          GROUP BY survey_answer_id
43
          ORDER BY survey_answer_id;"
44
    );
45
46
    return $survey_query;
47
  }
48
49
  /**
50
   * @param $survey_id
51
   * @param $survey_vote_id
52
   *
53
   * @return array|bool|mysqli_result|null
54
   */
55
  public static function db_survey_answer_get($survey_id, $survey_vote_id) {
56
    $is_answer_exists = classSupernova::$db->doSelectFetch("SELECT `survey_answer_id` FROM `{{survey_answers}}` WHERE survey_parent_id = {$survey_id} AND survey_answer_id = {$survey_vote_id};");
57
58
    return $is_answer_exists;
59
  }
60
61
}