@@ -9,13 +9,13 @@ discard block |
||
| 9 | 9 | * |
| 10 | 10 | * @var int |
| 11 | 11 | */ |
| 12 | - public static $pageLimit = 20; |
|
| 12 | + public static $pageLimit=20; |
|
| 13 | 13 | /** |
| 14 | 14 | * Variable that holds total pages count of last paginate() query |
| 15 | 15 | * |
| 16 | 16 | * @var int |
| 17 | 17 | */ |
| 18 | - public static $totalPages = 0; |
|
| 18 | + public static $totalPages=0; |
|
| 19 | 19 | /** |
| 20 | 20 | * Models path |
| 21 | 21 | * |
@@ -33,33 +33,33 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @var boolean |
| 35 | 35 | */ |
| 36 | - public $isNew = true; |
|
| 36 | + public $isNew=true; |
|
| 37 | 37 | /** |
| 38 | 38 | * Return type: 'Array' to return results as array, 'Object' as object |
| 39 | 39 | * 'Json' as json string |
| 40 | 40 | * |
| 41 | 41 | * @var string |
| 42 | 42 | */ |
| 43 | - public $returnType = 'Object'; |
|
| 43 | + public $returnType='Object'; |
|
| 44 | 44 | /** |
| 45 | 45 | * An array that holds insert/update/select errors |
| 46 | 46 | * |
| 47 | 47 | * @var array |
| 48 | 48 | */ |
| 49 | - public $errors = null; |
|
| 49 | + public $errors=null; |
|
| 50 | 50 | /** |
| 51 | 51 | * Primary key for an object. 'id' is a default value. |
| 52 | 52 | * |
| 53 | 53 | * @var stating |
| 54 | 54 | */ |
| 55 | - protected $primaryKey = 'id'; |
|
| 55 | + protected $primaryKey='id'; |
|
| 56 | 56 | /** |
| 57 | 57 | * Table name for an object. Class name will be used by default |
| 58 | 58 | * |
| 59 | 59 | * @var stating |
| 60 | 60 | */ |
| 61 | 61 | protected $dbTable; |
| 62 | - protected $dbConn = null; |
|
| 62 | + protected $dbConn=null; |
|
| 63 | 63 | protected $prefix; |
| 64 | 64 | /** |
| 65 | 65 | * Working instance of MysqliDb created earlier |
@@ -73,24 +73,24 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @var string |
| 75 | 75 | */ |
| 76 | - private $_with = Array(); |
|
| 76 | + private $_with=Array(); |
|
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * @param array $data Data to preload on object creation |
| 80 | 80 | */ |
| 81 | 81 | public function __construct() { |
| 82 | - $this->db = app('db')->connect($this->dbConn); |
|
| 82 | + $this->db=app('db')->connect($this->dbConn); |
|
| 83 | 83 | if ($this->prefix) { |
| 84 | - $this->db = $this->db->setPrefix($this->prefix); |
|
| 84 | + $this->db=$this->db->setPrefix($this->prefix); |
|
| 85 | 85 | } |
| 86 | 86 | if (!$this->dbTable) { |
| 87 | - $classFull = get_class($this); |
|
| 88 | - $classArray = explode("\\", $classFull); |
|
| 89 | - $classSelf = array_pop($classArray); |
|
| 90 | - $classSelf = Str::snake($classSelf); |
|
| 91 | - $this->dbTable = $classSelf; |
|
| 87 | + $classFull=get_class($this); |
|
| 88 | + $classArray=explode("\\", $classFull); |
|
| 89 | + $classSelf=array_pop($classArray); |
|
| 90 | + $classSelf=Str::snake($classSelf); |
|
| 91 | + $this->dbTable=$classSelf; |
|
| 92 | 92 | } |
| 93 | - $this->db = $this->db->table($this->dbTable); |
|
| 93 | + $this->db=$this->db->table($this->dbTable); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -100,10 +100,10 @@ discard block |
||
| 100 | 100 | * @return dbObject |
| 101 | 101 | */ |
| 102 | 102 | public static function table($tableName) { |
| 103 | - $tableName = preg_replace("/[^-a-z0-9_]+/i", '', $tableName); |
|
| 103 | + $tableName=preg_replace("/[^-a-z0-9_]+/i", '', $tableName); |
|
| 104 | 104 | if (!class_exists($tableName)) |
| 105 | 105 | eval ("class $tableName extends dbObject {}"); |
| 106 | - return new $tableName (); |
|
| 106 | + return new $tableName(); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -117,23 +117,23 @@ discard block |
||
| 117 | 117 | * @return mixed |
| 118 | 118 | */ |
| 119 | 119 | public static function __callStatic($method, $arg) { |
| 120 | - $obj = new static; |
|
| 121 | - $result = call_user_func_array(array($obj, $method), $arg); |
|
| 120 | + $obj=new static; |
|
| 121 | + $result=call_user_func_array(array($obj, $method), $arg); |
|
| 122 | 122 | if (method_exists($obj, $method)) |
| 123 | 123 | return $result; |
| 124 | 124 | return $obj; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - public static function autoload($path = null) { |
|
| 127 | + public static function autoload($path=null) { |
|
| 128 | 128 | if ($path) |
| 129 | - static::$modelPath = $path . "/"; |
|
| 129 | + static::$modelPath=$path."/"; |
|
| 130 | 130 | else |
| 131 | - static::$modelPath = __DIR__ . "/models/"; |
|
| 131 | + static::$modelPath=__DIR__."/models/"; |
|
| 132 | 132 | spl_autoload_register("dbObject::dbObjectAutoload"); |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | private static function dbObjectAutoload($classname) { |
| 136 | - $filename = static::$modelPath . $classname . ".php"; |
|
| 136 | + $filename=static::$modelPath.$classname.".php"; |
|
| 137 | 137 | if (file_exists($filename)) |
| 138 | 138 | include($filename); |
| 139 | 139 | } |
@@ -153,20 +153,20 @@ discard block |
||
| 153 | 153 | return $this->data[$name]; |
| 154 | 154 | |
| 155 | 155 | if (property_exists($this, 'relations') && isset ($this->relations[$name])) { |
| 156 | - $relationType = strtolower($this->relations[$name][0]); |
|
| 157 | - $modelName = $this->relations[$name][1]; |
|
| 156 | + $relationType=strtolower($this->relations[$name][0]); |
|
| 157 | + $modelName=$this->relations[$name][1]; |
|
| 158 | 158 | switch ($relationType) { |
| 159 | 159 | case 'hasone': |
| 160 | - $key = isset ($this->relations[$name][2]) ? $this->relations[$name][2] : $name; |
|
| 161 | - $obj = new $modelName; |
|
| 162 | - $obj->returnType = $this->returnType; |
|
| 163 | - return $this->data[$name] = $obj->byId($this->data[$key]); |
|
| 160 | + $key=isset ($this->relations[$name][2]) ? $this->relations[$name][2] : $name; |
|
| 161 | + $obj=new $modelName; |
|
| 162 | + $obj->returnType=$this->returnType; |
|
| 163 | + return $this->data[$name]=$obj->byId($this->data[$key]); |
|
| 164 | 164 | break; |
| 165 | 165 | case 'hasmany': |
| 166 | - $key = $this->relations[$name][2]; |
|
| 167 | - $obj = new $modelName; |
|
| 168 | - $obj->returnType = $this->returnType; |
|
| 169 | - return $this->data[$name] = $obj->where($key, $this->data[$this->primaryKey])->get(); |
|
| 166 | + $key=$this->relations[$name][2]; |
|
| 167 | + $obj=new $modelName; |
|
| 168 | + $obj->returnType=$this->returnType; |
|
| 169 | + return $this->data[$name]=$obj->where($key, $this->data[$this->primaryKey])->get(); |
|
| 170 | 170 | break; |
| 171 | 171 | default: |
| 172 | 172 | break; |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | if (property_exists($this, 'hidden') && array_search($name, $this->hidden) !== false) |
| 190 | 190 | return; |
| 191 | 191 | |
| 192 | - $this->data[$name] = $value; |
|
| 192 | + $this->data[$name]=$value; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | public function __isset($name) { |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | * |
| 210 | 210 | * @return mixed insert id or false in case of failure |
| 211 | 211 | */ |
| 212 | - public function save($data = null) { |
|
| 212 | + public function save($data=null) { |
|
| 213 | 213 | if ($this->isNew) |
| 214 | 214 | return $this->insert(); |
| 215 | 215 | return $this->update($data); |
@@ -220,22 +220,22 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | public function insert() { |
| 222 | 222 | if (!empty ($this->timestamps) && in_array("createdAt", $this->timestamps)) |
| 223 | - $this->createdAt = date("Y-m-d H:i:s"); |
|
| 224 | - $sqlData = $this->prepareData(); |
|
| 223 | + $this->createdAt=date("Y-m-d H:i:s"); |
|
| 224 | + $sqlData=$this->prepareData(); |
|
| 225 | 225 | if (!$this->validate($sqlData)) |
| 226 | 226 | return false; |
| 227 | 227 | |
| 228 | - $id = $this->db->insert($this->dbTable, $sqlData); |
|
| 228 | + $id=$this->db->insert($this->dbTable, $sqlData); |
|
| 229 | 229 | if (!empty ($this->primaryKey) && empty ($this->data[$this->primaryKey])) |
| 230 | - $this->data[$this->primaryKey] = $id; |
|
| 231 | - $this->isNew = false; |
|
| 230 | + $this->data[$this->primaryKey]=$id; |
|
| 231 | + $this->isNew=false; |
|
| 232 | 232 | |
| 233 | 233 | return $id; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | private function prepareData() { |
| 237 | - $this->errors = Array(); |
|
| 238 | - $sqlData = Array(); |
|
| 237 | + $this->errors=Array(); |
|
| 238 | + $sqlData=Array(); |
|
| 239 | 239 | if (count($this->data) == 0) |
| 240 | 240 | return Array(); |
| 241 | 241 | |
@@ -247,27 +247,27 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | foreach ($this->data as $key => &$value) { |
| 249 | 249 | if ($value instanceof dbObject && $value->isNew == true) { |
| 250 | - $id = $value->save(); |
|
| 250 | + $id=$value->save(); |
|
| 251 | 251 | if ($id) |
| 252 | - $value = $id; |
|
| 252 | + $value=$id; |
|
| 253 | 253 | else |
| 254 | - $this->errors = array_merge($this->errors, $value->errors); |
|
| 254 | + $this->errors=array_merge($this->errors, $value->errors); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | if (!in_array($key, array_keys($this->dbFields))) |
| 258 | 258 | continue; |
| 259 | 259 | |
| 260 | 260 | if (!is_array($value)) { |
| 261 | - $sqlData[$key] = $value; |
|
| 261 | + $sqlData[$key]=$value; |
|
| 262 | 262 | continue; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | if (isset ($this->jsonFields) && in_array($key, $this->jsonFields)) |
| 266 | - $sqlData[$key] = json_encode($value); |
|
| 266 | + $sqlData[$key]=json_encode($value); |
|
| 267 | 267 | else if (isset ($this->arrayFields) && in_array($key, $this->arrayFields)) |
| 268 | - $sqlData[$key] = implode("|", $value); |
|
| 268 | + $sqlData[$key]=implode("|", $value); |
|
| 269 | 269 | else |
| 270 | - $sqlData[$key] = $value; |
|
| 270 | + $sqlData[$key]=$value; |
|
| 271 | 271 | } |
| 272 | 272 | return $sqlData; |
| 273 | 273 | } |
@@ -280,23 +280,23 @@ discard block |
||
| 280 | 280 | return true; |
| 281 | 281 | |
| 282 | 282 | foreach ($this->dbFields as $key => $desc) { |
| 283 | - $type = null; |
|
| 284 | - $required = false; |
|
| 283 | + $type=null; |
|
| 284 | + $required=false; |
|
| 285 | 285 | if (isset ($data[$key])) |
| 286 | - $value = $data[$key]; |
|
| 286 | + $value=$data[$key]; |
|
| 287 | 287 | else |
| 288 | - $value = null; |
|
| 288 | + $value=null; |
|
| 289 | 289 | |
| 290 | 290 | if (is_array($value)) |
| 291 | 291 | continue; |
| 292 | 292 | |
| 293 | 293 | if (isset ($desc[0])) |
| 294 | - $type = $desc[0]; |
|
| 294 | + $type=$desc[0]; |
|
| 295 | 295 | if (isset ($desc[1]) && ($desc[1] == 'required')) |
| 296 | - $required = true; |
|
| 296 | + $required=true; |
|
| 297 | 297 | |
| 298 | 298 | if ($required && strlen($value) == 0) { |
| 299 | - $this->errors[] = Array($this->dbTable . "." . $key => "is required"); |
|
| 299 | + $this->errors[]=Array($this->dbTable.".".$key => "is required"); |
|
| 300 | 300 | continue; |
| 301 | 301 | } |
| 302 | 302 | if ($value == null) |
@@ -304,29 +304,29 @@ discard block |
||
| 304 | 304 | |
| 305 | 305 | switch ($type) { |
| 306 | 306 | case "text"; |
| 307 | - $regexp = null; |
|
| 307 | + $regexp=null; |
|
| 308 | 308 | break; |
| 309 | 309 | case "int": |
| 310 | - $regexp = "/^[0-9]*$/"; |
|
| 310 | + $regexp="/^[0-9]*$/"; |
|
| 311 | 311 | break; |
| 312 | 312 | case "double": |
| 313 | - $regexp = "/^[0-9\.]*$/"; |
|
| 313 | + $regexp="/^[0-9\.]*$/"; |
|
| 314 | 314 | break; |
| 315 | 315 | case "bool": |
| 316 | - $regexp = '/^[yes|no|0|1|true|false]$/i'; |
|
| 316 | + $regexp='/^[yes|no|0|1|true|false]$/i'; |
|
| 317 | 317 | break; |
| 318 | 318 | case "datetime": |
| 319 | - $regexp = "/^[0-9a-zA-Z -:]*$/"; |
|
| 319 | + $regexp="/^[0-9a-zA-Z -:]*$/"; |
|
| 320 | 320 | break; |
| 321 | 321 | default: |
| 322 | - $regexp = $type; |
|
| 322 | + $regexp=$type; |
|
| 323 | 323 | break; |
| 324 | 324 | } |
| 325 | 325 | if (!$regexp) |
| 326 | 326 | continue; |
| 327 | 327 | |
| 328 | 328 | if (!preg_match($regexp, $value)) { |
| 329 | - $this->errors[] = Array($this->dbTable . "." . $key => "$type validation failed"); |
|
| 329 | + $this->errors[]=Array($this->dbTable.".".$key => "$type validation failed"); |
|
| 330 | 330 | continue; |
| 331 | 331 | } |
| 332 | 332 | } |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | /** |
| 337 | 337 | * @param array $data Optional update data to apply to the object |
| 338 | 338 | */ |
| 339 | - public function update($data = null) { |
|
| 339 | + public function update($data=null) { |
|
| 340 | 340 | if (empty ($this->dbFields)) |
| 341 | 341 | return false; |
| 342 | 342 | |
@@ -345,13 +345,13 @@ discard block |
||
| 345 | 345 | |
| 346 | 346 | if ($data) { |
| 347 | 347 | foreach ($data as $k => $v) |
| 348 | - $this->$k = $v; |
|
| 348 | + $this->$k=$v; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | if (!empty ($this->timestamps) && in_array("updatedAt", $this->timestamps)) |
| 352 | - $this->updatedAt = date("Y-m-d H:i:s"); |
|
| 352 | + $this->updatedAt=date("Y-m-d H:i:s"); |
|
| 353 | 353 | |
| 354 | - $sqlData = $this->prepareData(); |
|
| 354 | + $sqlData=$this->prepareData(); |
|
| 355 | 355 | if (!$this->validate($sqlData)) |
| 356 | 356 | return false; |
| 357 | 357 | |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | if (method_exists($this, $method)) |
| 385 | 385 | return call_user_func_array(array($this, $method), $arg); |
| 386 | 386 | $this->db->table($this->dbTable); |
| 387 | - return call_user_func_array(array($this->db, $method), $arg);; |
|
| 387 | + return call_user_func_array(array($this->db, $method), $arg); ; |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | /** |
@@ -411,11 +411,11 @@ discard block |
||
| 411 | 411 | * @return array Converted data |
| 412 | 412 | */ |
| 413 | 413 | public function toArray() { |
| 414 | - $data = $this->data; |
|
| 414 | + $data=$this->data; |
|
| 415 | 415 | $this->processAllWith($data); |
| 416 | 416 | foreach ($data as &$d) { |
| 417 | 417 | if ($d instanceof dbObject) |
| 418 | - $d = $d->data; |
|
| 418 | + $d=$d->data; |
|
| 419 | 419 | } |
| 420 | 420 | return $data; |
| 421 | 421 | } |
@@ -425,40 +425,40 @@ discard block |
||
| 425 | 425 | * |
| 426 | 426 | * @param array $data |
| 427 | 427 | */ |
| 428 | - private function processAllWith(&$data, $shouldReset = true) { |
|
| 428 | + private function processAllWith(&$data, $shouldReset=true) { |
|
| 429 | 429 | if (count($this->_with) == 0) |
| 430 | 430 | return; |
| 431 | 431 | |
| 432 | 432 | foreach ($this->_with as $name => $opts) { |
| 433 | - $relationType = strtolower($opts[0]); |
|
| 434 | - $modelName = $opts[1]; |
|
| 433 | + $relationType=strtolower($opts[0]); |
|
| 434 | + $modelName=$opts[1]; |
|
| 435 | 435 | if ($relationType == 'hasone') { |
| 436 | - $obj = new $modelName; |
|
| 437 | - $table = $obj->dbTable; |
|
| 438 | - $primaryKey = $obj->primaryKey; |
|
| 436 | + $obj=new $modelName; |
|
| 437 | + $table=$obj->dbTable; |
|
| 438 | + $primaryKey=$obj->primaryKey; |
|
| 439 | 439 | |
| 440 | 440 | if (!isset ($data[$table])) { |
| 441 | - $data[$name] = $this->$name; |
|
| 441 | + $data[$name]=$this->$name; |
|
| 442 | 442 | continue; |
| 443 | 443 | } |
| 444 | 444 | if ($data[$table][$primaryKey] === null) { |
| 445 | - $data[$name] = null; |
|
| 445 | + $data[$name]=null; |
|
| 446 | 446 | } else { |
| 447 | 447 | if ($this->returnType == 'Object') { |
| 448 | - $item = new $modelName ($data[$table]); |
|
| 449 | - $item->returnType = $this->returnType; |
|
| 450 | - $item->isNew = false; |
|
| 451 | - $data[$name] = $item; |
|
| 448 | + $item=new $modelName($data[$table]); |
|
| 449 | + $item->returnType=$this->returnType; |
|
| 450 | + $item->isNew=false; |
|
| 451 | + $data[$name]=$item; |
|
| 452 | 452 | } else { |
| 453 | - $data[$name] = $data[$table]; |
|
| 453 | + $data[$name]=$data[$table]; |
|
| 454 | 454 | } |
| 455 | 455 | } |
| 456 | 456 | unset ($data[$table]); |
| 457 | 457 | } else |
| 458 | - $data[$name] = $this->$name; |
|
| 458 | + $data[$name]=$this->$name; |
|
| 459 | 459 | } |
| 460 | 460 | if ($shouldReset) |
| 461 | - $this->_with = Array(); |
|
| 461 | + $this->_with=Array(); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -471,24 +471,24 @@ discard block |
||
| 471 | 471 | * |
| 472 | 472 | * @return array Array of dbObjects |
| 473 | 473 | */ |
| 474 | - protected function get($limit = null, $fields = null) { |
|
| 475 | - $objects = Array(); |
|
| 474 | + protected function get($limit=null, $fields=null) { |
|
| 475 | + $objects=Array(); |
|
| 476 | 476 | $this->processHasOneWith(); |
| 477 | - $results = $this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields); |
|
| 477 | + $results=$this->db->ArrayBuilder()->get($this->dbTable, $limit, $fields); |
|
| 478 | 478 | if ($this->db->count == 0) |
| 479 | 479 | return null; |
| 480 | 480 | |
| 481 | 481 | foreach ($results as &$r) { |
| 482 | 482 | $this->processArrays($r); |
| 483 | - $this->data = $r; |
|
| 483 | + $this->data=$r; |
|
| 484 | 484 | $this->processAllWith($r, false); |
| 485 | 485 | if ($this->returnType == 'Object') { |
| 486 | - $item = new static ($r); |
|
| 487 | - $item->isNew = false; |
|
| 488 | - $objects[] = $item; |
|
| 486 | + $item=new static ($r); |
|
| 487 | + $item->isNew=false; |
|
| 488 | + $objects[]=$item; |
|
| 489 | 489 | } |
| 490 | 490 | } |
| 491 | - $this->_with = Array(); |
|
| 491 | + $this->_with=Array(); |
|
| 492 | 492 | if ($this->returnType == 'Object') |
| 493 | 493 | return $objects; |
| 494 | 494 | |
@@ -502,11 +502,11 @@ discard block |
||
| 502 | 502 | if (count($this->_with) == 0) |
| 503 | 503 | return; |
| 504 | 504 | foreach ($this->_with as $name => $opts) { |
| 505 | - $relationType = strtolower($opts[0]); |
|
| 506 | - $modelName = $opts[1]; |
|
| 507 | - $key = null; |
|
| 505 | + $relationType=strtolower($opts[0]); |
|
| 506 | + $modelName=$opts[1]; |
|
| 507 | + $key=null; |
|
| 508 | 508 | if (isset ($opts[2])) |
| 509 | - $key = $opts[2]; |
|
| 509 | + $key=$opts[2]; |
|
| 510 | 510 | if ($relationType == 'hasone') { |
| 511 | 511 | $this->db->setQueryOption("MYSQLI_NESTJOIN"); |
| 512 | 512 | $this->join($modelName, $key); |
@@ -525,18 +525,18 @@ discard block |
||
| 525 | 525 | * |
| 526 | 526 | * @return dbObject |
| 527 | 527 | */ |
| 528 | - private function join($objectName, $key = null, $joinType = 'LEFT', $primaryKey = null) { |
|
| 529 | - $joinObj = new $objectName; |
|
| 528 | + private function join($objectName, $key=null, $joinType='LEFT', $primaryKey=null) { |
|
| 529 | + $joinObj=new $objectName; |
|
| 530 | 530 | if (!$key) |
| 531 | - $key = $objectName . "id"; |
|
| 531 | + $key=$objectName."id"; |
|
| 532 | 532 | |
| 533 | 533 | if (!$primaryKey) |
| 534 | - $primaryKey = $this->db->getPrefix() . $joinObj->dbTable . "." . $joinObj->primaryKey; |
|
| 534 | + $primaryKey=$this->db->getPrefix().$joinObj->dbTable.".".$joinObj->primaryKey; |
|
| 535 | 535 | |
| 536 | 536 | if (!strchr($key, '.')) |
| 537 | - $joinStr = $this->db->getPrefix() . $this->dbTable . ".{$key} = " . $primaryKey; |
|
| 537 | + $joinStr=$this->db->getPrefix().$this->dbTable.".{$key} = ".$primaryKey; |
|
| 538 | 538 | else |
| 539 | - $joinStr = $this->db->getPrefix() . "{$key} = " . $primaryKey; |
|
| 539 | + $joinStr=$this->db->getPrefix()."{$key} = ".$primaryKey; |
|
| 540 | 540 | |
| 541 | 541 | $this->db->join($joinObj->dbTable, $joinStr, $joinType); |
| 542 | 542 | return $this; |
@@ -548,12 +548,12 @@ discard block |
||
| 548 | 548 | private function processArrays(&$data) { |
| 549 | 549 | if (isset ($this->jsonFields) && is_array($this->jsonFields)) { |
| 550 | 550 | foreach ($this->jsonFields as $key) |
| 551 | - $data[$key] = json_decode($data[$key]); |
|
| 551 | + $data[$key]=json_decode($data[$key]); |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | if (isset ($this->arrayFields) && is_array($this->arrayFields)) { |
| 555 | 555 | foreach ($this->arrayFields as $key) |
| 556 | - $data[$key] = explode("|", $data[$key]); |
|
| 556 | + $data[$key]=explode("|", $data[$key]); |
|
| 557 | 557 | } |
| 558 | 558 | } |
| 559 | 559 | |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | * @return int |
| 564 | 564 | */ |
| 565 | 565 | protected function count() { |
| 566 | - $res = $this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)"); |
|
| 566 | + $res=$this->db->ArrayBuilder()->getValue($this->dbTable, "count(*)"); |
|
| 567 | 567 | if (!$res) |
| 568 | 568 | return 0; |
| 569 | 569 | return $res; |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | * @return dbObject |
| 576 | 576 | */ |
| 577 | 577 | private function JsonBuilder() { |
| 578 | - $this->returnType = 'Json'; |
|
| 578 | + $this->returnType='Json'; |
|
| 579 | 579 | return $this; |
| 580 | 580 | } |
| 581 | 581 | |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | * @return dbObject |
| 590 | 590 | */ |
| 591 | 591 | private function ArrayBuilder() { |
| 592 | - $this->returnType = 'Array'; |
|
| 592 | + $this->returnType='Array'; |
|
| 593 | 593 | return $this; |
| 594 | 594 | } |
| 595 | 595 | |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | * @return dbObject |
| 601 | 601 | */ |
| 602 | 602 | private function ObjectBuilder() { |
| 603 | - $this->returnType = 'Object'; |
|
| 603 | + $this->returnType='Object'; |
|
| 604 | 604 | return $this; |
| 605 | 605 | } |
| 606 | 606 | |
@@ -613,8 +613,8 @@ discard block |
||
| 613 | 613 | * |
| 614 | 614 | * @return dbObject|array |
| 615 | 615 | */ |
| 616 | - private function byId($id, $fields = null) { |
|
| 617 | - $this->db->where($this->db->getPrefix() . $this->dbTable . '.' . $this->primaryKey, $id); |
|
| 616 | + private function byId($id, $fields=null) { |
|
| 617 | + $this->db->where($this->db->getPrefix().$this->dbTable.'.'.$this->primaryKey, $id); |
|
| 618 | 618 | return $this->getOne($fields); |
| 619 | 619 | } |
| 620 | 620 | |
@@ -626,22 +626,22 @@ discard block |
||
| 626 | 626 | * |
| 627 | 627 | * @return dbObject |
| 628 | 628 | */ |
| 629 | - protected function getOne($fields = null) { |
|
| 629 | + protected function getOne($fields=null) { |
|
| 630 | 630 | $this->processHasOneWith(); |
| 631 | - $results = $this->db->ArrayBuilder()->getOne($this->dbTable, $fields); |
|
| 631 | + $results=$this->db->ArrayBuilder()->getOne($this->dbTable, $fields); |
|
| 632 | 632 | if ($this->db->count == 0) |
| 633 | 633 | return null; |
| 634 | 634 | |
| 635 | 635 | $this->processArrays($results); |
| 636 | - $this->data = $results; |
|
| 636 | + $this->data=$results; |
|
| 637 | 637 | $this->processAllWith($results); |
| 638 | 638 | if ($this->returnType == 'Json') |
| 639 | 639 | return json_encode($results); |
| 640 | 640 | if ($this->returnType == 'Array') |
| 641 | 641 | return $results; |
| 642 | 642 | |
| 643 | - $item = new static ($results); |
|
| 644 | - $item->isNew = false; |
|
| 643 | + $item=new static ($results); |
|
| 644 | + $item->isNew=false; |
|
| 645 | 645 | |
| 646 | 646 | return $item; |
| 647 | 647 | } |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | if (!property_exists($this, 'relations') && !isset ($this->relations[$name])) |
| 659 | 659 | die ("No relation with name $objectName found"); |
| 660 | 660 | |
| 661 | - $this->_with[$objectName] = $this->relations[$objectName]; |
|
| 661 | + $this->_with[$objectName]=$this->relations[$objectName]; |
|
| 662 | 662 | |
| 663 | 663 | return $this; |
| 664 | 664 | } |
@@ -679,23 +679,23 @@ discard block |
||
| 679 | 679 | * @param array|string $fields Array or coma separated list of fields to fetch |
| 680 | 680 | * @return array |
| 681 | 681 | */ |
| 682 | - private function paginate($page, $fields = null) { |
|
| 683 | - $this->db->pageLimit = self::$pageLimit; |
|
| 684 | - $res = $this->db->paginate($this->dbTable, $page, $fields); |
|
| 685 | - self::$totalPages = $this->db->totalPages; |
|
| 682 | + private function paginate($page, $fields=null) { |
|
| 683 | + $this->db->pageLimit=self::$pageLimit; |
|
| 684 | + $res=$this->db->paginate($this->dbTable, $page, $fields); |
|
| 685 | + self::$totalPages=$this->db->totalPages; |
|
| 686 | 686 | if ($this->db->count == 0) return null; |
| 687 | 687 | |
| 688 | 688 | foreach ($res as &$r) { |
| 689 | 689 | $this->processArrays($r); |
| 690 | - $this->data = $r; |
|
| 690 | + $this->data=$r; |
|
| 691 | 691 | $this->processAllWith($r, false); |
| 692 | 692 | if ($this->returnType == 'Object') { |
| 693 | - $item = new static ($r); |
|
| 694 | - $item->isNew = false; |
|
| 695 | - $objects[] = $item; |
|
| 693 | + $item=new static ($r); |
|
| 694 | + $item->isNew=false; |
|
| 695 | + $objects[]=$item; |
|
| 696 | 696 | } |
| 697 | 697 | } |
| 698 | - $this->_with = Array(); |
|
| 698 | + $this->_with=Array(); |
|
| 699 | 699 | if ($this->returnType == 'Object') |
| 700 | 700 | return $objects; |
| 701 | 701 | |