Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92815446
PhabricatorBadgesBadgeAwardTransaction.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Nov 23, 22:20
Size
2 KB
Mime Type
text/x-php
Expires
Mon, Nov 25, 22:20 (2 d)
Engine
blob
Format
Raw Data
Handle
22519640
Attached To
rPH Phabricator
PhabricatorBadgesBadgeAwardTransaction.php
View Options
<?php
final
class
PhabricatorBadgesBadgeAwardTransaction
extends
PhabricatorBadgesBadgeTransactionType
{
const
TRANSACTIONTYPE
=
'badge.award'
;
public
function
generateOldValue
(
$object
)
{
return
null
;
}
public
function
applyExternalEffects
(
$object
,
$value
)
{
foreach
(
$value
as
$phid
)
{
$award
=
PhabricatorBadgesAward
::
initializeNewBadgesAward
(
$this
->
getActor
(),
$object
,
$phid
);
$award
->
save
();
}
return
;
}
public
function
getTitle
()
{
$new
=
$this
->
getNewValue
();
if
(!
is_array
(
$new
))
{
$new
=
array
();
}
$handles
=
$this
->
renderHandleList
(
$new
);
return
pht
(
'%s awarded this badge to %s recipient(s): %s.'
,
$this
->
renderAuthor
(),
new
PhutilNumber
(
count
(
$new
)),
$handles
);
}
public
function
getTitleForFeed
()
{
$new
=
$this
->
getNewValue
();
if
(!
is_array
(
$new
))
{
$new
=
array
();
}
$handles
=
$this
->
renderHandleList
(
$new
);
return
pht
(
'%s awarded %s to %s recipient(s): %s.'
,
$this
->
renderAuthor
(),
$this
->
renderObject
(),
new
PhutilNumber
(
count
(
$new
)),
$handles
);
}
public
function
getIcon
()
{
return
'fa-user-plus'
;
}
public
function
validateTransactions
(
$object
,
array
$xactions
)
{
$errors
=
array
();
foreach
(
$xactions
as
$xaction
)
{
$user_phids
=
$xaction
->
getNewValue
();
if
(!
$user_phids
)
{
$errors
[]
=
$this
->
newRequiredError
(
pht
(
'Recipient is required.'
));
continue
;
}
foreach
(
$user_phids
as
$user_phid
)
{
// Check if a valid user
$user
=
id
(
new
PhabricatorPeopleQuery
())
->
setViewer
(
$this
->
getActor
())
->
withPHIDs
(
array
(
$user_phid
))
->
executeOne
();
if
(!
$user
)
{
$errors
[]
=
$this
->
newInvalidError
(
pht
(
'Recipient PHID "%s" is not a valid user PHID.'
,
$user_phid
));
continue
;
}
// Check if already awarded
$award
=
id
(
new
PhabricatorBadgesAwardQuery
())
->
setViewer
(
$this
->
getActor
())
->
withRecipientPHIDs
(
array
(
$user_phid
))
->
withBadgePHIDs
(
array
(
$object
->
getPHID
()))
->
executeOne
();
if
(
$award
)
{
$errors
[]
=
$this
->
newInvalidError
(
pht
(
'%s has already been awarded this badge.'
,
$user
->
getUsername
()));
}
}
}
return
$errors
;
}
}
Event Timeline
Log In to Comment