1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ibonly\PotatoORM; |
4
|
|
|
|
5
|
|
|
use Ibonly\PotatoORM\GetDataInterface; |
6
|
|
|
|
7
|
|
|
class GetData implements GetDataInterface |
8
|
|
|
{ |
9
|
|
|
protected $value; |
10
|
|
|
|
11
|
|
|
public function __construct($value) |
12
|
|
|
{ |
13
|
|
|
$this->value = $value; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* get all the data in the table as an array |
18
|
|
|
*/ |
19
|
|
|
protected function getAllData() |
20
|
|
|
{ |
21
|
|
|
return $this->value; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Reverse the json data |
26
|
|
|
* @param [int] $limit |
|
|
|
|
27
|
|
|
*/ |
28
|
|
|
protected function DESC($limit = NULL) |
29
|
|
|
{ |
30
|
|
|
$value = array_reverse($this->value); |
31
|
|
|
if ($limit === NULL) { |
32
|
|
|
return $value; |
33
|
|
|
} else { |
34
|
|
|
return array_slice($value, 0, $limit); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Return data in descending order |
40
|
|
|
* @param [int] $limit |
|
|
|
|
41
|
|
|
*/ |
42
|
|
|
public function allDESC($limit = NULL) |
43
|
|
|
{ |
44
|
|
|
return json_decode(json_encode($this->DESC($limit))); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get all data in json_decoded format |
49
|
|
|
*/ |
50
|
|
|
public function all() |
51
|
|
|
{ |
52
|
|
|
return json_decode(json_encode($this->getAllData())); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get the actual fetched row and return an array |
57
|
|
|
*/ |
58
|
|
|
public function toArray() |
59
|
|
|
{ |
60
|
|
|
return current($this->value); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Convert the fetched row to json |
65
|
|
|
*/ |
66
|
|
|
public function toJson($all = false) |
67
|
|
|
{ |
68
|
|
|
return $all ? json_encode($this->getAllData()) : json_encode($this->toArray()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Convert the fetched row to json |
73
|
|
|
*/ |
74
|
|
|
public function toJsonDecode() |
75
|
|
|
{ |
76
|
|
|
return json_decode($this->toJson()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the output of the first jsondecoded element |
81
|
|
|
*/ |
82
|
|
|
public function first() |
83
|
|
|
{ |
84
|
|
|
return json_decode($this->toJson()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get the count of the fetch element |
89
|
|
|
*/ |
90
|
|
|
public function getCount() |
91
|
|
|
{ |
92
|
|
|
return count($this->value); |
93
|
|
|
} |
94
|
|
|
} |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.