@@ -102,11 +102,15 @@ |
||
| 102 | 102 | /** |
| 103 | 103 | * Get user option, or default option if it does not exist. |
| 104 | 104 | * @param string $option |
| 105 | - * @return mixed Returns option value as STRING, or FALSE if option does not exist. |
|
| 105 | + * @return string Returns option value as STRING, or FALSE if option does not exist. |
|
| 106 | 106 | */ |
| 107 | 107 | public function get(string $option) { |
| 108 | 108 | return $this->get_by_userid($option, (int) $this->User->id); |
| 109 | 109 | } |
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @return string |
|
| 113 | + */ |
|
| 110 | 114 | public function get_by_userid(string $option, int $userID) { |
| 111 | 115 | //Check if option is valid |
| 112 | 116 | if(array_key_exists($option, $this->options)) { |
@@ -170,10 +170,10 @@ |
||
| 170 | 170 | //This function assumes we've already done some basic validation. |
| 171 | 171 | if(!($data = $this->session->tempdata("option_{$option}"))) { |
| 172 | 172 | $query = $this->db->select('value_str, value_int') |
| 173 | - ->from('user_options') |
|
| 174 | - ->where('user_id', $userID) |
|
| 175 | - ->where('name', $option) |
|
| 176 | - ->limit(1); |
|
| 173 | + ->from('user_options') |
|
| 174 | + ->where('user_id', $userID) |
|
| 175 | + ->where('name', $option) |
|
| 176 | + ->limit(1); |
|
| 177 | 177 | $data = $query->get()->row_array(); |
| 178 | 178 | $this->session->set_tempdata("option_{$option}", $data, 3600); |
| 179 | 179 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); defined('BASEPATH') or exit('No direct script access allowed'); |
|
| 1 | +<?php declare(strict_types = 1); defined('BASEPATH') or exit('No direct script access allowed'); |
|
| 2 | 2 | |
| 3 | 3 | class User_Options_Model extends CI_Model { |
| 4 | 4 | public $options = array( |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | $query = $this->db->select('value_str, value_int') |
| 173 | 173 | ->from('user_options') |
| 174 | 174 | ->where('user_id', $userID) |
| 175 | - ->where('name', $option) |
|
| 175 | + ->where('name', $option) |
|
| 176 | 176 | ->limit(1); |
| 177 | 177 | $data = $query->get()->row_array(); |
| 178 | 178 | $this->session->set_tempdata("option_{$option}", $data, 3600); |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | ); |
| 215 | 215 | //FIXME: Get a better solution than str_replace for removing special characters |
| 216 | 216 | $elements = array(); |
| 217 | - foreach (array_values($this->options[$option]['valid_options']) as $valid_option) { |
|
| 217 | + foreach(array_values($this->options[$option]['valid_options']) as $valid_option) { |
|
| 218 | 218 | $elements[$option.'_'.str_replace(',', '_', $valid_option)] = array_merge($base_attributes, array( |
| 219 | 219 | 'value' => $valid_option |
| 220 | 220 | )); |
@@ -123,7 +123,9 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | //Overall fallback method. |
| 126 | - if(!isset($value)) $value = $this->options[$option]['default']; |
|
| 126 | + if(!isset($value)) { |
|
| 127 | + $value = $this->options[$option]['default']; |
|
| 128 | + } |
|
| 127 | 129 | } else { |
| 128 | 130 | $value = FALSE; |
| 129 | 131 | } |
@@ -159,7 +161,9 @@ discard block |
||
| 159 | 161 | $success = $this->db->update('user_options', $dataValues); |
| 160 | 162 | } |
| 161 | 163 | |
| 162 | - if($success) $this->session->unset_tempdata("option_{$option}"); |
|
| 164 | + if($success) { |
|
| 165 | + $this->session->unset_tempdata("option_{$option}"); |
|
| 166 | + } |
|
| 163 | 167 | } else { |
| 164 | 168 | $success = FALSE; |
| 165 | 169 | } |
@@ -200,7 +204,10 @@ discard block |
||
| 200 | 204 | //This should never happen. |
| 201 | 205 | break; |
| 202 | 206 | } |
| 203 | - if(!isset($value)) $value = FALSE; //FIXME: This won't play nice with BOOL type false? |
|
| 207 | + if(!isset($value)) { |
|
| 208 | + $value = FALSE; |
|
| 209 | + } |
|
| 210 | + //FIXME: This won't play nice with BOOL type false? |
|
| 204 | 211 | |
| 205 | 212 | return $value; |
| 206 | 213 | } |