Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F547802
DivinerBookQuery.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
DivinerBookQuery.php
View Options
<?php
final
class
DivinerBookQuery
extends
PhabricatorCursorPagedPolicyAwareQuery
{
private
$ids
;
private
$phids
;
private
$names
;
private
$nameLike
;
private
$namePrefix
;
private
$repositoryPHIDs
;
private
$needProjectPHIDs
;
private
$needRepositories
;
public
function
withIDs
(
array
$ids
)
{
$this
->
ids
=
$ids
;
return
$this
;
}
public
function
withPHIDs
(
array
$phids
)
{
$this
->
phids
=
$phids
;
return
$this
;
}
public
function
withNameLike
(
$name
)
{
$this
->
nameLike
=
$name
;
return
$this
;
}
public
function
withNames
(
array
$names
)
{
$this
->
names
=
$names
;
return
$this
;
}
public
function
withNamePrefix
(
$prefix
)
{
$this
->
namePrefix
=
$prefix
;
return
$this
;
}
public
function
withRepositoryPHIDs
(
array
$repository_phids
)
{
$this
->
repositoryPHIDs
=
$repository_phids
;
return
$this
;
}
public
function
needProjectPHIDs
(
$need_phids
)
{
$this
->
needProjectPHIDs
=
$need_phids
;
return
$this
;
}
public
function
needRepositories
(
$need_repositories
)
{
$this
->
needRepositories
=
$need_repositories
;
return
$this
;
}
protected
function
loadPage
()
{
$table
=
new
DivinerLiveBook
();
$conn_r
=
$table
->
establishConnection
(
'r'
);
$data
=
queryfx_all
(
$conn_r
,
'SELECT * FROM %T %Q %Q %Q'
,
$table
->
getTableName
(),
$this
->
buildWhereClause
(
$conn_r
),
$this
->
buildOrderClause
(
$conn_r
),
$this
->
buildLimitClause
(
$conn_r
));
return
$table
->
loadAllFromArray
(
$data
);
}
protected
function
didFilterPage
(
array
$books
)
{
assert_instances_of
(
$books
,
'DivinerLiveBook'
);
if
(
$this
->
needRepositories
)
{
$repositories
=
id
(
new
PhabricatorRepositoryQuery
())
->
setViewer
(
$this
->
getViewer
())
->
withPHIDs
(
mpull
(
$books
,
'getRepositoryPHID'
))
->
execute
();
$repositories
=
mpull
(
$repositories
,
null
,
'getPHID'
);
foreach
(
$books
as
$key
=>
$book
)
{
if
(
$book
->
getRepositoryPHID
()
===
null
)
{
$book
->
attachRepository
(
null
);
continue
;
}
$repository
=
idx
(
$repositories
,
$book
->
getRepositoryPHID
());
if
(!
$repository
)
{
$this
->
didRejectResult
(
$book
);
unset
(
$books
[
$key
]);
continue
;
}
$book
->
attachRepository
(
$repository
);
}
}
if
(
$this
->
needProjectPHIDs
)
{
$edge_query
=
id
(
new
PhabricatorEdgeQuery
())
->
withSourcePHIDs
(
mpull
(
$books
,
'getPHID'
))
->
withEdgeTypes
(
array
(
PhabricatorProjectObjectHasProjectEdgeType
::
EDGECONST
,
));
$edge_query
->
execute
();
foreach
(
$books
as
$book
)
{
$project_phids
=
$edge_query
->
getDestinationPHIDs
(
array
(
$book
->
getPHID
(),
));
$book
->
attachProjectPHIDs
(
$project_phids
);
}
}
return
$books
;
}
protected
function
buildWhereClause
(
AphrontDatabaseConnection
$conn
)
{
$where
=
array
();
if
(
$this
->
ids
)
{
$where
[]
=
qsprintf
(
$conn
,
'id IN (%Ld)'
,
$this
->
ids
);
}
if
(
$this
->
phids
)
{
$where
[]
=
qsprintf
(
$conn
,
'phid IN (%Ls)'
,
$this
->
phids
);
}
if
(
phutil_nonempty_string
(
$this
->
nameLike
))
{
$where
[]
=
qsprintf
(
$conn
,
'name LIKE %~'
,
$this
->
nameLike
);
}
if
(
$this
->
names
!==
null
)
{
$where
[]
=
qsprintf
(
$conn
,
'name IN (%Ls)'
,
$this
->
names
);
}
if
(
phutil_nonempty_string
(
$this
->
namePrefix
))
{
$where
[]
=
qsprintf
(
$conn
,
'name LIKE %>'
,
$this
->
namePrefix
);
}
if
(
$this
->
repositoryPHIDs
!==
null
)
{
$where
[]
=
qsprintf
(
$conn
,
'repositoryPHID IN (%Ls)'
,
$this
->
repositoryPHIDs
);
}
$where
[]
=
$this
->
buildPagingClause
(
$conn
);
return
$this
->
formatWhereClause
(
$conn
,
$where
);
}
public
function
getQueryApplicationClass
()
{
return
PhabricatorDivinerApplication
::
class
;
}
public
function
getOrderableColumns
()
{
return
parent
::
getOrderableColumns
()
+
array
(
'name'
=>
array
(
'column'
=>
'name'
,
'type'
=>
'string'
,
'reverse'
=>
true
,
'unique'
=>
true
,
),
);
}
protected
function
newPagingMapFromPartialObject
(
$object
)
{
return
array
(
'id'
=>
(
int
)
$object
->
getID
(),
'name'
=>
$object
->
getName
(),
);
}
public
function
getBuiltinOrders
()
{
return
array
(
'name'
=>
array
(
'vector'
=>
array
(
'name'
),
'name'
=>
pht
(
'Name'
),
),
)
+
parent
::
getBuiltinOrders
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, May 12, 1:38 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
97950
Default Alt Text
DivinerBookQuery.php (4 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment