1 | <?php |
||||
2 | /** |
||||
3 | * @package Polls |
||||
4 | * @category modules |
||||
5 | * @author Nazar Mokrynskyi <[email protected]> |
||||
6 | * @license 0BSD |
||||
7 | */ |
||||
8 | namespace cs\modules\Polls; |
||||
9 | use |
||||
10 | cs\Config, |
||||
11 | cs\User, |
||||
12 | cs\CRUD, |
||||
13 | cs\Singleton; |
||||
14 | |||||
15 | /** |
||||
16 | * @method static $this instance($check = false) |
||||
17 | */ |
||||
18 | class Answers { |
||||
19 | use |
||||
20 | CRUD, |
||||
21 | Singleton; |
||||
22 | |||||
23 | protected $data_model = [ |
||||
24 | 'id' => 'int', |
||||
25 | 'option' => 'int', |
||||
26 | 'user' => 'int' |
||||
27 | ]; |
||||
28 | protected $table = '[prefix]polls_options_answers'; |
||||
29 | |||||
30 | protected function cdb () { |
||||
31 | return Config::instance()->module('Polls')->db('polls'); |
||||
32 | } |
||||
33 | /** |
||||
34 | * Add new answer |
||||
35 | * |
||||
36 | * @param $poll |
||||
37 | * @param $option |
||||
38 | * |
||||
39 | * @return bool |
||||
40 | */ |
||||
41 | public function add ($poll, $option) { |
||||
42 | $User = User::instance(); |
||||
43 | if ($User->guest()) { |
||||
44 | return false; |
||||
45 | } |
||||
46 | $result = $this->create($poll, $option, $User->id); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
47 | if ($result) { |
||||
48 | Options::instance()->update_votes($option); |
||||
49 | return true; |
||||
50 | } |
||||
51 | return false; |
||||
52 | } |
||||
53 | /** |
||||
54 | * Get answer |
||||
55 | * |
||||
56 | * @param int|int[] $poll |
||||
57 | * @param false|int $user |
||||
58 | * |
||||
59 | * @return int|int[]|false Option id |
||||
60 | */ |
||||
61 | public function get ($poll, $user = false) { |
||||
62 | if (is_array($poll)) { |
||||
63 | return array_map_arguments([$this, 'get'], $poll, $user); |
||||
0 ignored issues
–
show
$user of type integer|false is incompatible with the type array expected by parameter $additional_arguments of array_map_arguments() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
64 | } |
||||
65 | return $this->db()->qfs( |
||||
66 | "SELECT `option` |
||||
0 ignored issues
–
show
'SELECT `option` FROM...ser` = '%d' LIMIT 1' of type string is incompatible with the type string[] expected by parameter $query of cs\DB\_Abstract::qfs() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
67 | FROM `$this->table` |
||||
68 | WHERE |
||||
69 | `id` = '%d' AND |
||||
70 | `user` = '%d' |
||||
71 | LIMIT 1", |
||||
72 | $poll, |
||||
0 ignored issues
–
show
$poll of type integer is incompatible with the type string[] expected by parameter $query of cs\DB\_Abstract::qfs() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
73 | $user ?: User::instance()->id |
||||
74 | ); |
||||
75 | } |
||||
76 | } |
||||
77 |