| Total Complexity | 7 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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); |
||
|
|
|||
| 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) { |
||
| 74 | ); |
||
| 75 | } |
||
| 76 | } |
||
| 77 |