@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -class OctaORM{ |
|
| 2 | +class OctaORM { |
|
| 3 | 3 | |
| 4 | 4 | protected $redbean; |
| 5 | 5 | protected $db_field; |
@@ -29,19 +29,19 @@ discard block |
||
| 29 | 29 | var $num_rows; |
| 30 | 30 | var $result; |
| 31 | 31 | |
| 32 | - public function __construct($db){ |
|
| 32 | + public function __construct($db) { |
|
| 33 | 33 | include_once('RedBean.php'); |
| 34 | 34 | $this->redbean = new R(); |
| 35 | 35 | $this->db_field = $db; |
| 36 | 36 | |
| 37 | - if(!$this->redbean->testConnection()){ |
|
| 37 | + if (!$this->redbean->testConnection()) { |
|
| 38 | 38 | $conn = $this->initiate_database_connection($db); |
| 39 | 39 | $this->redbean->setup($conn); |
| 40 | - $this->redbean->useFeatureSet( 'novice/latest' ); |
|
| 40 | + $this->redbean->useFeatureSet('novice/latest'); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public function initiate_database_connection($db){ |
|
| 44 | + public function initiate_database_connection($db) { |
|
| 45 | 45 | $DB_HOST = $db['hostname']; |
| 46 | 46 | $DB_USERNAME = $db['username']; |
| 47 | 47 | $DB_PASSWORD = $db['password']; |
@@ -52,24 +52,24 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | $DB_con->exec("CREATE DATABASE IF NOT EXISTS $DB_NAME;"); |
| 54 | 54 | |
| 55 | - $DB_con = new PDO("mysql:host={$DB_HOST};dbname={$DB_NAME}",$DB_USERNAME,$DB_PASSWORD); |
|
| 55 | + $DB_con = new PDO("mysql:host={$DB_HOST};dbname={$DB_NAME}", $DB_USERNAME, $DB_PASSWORD); |
|
| 56 | 56 | $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 57 | 57 | return $DB_con; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public function insert_id(){ |
|
| 60 | + public function insert_id() { |
|
| 61 | 61 | return $this->last_id; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - public function last_query(){ |
|
| 64 | + public function last_query() { |
|
| 65 | 65 | return $this->last_query; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - public function insert($array,$table){ |
|
| 68 | + public function insert($array, $table) { |
|
| 69 | 69 | $data = $this->redbean->dispense($table); |
| 70 | 70 | |
| 71 | - if($array){ |
|
| 72 | - foreach($array as $key=>$row){ |
|
| 71 | + if ($array) { |
|
| 72 | + foreach ($array as $key=>$row) { |
|
| 73 | 73 | $data->$key = $row; |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -78,28 +78,28 @@ discard block |
||
| 78 | 78 | return ($this->last_id) ? true : false; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - public function insert_batch($array,$table){ |
|
| 81 | + public function insert_batch($array, $table) { |
|
| 82 | 82 | $data = array(); |
| 83 | 83 | |
| 84 | - if($array){ |
|
| 85 | - foreach($array as $key_ib=>$row_ib){ |
|
| 84 | + if ($array) { |
|
| 85 | + foreach ($array as $key_ib=>$row_ib) { |
|
| 86 | 86 | |
| 87 | - $data[$key_ib]=$this->redbean->dispense($table); |
|
| 87 | + $data[$key_ib] = $this->redbean->dispense($table); |
|
| 88 | 88 | $table_fields = []; |
| 89 | 89 | $table_fields_val = []; |
| 90 | 90 | |
| 91 | - if($row_ib){ |
|
| 92 | - foreach($row_ib as $row=>$val){ |
|
| 91 | + if ($row_ib) { |
|
| 92 | + foreach ($row_ib as $row=>$val) { |
|
| 93 | 93 | $table_fields[] = $row; |
| 94 | 94 | $table_fields_val[] = $val; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - if($table_fields && $table_fields_val){ |
|
| 98 | - foreach($table_fields as $key=>$row){ |
|
| 97 | + if ($table_fields && $table_fields_val) { |
|
| 98 | + foreach ($table_fields as $key=>$row) { |
|
| 99 | 99 | $data[$key_ib]->$row = $table_fields_val[$key]; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - }else{ |
|
| 102 | + } else { |
|
| 103 | 103 | return false; |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | return ($result) ? true : false; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - public function update($table,$array,$id){ |
|
| 113 | + public function update($table, $array, $id) { |
|
| 114 | 114 | $data = $this->redbean->load($table, $id); |
| 115 | 115 | |
| 116 | - if($array){ |
|
| 117 | - foreach($array as $key=>$row){ |
|
| 116 | + if ($array) { |
|
| 117 | + foreach ($array as $key=>$row) { |
|
| 118 | 118 | $data->$key = $row; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -123,33 +123,33 @@ discard block |
||
| 123 | 123 | return ($result) ? true : false; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function update_batch($table,$array,$where){ |
|
| 127 | - if($array){ |
|
| 128 | - foreach($array as $key_ub=>$row_ub){ |
|
| 126 | + public function update_batch($table, $array, $where) { |
|
| 127 | + if ($array) { |
|
| 128 | + foreach ($array as $key_ub=>$row_ub) { |
|
| 129 | 129 | $where_key = ''; |
| 130 | 130 | $table_fields = []; |
| 131 | 131 | $table_fields_val = []; |
| 132 | 132 | |
| 133 | - if($row_ub){ |
|
| 134 | - foreach($row_ub as $row=>$val){ |
|
| 133 | + if ($row_ub) { |
|
| 134 | + foreach ($row_ub as $row=>$val) { |
|
| 135 | 135 | |
| 136 | - if($row === $where){ |
|
| 136 | + if ($row === $where) { |
|
| 137 | 137 | $where_key = $val; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if($row !== $where){ |
|
| 140 | + if ($row !== $where) { |
|
| 141 | 141 | $table_fields[] = $row; |
| 142 | 142 | $table_fields_val[] = $val; |
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | $data = $this->redbean->load($table, $where_key); |
| 147 | - if($table_fields && $table_fields_val){ |
|
| 148 | - foreach($table_fields as $key=>$row){ |
|
| 147 | + if ($table_fields && $table_fields_val) { |
|
| 148 | + foreach ($table_fields as $key=>$row) { |
|
| 149 | 149 | $data->$row = $table_fields_val[$key]; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - }else{ |
|
| 152 | + } else { |
|
| 153 | 153 | return false; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -161,32 +161,32 @@ discard block |
||
| 161 | 161 | return true; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - public function delete($table,$id){ |
|
| 165 | - if(is_array($id)){ |
|
| 166 | - if($id){ |
|
| 167 | - foreach($id as $key=>$row){ |
|
| 168 | - $this->redbean->trash($table,$row); |
|
| 164 | + public function delete($table, $id) { |
|
| 165 | + if (is_array($id)) { |
|
| 166 | + if ($id) { |
|
| 167 | + foreach ($id as $key=>$row) { |
|
| 168 | + $this->redbean->trash($table, $row); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | return true; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - }else{ |
|
| 175 | - $this->redbean->trash($table,$id); |
|
| 174 | + } else { |
|
| 175 | + $this->redbean->trash($table, $id); |
|
| 176 | 176 | return true; |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - public function delete_all($table){ |
|
| 180 | + public function delete_all($table) { |
|
| 181 | 181 | $result = $this->redbean->wipe($table); |
| 182 | 182 | return ($result) ? true : false; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - public function select($data){ |
|
| 185 | + public function select($data) { |
|
| 186 | 186 | $reset = []; |
| 187 | - if($data){ |
|
| 188 | - foreach($data as $key=>$row){ |
|
| 189 | - array_push($reset,$row); |
|
| 187 | + if ($data) { |
|
| 188 | + foreach ($data as $key=>$row) { |
|
| 189 | + array_push($reset, $row); |
|
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | |
@@ -194,25 +194,25 @@ discard block |
||
| 194 | 194 | return $this->select; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - public function where($data=null,$match=null){ |
|
| 197 | + public function where($data = null, $match = null) { |
|
| 198 | 198 | $tmp_where = ''; |
| 199 | 199 | $arr_check = false; |
| 200 | - if($data){ |
|
| 201 | - if(is_array($data)){ |
|
| 200 | + if ($data) { |
|
| 201 | + if (is_array($data)) { |
|
| 202 | 202 | end($data); |
| 203 | 203 | $last_element = key($data); |
| 204 | 204 | |
| 205 | - if($data){ |
|
| 205 | + if ($data) { |
|
| 206 | 206 | $arr_check = true; |
| 207 | - foreach($data as $key=>$row){ |
|
| 208 | - if($key == $last_element){ |
|
| 207 | + foreach ($data as $key=>$row) { |
|
| 208 | + if ($key == $last_element) { |
|
| 209 | 209 | $tmp_where .= $key."='".$row."'"; |
| 210 | - }else{ |
|
| 210 | + } else { |
|
| 211 | 211 | $tmp_where .= $key."='".$row."' AND "; |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | - }else{ |
|
| 215 | + } else { |
|
| 216 | 216 | $arr_check = false; |
| 217 | 217 | $tmp_where = "WHERE ".$data."='".$match."'"; |
| 218 | 218 | } |
@@ -221,25 +221,25 @@ discard block |
||
| 221 | 221 | $this->where = ($arr_check) ? "WHERE ".$tmp_where : $tmp_where; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - public function or_where($data=null,$match=null){ |
|
| 224 | + public function or_where($data = null, $match = null) { |
|
| 225 | 225 | $tmp_or_where = ''; |
| 226 | 226 | $arr_check = false; |
| 227 | - if($data){ |
|
| 228 | - if(is_array($data)){ |
|
| 227 | + if ($data) { |
|
| 228 | + if (is_array($data)) { |
|
| 229 | 229 | end($data); |
| 230 | 230 | $last_element = key($data); |
| 231 | 231 | $arr_check = true; |
| 232 | 232 | |
| 233 | - if($data){ |
|
| 234 | - foreach($data as $key=>$row){ |
|
| 235 | - if($key == $last_element){ |
|
| 233 | + if ($data) { |
|
| 234 | + foreach ($data as $key=>$row) { |
|
| 235 | + if ($key == $last_element) { |
|
| 236 | 236 | $tmp_or_where .= $key."='".$row."'"; |
| 237 | - }else{ |
|
| 237 | + } else { |
|
| 238 | 238 | $tmp_or_where .= $key."='".$row."' AND "; |
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | - }else{ |
|
| 242 | + } else { |
|
| 243 | 243 | $arr_check = false; |
| 244 | 244 | $tmp_or_where = "OR ".$data."='".$match."'"; |
| 245 | 245 | } |
@@ -248,14 +248,14 @@ discard block |
||
| 248 | 248 | $this->or_where = ($arr_check) ? "OR ".$tmp_or_where : $tmp_or_where; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - public function where_in($field,$data){ |
|
| 251 | + public function where_in($field, $data) { |
|
| 252 | 252 | $where_in_fields = ''; |
| 253 | 253 | $last_key = end(array_keys($data)); |
| 254 | - if($data){ |
|
| 255 | - foreach($data as $key=>$row){ |
|
| 256 | - if($key == $last_key){ |
|
| 254 | + if ($data) { |
|
| 255 | + foreach ($data as $key=>$row) { |
|
| 256 | + if ($key == $last_key) { |
|
| 257 | 257 | $where_in_fields .= $row; |
| 258 | - }else{ |
|
| 258 | + } else { |
|
| 259 | 259 | $where_in_fields .= $row.","; |
| 260 | 260 | } |
| 261 | 261 | } |
@@ -264,14 +264,14 @@ discard block |
||
| 264 | 264 | $this->where_in = 'WHERE '.$field.' IN ('.$where_in_fields.')'; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - public function or_where_in($field,$data){ |
|
| 267 | + public function or_where_in($field, $data) { |
|
| 268 | 268 | $where_in_fields = ''; |
| 269 | 269 | $last_key = end(array_keys($data)); |
| 270 | - if($data){ |
|
| 271 | - foreach($data as $key=>$row){ |
|
| 272 | - if($key == $last_key){ |
|
| 270 | + if ($data) { |
|
| 271 | + foreach ($data as $key=>$row) { |
|
| 272 | + if ($key == $last_key) { |
|
| 273 | 273 | $where_in_fields .= $row; |
| 274 | - }else{ |
|
| 274 | + } else { |
|
| 275 | 275 | $where_in_fields .= $row.","; |
| 276 | 276 | } |
| 277 | 277 | } |
@@ -280,14 +280,14 @@ discard block |
||
| 280 | 280 | $this->or_where_in = 'OR '.$field.' IN ('.$where_in_fields.')'; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - public function where_not_in($field,$data){ |
|
| 283 | + public function where_not_in($field, $data) { |
|
| 284 | 284 | $where_in_fields = ''; |
| 285 | 285 | $last_key = end(array_keys($data)); |
| 286 | - if($data){ |
|
| 287 | - foreach($data as $key=>$row){ |
|
| 288 | - if($key == $last_key){ |
|
| 286 | + if ($data) { |
|
| 287 | + foreach ($data as $key=>$row) { |
|
| 288 | + if ($key == $last_key) { |
|
| 289 | 289 | $where_in_fields .= $row; |
| 290 | - }else{ |
|
| 290 | + } else { |
|
| 291 | 291 | $where_in_fields .= $row.","; |
| 292 | 292 | } |
| 293 | 293 | } |
@@ -296,14 +296,14 @@ discard block |
||
| 296 | 296 | $this->where_not_in = 'WHERE '.$field.' NOT IN ('.$where_in_fields.')'; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - public function or_where_not_in($field,$data){ |
|
| 299 | + public function or_where_not_in($field, $data) { |
|
| 300 | 300 | $where_in_fields = ''; |
| 301 | 301 | $last_key = end(array_keys($data)); |
| 302 | - if($data){ |
|
| 303 | - foreach($data as $key=>$row){ |
|
| 304 | - if($key == $last_key){ |
|
| 302 | + if ($data) { |
|
| 303 | + foreach ($data as $key=>$row) { |
|
| 304 | + if ($key == $last_key) { |
|
| 305 | 305 | $where_in_fields .= $row; |
| 306 | - }else{ |
|
| 306 | + } else { |
|
| 307 | 307 | $where_in_fields .= $row.","; |
| 308 | 308 | } |
| 309 | 309 | } |
@@ -312,25 +312,25 @@ discard block |
||
| 312 | 312 | $this->or_where_not_in = 'OR '.$field.' NOT IN ('.$where_in_fields.')'; |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - public function like($data=null,$match=null){ |
|
| 315 | + public function like($data = null, $match = null) { |
|
| 316 | 316 | $tmp_like = ''; |
| 317 | 317 | $arr_check = false; |
| 318 | - if($data){ |
|
| 319 | - if(is_array($data)){ |
|
| 318 | + if ($data) { |
|
| 319 | + if (is_array($data)) { |
|
| 320 | 320 | end($data); |
| 321 | 321 | $last_element = key($data); |
| 322 | 322 | |
| 323 | - if($data){ |
|
| 323 | + if ($data) { |
|
| 324 | 324 | $arr_check = true; |
| 325 | - foreach($data as $key=>$row){ |
|
| 326 | - if($key == $last_element){ |
|
| 325 | + foreach ($data as $key=>$row) { |
|
| 326 | + if ($key == $last_element) { |
|
| 327 | 327 | $tmp_like .= $key." LIKE '%".$row."%'"; |
| 328 | - }else{ |
|
| 328 | + } else { |
|
| 329 | 329 | $tmp_like .= $key." LIKE '%".$row."%' AND "; |
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | - }else{ |
|
| 333 | + } else { |
|
| 334 | 334 | $arr_check = false; |
| 335 | 335 | $tmp_like = "WHERE ".$data." LIKE '%".$match."%'"; |
| 336 | 336 | } |
@@ -340,23 +340,23 @@ discard block |
||
| 340 | 340 | $this->like = ($arr_check == false) ? "WHERE ".$tmp_like : $tmp_like; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - public function or_like($data=null,$match=null){ |
|
| 343 | + public function or_like($data = null, $match = null) { |
|
| 344 | 344 | $tmp_or_like = ''; |
| 345 | - if($data){ |
|
| 346 | - if(is_array($data)){ |
|
| 345 | + if ($data) { |
|
| 346 | + if (is_array($data)) { |
|
| 347 | 347 | end($data); |
| 348 | 348 | $last_element = key($data); |
| 349 | 349 | |
| 350 | - if($data){ |
|
| 351 | - foreach($data as $key=>$row){ |
|
| 352 | - if($key == $last_element){ |
|
| 350 | + if ($data) { |
|
| 351 | + foreach ($data as $key=>$row) { |
|
| 352 | + if ($key == $last_element) { |
|
| 353 | 353 | $tmp_or_like .= "OR ".$key." LIKE '%".$row."%'"; |
| 354 | - }else{ |
|
| 354 | + } else { |
|
| 355 | 355 | $tmp_or_like .= "OR ".$key." LIKE '%".$row."%' AND "; |
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | - }else{ |
|
| 359 | + } else { |
|
| 360 | 360 | $tmp_or_like = "OR ".$data." LIKE '%".$match."%'"; |
| 361 | 361 | } |
| 362 | 362 | } |
@@ -364,25 +364,25 @@ discard block |
||
| 364 | 364 | $this->or_like = $tmp_or_like; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - public function not_like($data=null,$match=null){ |
|
| 367 | + public function not_like($data = null, $match = null) { |
|
| 368 | 368 | $tmp_like = ''; |
| 369 | 369 | $arr_check = false; |
| 370 | - if($data){ |
|
| 371 | - if(is_array($data)){ |
|
| 370 | + if ($data) { |
|
| 371 | + if (is_array($data)) { |
|
| 372 | 372 | end($data); |
| 373 | 373 | $last_element = key($data); |
| 374 | 374 | |
| 375 | - if($data){ |
|
| 375 | + if ($data) { |
|
| 376 | 376 | $arr_check = true; |
| 377 | - foreach($data as $key=>$row){ |
|
| 378 | - if($key == $last_element){ |
|
| 377 | + foreach ($data as $key=>$row) { |
|
| 378 | + if ($key == $last_element) { |
|
| 379 | 379 | $tmp_like .= $key." NOT LIKE '%".$row."%'"; |
| 380 | - }else{ |
|
| 380 | + } else { |
|
| 381 | 381 | $tmp_like .= $key." NOT LIKE '%".$row."%' AND "; |
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | - }else{ |
|
| 385 | + } else { |
|
| 386 | 386 | $arr_check = false; |
| 387 | 387 | $tmp_like = "WHERE ".$data." NOT LIKE '%".$match."%'"; |
| 388 | 388 | } |
@@ -392,23 +392,23 @@ discard block |
||
| 392 | 392 | $this->like = ($arr_check) ? "WHERE ".$tmp_like : $tmp_like; |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - public function or_not_like($data=null,$match=null){ |
|
| 395 | + public function or_not_like($data = null, $match = null) { |
|
| 396 | 396 | $tmp_or_like = ''; |
| 397 | - if($data){ |
|
| 398 | - if(is_array($data)){ |
|
| 397 | + if ($data) { |
|
| 398 | + if (is_array($data)) { |
|
| 399 | 399 | end($data); |
| 400 | 400 | $last_element = key($data); |
| 401 | 401 | |
| 402 | - if($data){ |
|
| 403 | - foreach($data as $key=>$row){ |
|
| 404 | - if($key == $last_element){ |
|
| 402 | + if ($data) { |
|
| 403 | + foreach ($data as $key=>$row) { |
|
| 404 | + if ($key == $last_element) { |
|
| 405 | 405 | $tmp_or_like .= "OR ".$key." NOT LIKE '%".$row."%'"; |
| 406 | - }else{ |
|
| 406 | + } else { |
|
| 407 | 407 | $tmp_or_like .= "OR ".$key." NOT LIKE '%".$row."%' AND "; |
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | - }else{ |
|
| 411 | + } else { |
|
| 412 | 412 | $tmp_or_like = "OR ".$data." NOT LIKE '%".$match."%'"; |
| 413 | 413 | } |
| 414 | 414 | } |
@@ -416,25 +416,25 @@ discard block |
||
| 416 | 416 | $this->or_like = $tmp_or_like; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - public function order_by($field,$sort){ |
|
| 419 | + public function order_by($field, $sort) { |
|
| 420 | 420 | $this->order_by = $field.' '.$sort; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - public function join($table,$joint,$join_type="INNER"){ |
|
| 423 | + public function join($table, $joint, $join_type = "INNER") { |
|
| 424 | 424 | $this->join = $join_type.' JOIN '.$table.' ON '.$joint; |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - public function group_by($field){ |
|
| 427 | + public function group_by($field) { |
|
| 428 | 428 | $this->group_by = 'GROUP BY '.$field; |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - public function get($table=null,$limit=null,$offset=null){ |
|
| 431 | + public function get($table = null, $limit = null, $offset = null) { |
|
| 432 | 432 | $this->table = $table; |
| 433 | 433 | $this->limit = $limit; |
| 434 | 434 | $this->offset = $offset; |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - public function clear_global_var(){ |
|
| 437 | + public function clear_global_var() { |
|
| 438 | 438 | $this->select = ''; |
| 439 | 439 | $this->where = ''; |
| 440 | 440 | $this->or_where = ''; |
@@ -457,10 +457,10 @@ discard block |
||
| 457 | 457 | $this->result = ''; |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - public function row(){ |
|
| 460 | + public function row() { |
|
| 461 | 461 | /*init var*/ |
| 462 | 462 | $result = []; |
| 463 | - $select = ($this->select) ? implode(',',$this->select) : '*'; |
|
| 463 | + $select = ($this->select) ? implode(',', $this->select) : '*'; |
|
| 464 | 464 | $order_by = ($this->order_by) ? 'ORDER BY '.$this->order_by : ''; |
| 465 | 465 | $join = ($this->join) ? $this->join : ''; |
| 466 | 466 | $group_by = ($this->group_by) ? $this->group_by : ''; |
@@ -484,8 +484,8 @@ discard block |
||
| 484 | 484 | $this->row = "SELECT {$select} FROM {$table} {$join} {$where} {$or_where} {$where_in} {$or_where_in} {$where_not_in} {$or_where_not_in} {$like} {$or_like} {$not_like} {$or_not_like} {$group_by} {$order_by} {$limit} {$offset}"; |
| 485 | 485 | $this->last_query = $this->row; |
| 486 | 486 | $data = $this->redbean->getRow($this->row); |
| 487 | - if($data){ |
|
| 488 | - foreach($data as $key=>$row){ |
|
| 487 | + if ($data) { |
|
| 488 | + foreach ($data as $key=>$row) { |
|
| 489 | 489 | $result[$key] = $row; |
| 490 | 490 | } |
| 491 | 491 | } |
@@ -497,10 +497,10 @@ discard block |
||
| 497 | 497 | return $result; |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - public function num_rows(){ |
|
| 500 | + public function num_rows() { |
|
| 501 | 501 | /*init var*/ |
| 502 | - $result = 0;#array(); |
|
| 503 | - $select = ($this->select) ? implode(',',$this->select) : '*'; |
|
| 502 | + $result = 0; #array(); |
|
| 503 | + $select = ($this->select) ? implode(',', $this->select) : '*'; |
|
| 504 | 504 | $order_by = ($this->order_by) ? 'ORDER BY '.$this->order_by : ''; |
| 505 | 505 | $join = ($this->join) ? $this->join : ''; |
| 506 | 506 | $group_by = ($this->group_by) ? $this->group_by : ''; |
@@ -533,10 +533,10 @@ discard block |
||
| 533 | 533 | return $result; |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | - public function result(){ |
|
| 536 | + public function result() { |
|
| 537 | 537 | /*init var*/ |
| 538 | 538 | $result = array(); |
| 539 | - $select = ($this->select) ? implode(',',$this->select) : '*'; |
|
| 539 | + $select = ($this->select) ? implode(',', $this->select) : '*'; |
|
| 540 | 540 | $order_by = ($this->order_by) ? 'ORDER BY '.$this->order_by : ''; |
| 541 | 541 | $join = ($this->join) ? $this->join : ''; |
| 542 | 542 | $group_by = ($this->group_by) ? $this->group_by : ''; |
@@ -562,9 +562,9 @@ discard block |
||
| 562 | 562 | $this->result = "SELECT {$select} FROM {$table} {$join} {$where} {$or_where} {$where_in} {$or_where_in} {$where_not_in} {$or_where_not_in} {$like} {$or_like} {$not_like} {$or_not_like} {$group_by} {$order_by} {$limit} {$offset}"; |
| 563 | 563 | $this->last_query = $this->result; |
| 564 | 564 | $data = $this->redbean->getAll($this->result); |
| 565 | - if($data){ |
|
| 566 | - foreach($data as $key=>$row){ |
|
| 567 | - $result[$key] = (object)$row; |
|
| 565 | + if ($data) { |
|
| 566 | + foreach ($data as $key=>$row) { |
|
| 567 | + $result[$key] = (object) $row; |
|
| 568 | 568 | } |
| 569 | 569 | } |
| 570 | 570 | |
@@ -576,146 +576,146 @@ discard block |
||
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | /*Database*/ |
| 579 | - public function wipe($beanType){ |
|
| 579 | + public function wipe($beanType) { |
|
| 580 | 580 | $result = $this->redbean->wipe($beanType); |
| 581 | 581 | return ($result) ? $result : false; |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - public function dispense($data){ |
|
| 584 | + public function dispense($data) { |
|
| 585 | 585 | $result = $this->redbean->dispense($data); |
| 586 | 586 | return ($result) ? true : false; |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | - public function store($data){ |
|
| 589 | + public function store($data) { |
|
| 590 | 590 | $result = $this->redbean->store($data); |
| 591 | 591 | return ($result) ? true : false; |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | - public function inspect($data){ |
|
| 595 | - if($data){ |
|
| 596 | - if(is_array($data)){ |
|
| 594 | + public function inspect($data) { |
|
| 595 | + if ($data) { |
|
| 596 | + if (is_array($data)) { |
|
| 597 | 597 | |
| 598 | 598 | $result = array(); |
| 599 | - foreach($data as $key=>$row){ |
|
| 600 | - $result[$key]=$this->redbean->inspect($row); |
|
| 599 | + foreach ($data as $key=>$row) { |
|
| 600 | + $result[$key] = $this->redbean->inspect($row); |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | return ($result) ? $result : false; |
| 604 | 604 | |
| 605 | - }else{ |
|
| 605 | + } else { |
|
| 606 | 606 | $this->redbean->inspect($data); |
| 607 | 607 | return true; |
| 608 | 608 | } |
| 609 | 609 | } |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | - public function get_all_tables(){ |
|
| 612 | + public function get_all_tables() { |
|
| 613 | 613 | $result = $this->redbean->inspect(); |
| 614 | 614 | return ($result) ? $result : false; |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - public function select_database($db_name){ |
|
| 617 | + public function select_database($db_name) { |
|
| 618 | 618 | $result = $this->redbean->selectDatabase($db_name); |
| 619 | 619 | return ($result) ? true : false; |
| 620 | 620 | } |
| 621 | 621 | |
| 622 | - public function set_database(){ |
|
| 622 | + public function set_database() { |
|
| 623 | 623 | $result = $this->redbean->selectDatabase('default'); |
| 624 | 624 | return ($result) ? true : false; |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | - public function begin(){ |
|
| 627 | + public function begin() { |
|
| 628 | 628 | $result = $this->redbean->begin(); |
| 629 | 629 | return ($result) ? true : false; |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - public function commit(){ |
|
| 632 | + public function commit() { |
|
| 633 | 633 | $result = $this->redbean->commit(); |
| 634 | 634 | return ($result) ? true : false; |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | - public function roll_back(){ |
|
| 637 | + public function roll_back() { |
|
| 638 | 638 | $result = $this->redbean->rollback(); |
| 639 | 639 | return ($result) ? true : false; |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | - public function get_query_count(){ |
|
| 642 | + public function get_query_count() { |
|
| 643 | 643 | $this->redbean->getQueryCount(); |
| 644 | 644 | return true; |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - public function get_logs(){ |
|
| 647 | + public function get_logs() { |
|
| 648 | 648 | $this->redbean->getLogs(); |
| 649 | 649 | return true; |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | /*querying*/ |
| 653 | - public function exec($data){ |
|
| 653 | + public function exec($data) { |
|
| 654 | 654 | $result = $this->redbean->exec($data); |
| 655 | 655 | return ($result) ? $result : false; |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | - public function get_all($table){ |
|
| 658 | + public function get_all($table) { |
|
| 659 | 659 | $result = $this->redbean->getAll($table); |
| 660 | 660 | return ($result) ? $result : false; |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - public function get_row($data){ |
|
| 663 | + public function get_row($data) { |
|
| 664 | 664 | $result = $this->redbean->getRow($data); |
| 665 | 665 | return ($result) ? $result : false; |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | - public function get_column($data){ |
|
| 668 | + public function get_column($data) { |
|
| 669 | 669 | $result = $this->redbean->getCol($data); |
| 670 | 670 | return ($result) ? $result : false; |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | - public function get_cell($data){ |
|
| 673 | + public function get_cell($data) { |
|
| 674 | 674 | $result = $this->redbean->getCell($data); |
| 675 | 675 | return ($result) ? $result : false; |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | - public function get_assoc($data){ |
|
| 678 | + public function get_assoc($data) { |
|
| 679 | 679 | $result = $this->redbean->getAssoc($data); |
| 680 | 680 | return ($result) ? $result : false; |
| 681 | 681 | } |
| 682 | 682 | |
| 683 | - public function get_inserted_id(){ |
|
| 683 | + public function get_inserted_id() { |
|
| 684 | 684 | $result = $this->redbean->getInsertID(); |
| 685 | 685 | return ($result) ? $result : false; |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | - public function convert_to_beans($type,$rows,$metamask=null){ |
|
| 689 | - $result = $this->redbean->convertToBeans( $type, $rows, $metamask ); |
|
| 688 | + public function convert_to_beans($type, $rows, $metamask = null) { |
|
| 689 | + $result = $this->redbean->convertToBeans($type, $rows, $metamask); |
|
| 690 | 690 | return ($result) ? $result : false; |
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | /*Data Tools*/ |
| 694 | - public function match_up($type, $sql, $bindings = array(), $onFoundDo = NULL, $onNotFoundDo = NULL, &$bean = NULL){ |
|
| 694 | + public function match_up($type, $sql, $bindings = array(), $onFoundDo = NULL, $onNotFoundDo = NULL, &$bean = NULL) { |
|
| 695 | 695 | $result = $this->redbean->matchUp($type, $sql, $bindings, $onFoundDo, $onNotFoundDo, $bean); |
| 696 | 696 | return ($result) ? $result : false; |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | - public function find_all($table){ |
|
| 699 | + public function find_all($table) { |
|
| 700 | 700 | $this->redbean->findAll($table); |
| 701 | 701 | return true; |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | - public function find($type,$sql,$bindings){ |
|
| 705 | - $result = $this->redbean->find($type,$sql,$bindings); |
|
| 704 | + public function find($type, $sql, $bindings) { |
|
| 705 | + $result = $this->redbean->find($type, $sql, $bindings); |
|
| 706 | 706 | return ($result) ? $result : false; |
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /*Fluid and Frozen*/ |
| 710 | - public function freeze($data=null){ |
|
| 711 | - if($data){ |
|
| 710 | + public function freeze($data = null) { |
|
| 711 | + if ($data) { |
|
| 712 | 712 | $data = array(); |
| 713 | - foreach($data as $key=>$row){ |
|
| 713 | + foreach ($data as $key=>$row) { |
|
| 714 | 714 | $data[$key] = $row; |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | $this->redbean->freeze($data); |
| 718 | - }else{ |
|
| 718 | + } else { |
|
| 719 | 719 | $this->redbean->freeze(TRUE); |
| 720 | 720 | } |
| 721 | 721 | return true; |
@@ -723,55 +723,55 @@ discard block |
||
| 723 | 723 | |
| 724 | 724 | /*Debugging*/ |
| 725 | 725 | /*value "true", "false"*/ |
| 726 | - public function debug($tf = TRUE, $mode = 0){ |
|
| 727 | - $result = $this->redbean->debug($tf,$mode); |
|
| 726 | + public function debug($tf = TRUE, $mode = 0) { |
|
| 727 | + $result = $this->redbean->debug($tf, $mode); |
|
| 728 | 728 | return ($result) ? $result : false; |
| 729 | 729 | } |
| 730 | 730 | |
| 731 | - public function dump($data){ |
|
| 731 | + public function dump($data) { |
|
| 732 | 732 | $this->redbean->dump($data); |
| 733 | 733 | return true; |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | - public function test_connection(){ |
|
| 736 | + public function test_connection() { |
|
| 737 | 737 | $result = $this->redbean->testConnection(); |
| 738 | 738 | return ($result) ? $result : false; |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | /*Aliases*/ |
| 742 | - public function load($oodb, $types, $id){ |
|
| 742 | + public function load($oodb, $types, $id) { |
|
| 743 | 743 | $result = $this->redbean->load($oodb, $types, $id); |
| 744 | 744 | return ($result) ? $result : false; |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | /*Count*/ |
| 748 | - public function count($type, $addSQL = '', $bindings = array()){ |
|
| 749 | - $result = $this->redbean->count($type,$addSQL,$bindings); |
|
| 748 | + public function count($type, $addSQL = '', $bindings = array()) { |
|
| 749 | + $result = $this->redbean->count($type, $addSQL, $bindings); |
|
| 750 | 750 | return ($result) ? $result : false; |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | - public function count_shared($type){ |
|
| 753 | + public function count_shared($type) { |
|
| 754 | 754 | $result = $this->redbean->countOwn($type); |
| 755 | 755 | return ($result) ? $result : false; |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | /*Labels, Enums, Tags*/ |
| 759 | - public function dispense_labels($type,$labels){ |
|
| 760 | - $result = $this->redbean->dispenseLabels($type,$labels); |
|
| 759 | + public function dispense_labels($type, $labels) { |
|
| 760 | + $result = $this->redbean->dispenseLabels($type, $labels); |
|
| 761 | 761 | return ($result) ? $result : false; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - public function gather_labels($beans){ |
|
| 764 | + public function gather_labels($beans) { |
|
| 765 | 765 | $result = $this->redbean->gatherLabels($beans); |
| 766 | 766 | return ($result) ? $result : false; |
| 767 | 767 | } |
| 768 | 768 | |
| 769 | - public function enum($enum){ |
|
| 769 | + public function enum($enum) { |
|
| 770 | 770 | $result = $this->redbean->enum($enum); |
| 771 | 771 | return ($result) ? $result : false; |
| 772 | 772 | } |
| 773 | 773 | |
| 774 | - public function tag($bean, $tagList){ |
|
| 774 | + public function tag($bean, $tagList) { |
|
| 775 | 775 | $result = $this->redbean->tag($bean, $tagList); |
| 776 | 776 | return ($result) ? $result : false; |
| 777 | 777 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | $data[$key_ib]->$row = $table_fields_val[$key]; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - }else{ |
|
| 102 | + } else{ |
|
| 103 | 103 | return false; |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $data->$row = $table_fields_val[$key]; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - }else{ |
|
| 152 | + } else{ |
|
| 153 | 153 | return false; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | return true; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - }else{ |
|
| 174 | + } else{ |
|
| 175 | 175 | $this->redbean->trash($table,$id); |
| 176 | 176 | return true; |
| 177 | 177 | } |
@@ -207,12 +207,12 @@ discard block |
||
| 207 | 207 | foreach($data as $key=>$row){ |
| 208 | 208 | if($key == $last_element){ |
| 209 | 209 | $tmp_where .= $key."='".$row."'"; |
| 210 | - }else{ |
|
| 210 | + } else{ |
|
| 211 | 211 | $tmp_where .= $key."='".$row."' AND "; |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | - }else{ |
|
| 215 | + } else{ |
|
| 216 | 216 | $arr_check = false; |
| 217 | 217 | $tmp_where = "WHERE ".$data."='".$match."'"; |
| 218 | 218 | } |
@@ -234,12 +234,12 @@ discard block |
||
| 234 | 234 | foreach($data as $key=>$row){ |
| 235 | 235 | if($key == $last_element){ |
| 236 | 236 | $tmp_or_where .= $key."='".$row."'"; |
| 237 | - }else{ |
|
| 237 | + } else{ |
|
| 238 | 238 | $tmp_or_where .= $key."='".$row."' AND "; |
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | - }else{ |
|
| 242 | + } else{ |
|
| 243 | 243 | $arr_check = false; |
| 244 | 244 | $tmp_or_where = "OR ".$data."='".$match."'"; |
| 245 | 245 | } |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | foreach($data as $key=>$row){ |
| 256 | 256 | if($key == $last_key){ |
| 257 | 257 | $where_in_fields .= $row; |
| 258 | - }else{ |
|
| 258 | + } else{ |
|
| 259 | 259 | $where_in_fields .= $row.","; |
| 260 | 260 | } |
| 261 | 261 | } |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | foreach($data as $key=>$row){ |
| 272 | 272 | if($key == $last_key){ |
| 273 | 273 | $where_in_fields .= $row; |
| 274 | - }else{ |
|
| 274 | + } else{ |
|
| 275 | 275 | $where_in_fields .= $row.","; |
| 276 | 276 | } |
| 277 | 277 | } |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | foreach($data as $key=>$row){ |
| 288 | 288 | if($key == $last_key){ |
| 289 | 289 | $where_in_fields .= $row; |
| 290 | - }else{ |
|
| 290 | + } else{ |
|
| 291 | 291 | $where_in_fields .= $row.","; |
| 292 | 292 | } |
| 293 | 293 | } |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | foreach($data as $key=>$row){ |
| 304 | 304 | if($key == $last_key){ |
| 305 | 305 | $where_in_fields .= $row; |
| 306 | - }else{ |
|
| 306 | + } else{ |
|
| 307 | 307 | $where_in_fields .= $row.","; |
| 308 | 308 | } |
| 309 | 309 | } |
@@ -325,12 +325,12 @@ discard block |
||
| 325 | 325 | foreach($data as $key=>$row){ |
| 326 | 326 | if($key == $last_element){ |
| 327 | 327 | $tmp_like .= $key." LIKE '%".$row."%'"; |
| 328 | - }else{ |
|
| 328 | + } else{ |
|
| 329 | 329 | $tmp_like .= $key." LIKE '%".$row."%' AND "; |
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | - }else{ |
|
| 333 | + } else{ |
|
| 334 | 334 | $arr_check = false; |
| 335 | 335 | $tmp_like = "WHERE ".$data." LIKE '%".$match."%'"; |
| 336 | 336 | } |
@@ -351,12 +351,12 @@ discard block |
||
| 351 | 351 | foreach($data as $key=>$row){ |
| 352 | 352 | if($key == $last_element){ |
| 353 | 353 | $tmp_or_like .= "OR ".$key." LIKE '%".$row."%'"; |
| 354 | - }else{ |
|
| 354 | + } else{ |
|
| 355 | 355 | $tmp_or_like .= "OR ".$key." LIKE '%".$row."%' AND "; |
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | - }else{ |
|
| 359 | + } else{ |
|
| 360 | 360 | $tmp_or_like = "OR ".$data." LIKE '%".$match."%'"; |
| 361 | 361 | } |
| 362 | 362 | } |
@@ -377,12 +377,12 @@ discard block |
||
| 377 | 377 | foreach($data as $key=>$row){ |
| 378 | 378 | if($key == $last_element){ |
| 379 | 379 | $tmp_like .= $key." NOT LIKE '%".$row."%'"; |
| 380 | - }else{ |
|
| 380 | + } else{ |
|
| 381 | 381 | $tmp_like .= $key." NOT LIKE '%".$row."%' AND "; |
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | - }else{ |
|
| 385 | + } else{ |
|
| 386 | 386 | $arr_check = false; |
| 387 | 387 | $tmp_like = "WHERE ".$data." NOT LIKE '%".$match."%'"; |
| 388 | 388 | } |
@@ -403,12 +403,12 @@ discard block |
||
| 403 | 403 | foreach($data as $key=>$row){ |
| 404 | 404 | if($key == $last_element){ |
| 405 | 405 | $tmp_or_like .= "OR ".$key." NOT LIKE '%".$row."%'"; |
| 406 | - }else{ |
|
| 406 | + } else{ |
|
| 407 | 407 | $tmp_or_like .= "OR ".$key." NOT LIKE '%".$row."%' AND "; |
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | - }else{ |
|
| 411 | + } else{ |
|
| 412 | 412 | $tmp_or_like = "OR ".$data." NOT LIKE '%".$match."%'"; |
| 413 | 413 | } |
| 414 | 414 | } |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | |
| 603 | 603 | return ($result) ? $result : false; |
| 604 | 604 | |
| 605 | - }else{ |
|
| 605 | + } else{ |
|
| 606 | 606 | $this->redbean->inspect($data); |
| 607 | 607 | return true; |
| 608 | 608 | } |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | $this->redbean->freeze($data); |
| 718 | - }else{ |
|
| 718 | + } else{ |
|
| 719 | 719 | $this->redbean->freeze(TRUE); |
| 720 | 720 | } |
| 721 | 721 | return true; |