FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
arraybase/src/Query/Type/Select.php at master · whizsid/arraybase · GitHub
whizsid
/
arraybase
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
18
Code
Issues
1
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
arraybase
/
src
/
Query
/
Type
/
Select.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
163 lines (137 loc) · 3.88 KB
Breadcrumbs
arraybase
/
src
/
Query
/
Type
/
Select.php
Copy path
File metadata and controls
163 lines (137 loc) · 3.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
namespace
WhizSid
\
ArrayBase
\
Query
\
Type
;
use
WhizSid
\
ArrayBase
\
AB
\
DataSet
;
use
WhizSid
\
ArrayBase
\
AB
\
DataSet
\
Row
;
use
WhizSid
\
ArrayBase
\
AB
\
Table
;
use
WhizSid
\
ArrayBase
\
AB
\
Table
\
Column
;
use
WhizSid
\
ArrayBase
\
AB
\
Traits
\
KeepDataSet
;
use
WhizSid
\
ArrayBase
\
Query
\
Interfaces
\
QueryType
;
use
WhizSid
\
ArrayBase
\
Query
\
Objects
\
GroupedDataSet
;
use
WhizSid
\
ArrayBase
\
Query
\
Objects
\
Parser
;
use
WhizSid
\
ArrayBase
\
Query
\
Objects
\
ReturnSet
;
use
WhizSid
\
ArrayBase
\
Query
\
Traits
\
Groupable
;
use
WhizSid
\
ArrayBase
\
Query
\
Traits
\
Joinable
;
use
WhizSid
\
ArrayBase
\
Query
\
Traits
\
Limitable
;
use
WhizSid
\
ArrayBase
\
Query
\
Traits
\
Orderable
;
use
WhizSid
\
ArrayBase
\
Query
\
Traits
\
Whereable
;
use
WhizSid
\
ArrayBase
\
Query
\
Type
;
class
Select
extends
Type
implements
QueryType
{
use
Joinable,Whereable,Limitable,Orderable,Groupable,KeepDataSet;
/**
* Table tha in from clause.
*
* @var Table
*/
protected
$
table
;
/**
* Columns that we are selecting.
*
* @var Column[]
*/
protected
$
columns
= [];
/**
* Setting a base table.
*
* @param Table $tbl
*/
public
function
setFrom
(
$
tbl
)
{
$
this
->
table
=
$
tbl
;
// Registering the table
$
this
->
query
->
addTable
(
$
tbl
);
return
$
this
;
}
/**
* Returning the base table.
*
* @return Table
*/
public
function
getFrom
()
{
return
$
this
->
table
;
}
/**
* Setting columns in select clause.
*
* @param Column[] ...$columns
*
* @return void
*/
public
function
setColumns
(...
$
columns
)
{
$
this
->
columns
=
array_merge
(
$
this
->
columns
,
$
columns
);
return
$
this
;
}
/**
* Returning the columns.
*
* @return Column[]
*/
public
function
getColumns
()
{
return
$
this
->
columns
;
}
/**
* {@inheritdoc}
*/
public
function
execute
()
{
$
startTime
=
\microtime
(
true
);
$
this
->
resolveDataSet
();
$
this
->
executeJoin
();
$
this
->
executeWhere
();
$
this
->
executeOrder
();
$
this
->
executeGroupBy
();
$
this
->
executeSelect
();
$
this
->
executeLimit
();
$
endTime
=
\microtime
(
true
);
$
returnSet
=
new
ReturnSet
();
$
returnSet
->
setDataSet
(
$
this
->
dataSet
);
$
returnSet
->
setTime
(
$
endTime
-
$
startTime
);
return
$
returnSet
;
}
public
function
executeSelect
()
{
$
columns
=
$
this
->
columns
;
$
dataSet
=
new
DataSet
();
$
columns
=
$
this
->
columns
;
if
(
empty
(
$
columns
)) {
$
columns
=
array_values
(
$
this
->
table
->
getColumns
());
foreach
(
$
this
->
joins
as
$
key
=>
$
join
) {
$
table
=
$
join
->
getTable
();
$
joinedTableColumns
=
array_values
(
$
table
->
getColumns
());
$
columns
=
array_merge
(
$
columns
,
$
joinedTableColumns
);
}
}
foreach
(
$
columns
as
$
column
) {
$
dataSet
->
newColumn
(Parser::
parseName
(
$
column
));
}
$
rows
= [];
if
(
$
this
->
grouped
) {
/** @var GroupedDataSet $groupedSet */
foreach
(
$
this
->
groupedSets
as
$
key
=>
$
groupedSet
) {
$
row
=
new
Row
();
$
row
->
setDataSet
(
$
dataSet
);
$
row
->
setIndex
(
$
key
);
foreach
(
$
columns
as
$
column
) {
$
row
->
newCell
(
$
groupedSet
->
getValue
(
$
column
));
}
$
rows
[] =
$
row
;
}
}
else
{
$
count
=
$
this
->
dataSet
->
getCount
();
for
(
$
i
=
0
;
$
i
<
$
count
;
$
i
++) {
$
row
=
new
Row
();
$
row
->
setDataSet
(
$
dataSet
);
$
row
->
setIndex
(
$
i
);
foreach
(
$
columns
as
$
column
) {
$
row
->
newCell
(
$
this
->
dataSet
->
getValue
(
$
column
,
$
i
));
}
$
rows
[] =
$
row
;
}
}
$
dataSet
->
__setRows
(
$
rows
);
$
this
->
dataSet
=
$
dataSet
;
}
}
Back
|
FazBrowse Home
|
New Git URL