Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F940989
PhortuneAccountQuery.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
PhortuneAccountQuery.php
View Options
<?php
final
class
PhortuneAccountQuery
extends
PhabricatorCursorPagedPolicyAwareQuery
{
private
$ids
;
private
$phids
;
private
$memberPHIDs
;
public
static
function
loadAccountsForUser
(
PhabricatorUser
$user
,
PhabricatorContentSource
$content_source
)
{
$accounts
=
id
(
new
PhortuneAccountQuery
())
->
setViewer
(
$user
)
->
withMemberPHIDs
(
array
(
$user
->
getPHID
()))
->
execute
();
if
(!
$accounts
)
{
$accounts
=
array
(
PhortuneAccount
::
createNewAccount
(
$user
,
$content_source
),
);
}
$accounts
=
mpull
(
$accounts
,
null
,
'getPHID'
);
return
$accounts
;
}
public
function
withIDs
(
array
$ids
)
{
$this
->
ids
=
$ids
;
return
$this
;
}
public
function
withPHIDs
(
array
$phids
)
{
$this
->
phids
=
$phids
;
return
$this
;
}
public
function
withMemberPHIDs
(
array
$phids
)
{
$this
->
memberPHIDs
=
$phids
;
return
$this
;
}
public
function
newResultObject
()
{
return
new
PhortuneAccount
();
}
protected
function
willFilterPage
(
array
$accounts
)
{
$query
=
id
(
new
PhabricatorEdgeQuery
())
->
withSourcePHIDs
(
mpull
(
$accounts
,
'getPHID'
))
->
withEdgeTypes
(
array
(
PhortuneAccountHasMemberEdgeType
::
EDGECONST
,
PhortuneAccountHasMerchantEdgeType
::
EDGECONST
,
));
$query
->
execute
();
foreach
(
$accounts
as
$account
)
{
$member_phids
=
$query
->
getDestinationPHIDs
(
array
(
$account
->
getPHID
(),
),
array
(
PhortuneAccountHasMemberEdgeType
::
EDGECONST
,
));
$member_phids
=
array_reverse
(
$member_phids
);
$account
->
attachMemberPHIDs
(
$member_phids
);
$merchant_phids
=
$query
->
getDestinationPHIDs
(
array
(
$account
->
getPHID
(),
),
array
(
PhortuneAccountHasMerchantEdgeType
::
EDGECONST
,
));
$merchant_phids
=
array_reverse
(
$merchant_phids
);
$account
->
attachMerchantPHIDs
(
$merchant_phids
);
}
return
$accounts
;
}
protected
function
buildWhereClauseParts
(
AphrontDatabaseConnection
$conn
)
{
$where
=
parent
::
buildWhereClauseParts
(
$conn
);
if
(
$this
->
ids
!==
null
)
{
$where
[]
=
qsprintf
(
$conn
,
'a.id IN (%Ld)'
,
$this
->
ids
);
}
if
(
$this
->
phids
!==
null
)
{
$where
[]
=
qsprintf
(
$conn
,
'a.phid IN (%Ls)'
,
$this
->
phids
);
}
if
(
$this
->
memberPHIDs
!==
null
)
{
$where
[]
=
qsprintf
(
$conn
,
'm.dst IN (%Ls)'
,
$this
->
memberPHIDs
);
}
return
$where
;
}
protected
function
buildJoinClauseParts
(
AphrontDatabaseConnection
$conn
)
{
$joins
=
parent
::
buildJoinClauseParts
(
$conn
);
if
(
$this
->
memberPHIDs
!==
null
)
{
$joins
[]
=
qsprintf
(
$conn
,
'LEFT JOIN %T m ON a.phid = m.src AND m.type = %d'
,
PhabricatorEdgeConfig
::
TABLE_NAME_EDGE
,
PhortuneAccountHasMemberEdgeType
::
EDGECONST
);
}
return
$joins
;
}
public
function
getQueryApplicationClass
()
{
return
PhabricatorPhortuneApplication
::
class
;
}
protected
function
getPrimaryTableAlias
()
{
return
'a'
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Jun 17, 6:58 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
216044
Default Alt Text
PhortuneAccountQuery.php (3 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment