2015-07-22 22:37:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
|
|
|
|
implements
|
|
|
|
PhabricatorPolicyInterface,
|
|
|
|
PhabricatorApplicationTransactionInterface,
|
|
|
|
PhabricatorSubscribableInterface,
|
2015-07-28 16:57:15 +02:00
|
|
|
PhabricatorTokenReceiverInterface,
|
2015-07-22 22:37:20 +02:00
|
|
|
PhabricatorFlaggableInterface,
|
|
|
|
PhabricatorDestructibleInterface {
|
|
|
|
|
|
|
|
protected $name;
|
|
|
|
protected $flavor;
|
|
|
|
protected $description;
|
|
|
|
protected $icon;
|
|
|
|
protected $quality;
|
2015-07-25 22:34:43 +02:00
|
|
|
protected $mailKey;
|
2015-07-22 22:37:20 +02:00
|
|
|
protected $editPolicy;
|
|
|
|
protected $status;
|
|
|
|
protected $creatorPHID;
|
|
|
|
|
|
|
|
private $recipientPHIDs = self::ATTACHABLE;
|
|
|
|
|
2015-12-09 22:26:26 +01:00
|
|
|
const STATUS_ACTIVE = 'open';
|
|
|
|
const STATUS_ARCHIVED = 'closed';
|
2015-07-22 22:37:20 +02:00
|
|
|
|
|
|
|
const DEFAULT_ICON = 'fa-star';
|
|
|
|
const DEFAULT_QUALITY = 'green';
|
|
|
|
|
|
|
|
const POOR = 'grey';
|
|
|
|
const COMMON = 'white';
|
|
|
|
const UNCOMMON = 'green';
|
|
|
|
const RARE = 'blue';
|
|
|
|
const EPIC = 'indigo';
|
|
|
|
const LEGENDARY = 'orange';
|
|
|
|
const HEIRLOOM = 'yellow';
|
|
|
|
|
|
|
|
public static function getStatusNameMap() {
|
|
|
|
return array(
|
2015-12-09 22:26:26 +01:00
|
|
|
self::STATUS_ACTIVE => pht('Active'),
|
|
|
|
self::STATUS_ARCHIVED => pht('Archived'),
|
2015-07-22 22:37:20 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getQualityNameMap() {
|
|
|
|
return array(
|
|
|
|
self::POOR => pht('Poor'),
|
|
|
|
self::COMMON => pht('Common'),
|
|
|
|
self::UNCOMMON => pht('Uncommon'),
|
|
|
|
self::RARE => pht('Rare'),
|
|
|
|
self::EPIC => pht('Epic'),
|
|
|
|
self::LEGENDARY => pht('Legendary'),
|
|
|
|
self::HEIRLOOM => pht('Heirloom'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function initializeNewBadge(PhabricatorUser $actor) {
|
|
|
|
$app = id(new PhabricatorApplicationQuery())
|
|
|
|
->setViewer($actor)
|
|
|
|
->withClasses(array('PhabricatorBadgesApplication'))
|
|
|
|
->executeOne();
|
|
|
|
|
2015-07-24 20:03:43 +02:00
|
|
|
$view_policy = PhabricatorPolicies::getMostOpenPolicy();
|
2015-07-22 22:37:20 +02:00
|
|
|
|
|
|
|
$edit_policy =
|
|
|
|
$app->getPolicy(PhabricatorBadgesDefaultEditCapability::CAPABILITY);
|
|
|
|
|
|
|
|
return id(new PhabricatorBadgesBadge())
|
|
|
|
->setIcon(self::DEFAULT_ICON)
|
|
|
|
->setQuality(self::DEFAULT_QUALITY)
|
|
|
|
->setCreatorPHID($actor->getPHID())
|
|
|
|
->setEditPolicy($edit_policy)
|
2015-12-09 22:26:26 +01:00
|
|
|
->setStatus(self::STATUS_ACTIVE);
|
2015-07-22 22:37:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
|
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
|
|
|
'name' => 'text255',
|
|
|
|
'flavor' => 'text255',
|
|
|
|
'description' => 'text',
|
|
|
|
'icon' => 'text255',
|
|
|
|
'quality' => 'text255',
|
|
|
|
'status' => 'text32',
|
2015-07-25 22:34:43 +02:00
|
|
|
'mailKey' => 'bytes20',
|
2015-07-22 22:37:20 +02:00
|
|
|
),
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
|
|
'key_creator' => array(
|
|
|
|
'columns' => array('creatorPHID', 'dateModified'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
|
|
|
return
|
|
|
|
PhabricatorPHID::generateNewPHID(PhabricatorBadgesPHIDType::TYPECONST);
|
|
|
|
}
|
|
|
|
|
2015-12-09 22:26:26 +01:00
|
|
|
public function isArchived() {
|
|
|
|
return ($this->getStatus() == self::STATUS_ARCHIVED);
|
2015-07-22 22:37:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachRecipientPHIDs(array $phids) {
|
|
|
|
$this->recipientPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRecipientPHIDs() {
|
|
|
|
return $this->assertAttached($this->recipientPHIDs);
|
|
|
|
}
|
|
|
|
|
2015-07-25 22:34:43 +02:00
|
|
|
public function save() {
|
|
|
|
if (!$this->getMailKey()) {
|
|
|
|
$this->setMailKey(Filesystem::readRandomCharacters(20));
|
|
|
|
}
|
|
|
|
return parent::save();
|
|
|
|
}
|
|
|
|
|
2015-07-22 22:37:20 +02:00
|
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
2015-07-24 20:03:43 +02:00
|
|
|
return PhabricatorPolicies::getMostOpenPolicy();
|
2015-07-22 22:37:20 +02:00
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
return $this->getEditPolicy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getApplicationTransactionEditor() {
|
|
|
|
return new PhabricatorBadgesEditor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionObject() {
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionTemplate() {
|
|
|
|
return new PhabricatorBadgesTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function willRenderTimeline(
|
|
|
|
PhabricatorApplicationTransactionView $timeline,
|
|
|
|
AphrontRequest $request) {
|
|
|
|
|
|
|
|
return $timeline;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -( PhabricatorSubscribableInterface )----------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function isAutomaticallySubscribed($phid) {
|
|
|
|
return ($this->creatorPHID == $phid);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldShowSubscribersProperty() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldAllowSubscription($phid) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-28 16:57:15 +02:00
|
|
|
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getUsersToNotifyOfTokenGiven() {
|
|
|
|
return array($this->getCreatorPHID());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-22 22:37:20 +02:00
|
|
|
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function destroyObjectPermanently(
|
|
|
|
PhabricatorDestructionEngine $engine) {
|
|
|
|
|
|
|
|
$this->openTransaction();
|
|
|
|
$this->delete();
|
|
|
|
$this->saveTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|