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

DBStaticSurveyAnswer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 55
ccs 0
cts 28
cp 0
rs 10
wmc 5
lcom 0
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A db_survey_answer_insert() 0 6 1
A db_survey_answer_text_select_by_news() 0 3 1
A db_survey_answers_get_list_by_parent() 0 5 1
A db_survey_get_answer_texts() 0 12 1
A db_survey_answer_get() 0 5 1
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
}