Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / badges / storage / PhabricatorBadgesBadge.php
blob2fc787d9eeff625a5cd71960eab3ee2351ca577b
1 <?php
3 final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
4 implements
5 PhabricatorPolicyInterface,
6 PhabricatorApplicationTransactionInterface,
7 PhabricatorSubscribableInterface,
8 PhabricatorFlaggableInterface,
9 PhabricatorDestructibleInterface,
10 PhabricatorConduitResultInterface,
11 PhabricatorNgramsInterface {
13 protected $name;
14 protected $flavor;
15 protected $description;
16 protected $icon;
17 protected $quality;
18 protected $mailKey;
19 protected $editPolicy;
20 protected $status;
21 protected $creatorPHID;
23 const STATUS_ACTIVE = 'open';
24 const STATUS_ARCHIVED = 'closed';
26 const DEFAULT_ICON = 'fa-star';
28 public static function getStatusNameMap() {
29 return array(
30 self::STATUS_ACTIVE => pht('Active'),
31 self::STATUS_ARCHIVED => pht('Archived'),
35 public static function initializeNewBadge(PhabricatorUser $actor) {
36 $app = id(new PhabricatorApplicationQuery())
37 ->setViewer($actor)
38 ->withClasses(array('PhabricatorBadgesApplication'))
39 ->executeOne();
41 $view_policy = PhabricatorPolicies::getMostOpenPolicy();
43 $edit_policy =
44 $app->getPolicy(PhabricatorBadgesDefaultEditCapability::CAPABILITY);
46 return id(new PhabricatorBadgesBadge())
47 ->setIcon(self::DEFAULT_ICON)
48 ->setQuality(PhabricatorBadgesQuality::DEFAULT_QUALITY)
49 ->setCreatorPHID($actor->getPHID())
50 ->setEditPolicy($edit_policy)
51 ->setFlavor('')
52 ->setDescription('')
53 ->setStatus(self::STATUS_ACTIVE);
56 protected function getConfiguration() {
57 return array(
58 self::CONFIG_AUX_PHID => true,
59 self::CONFIG_COLUMN_SCHEMA => array(
60 'name' => 'sort255',
61 'flavor' => 'text255',
62 'description' => 'text',
63 'icon' => 'text255',
64 'quality' => 'uint32',
65 'status' => 'text32',
66 'mailKey' => 'bytes20',
68 self::CONFIG_KEY_SCHEMA => array(
69 'key_creator' => array(
70 'columns' => array('creatorPHID', 'dateModified'),
73 ) + parent::getConfiguration();
76 public function generatePHID() {
77 return
78 PhabricatorPHID::generateNewPHID(PhabricatorBadgesPHIDType::TYPECONST);
81 public function isArchived() {
82 return ($this->getStatus() == self::STATUS_ARCHIVED);
85 public function getViewURI() {
86 return '/badges/view/'.$this->getID().'/';
89 public function save() {
90 if (!$this->getMailKey()) {
91 $this->setMailKey(Filesystem::readRandomCharacters(20));
93 return parent::save();
97 /* -( PhabricatorPolicyInterface )----------------------------------------- */
100 public function getCapabilities() {
101 return array(
102 PhabricatorPolicyCapability::CAN_VIEW,
103 PhabricatorPolicyCapability::CAN_EDIT,
107 public function getPolicy($capability) {
108 switch ($capability) {
109 case PhabricatorPolicyCapability::CAN_VIEW:
110 return PhabricatorPolicies::getMostOpenPolicy();
111 case PhabricatorPolicyCapability::CAN_EDIT:
112 return $this->getEditPolicy();
116 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
117 return false;
121 /* -( PhabricatorApplicationTransactionInterface )------------------------- */
124 public function getApplicationTransactionEditor() {
125 return new PhabricatorBadgesEditor();
128 public function getApplicationTransactionTemplate() {
129 return new PhabricatorBadgesTransaction();
133 /* -( PhabricatorSubscribableInterface )----------------------------------- */
136 public function isAutomaticallySubscribed($phid) {
137 return false;
142 /* -( PhabricatorDestructibleInterface )----------------------------------- */
145 public function destroyObjectPermanently(
146 PhabricatorDestructionEngine $engine) {
148 $awards = id(new PhabricatorBadgesAwardQuery())
149 ->setViewer($engine->getViewer())
150 ->withBadgePHIDs(array($this->getPHID()))
151 ->execute();
153 foreach ($awards as $award) {
154 $engine->destroyObject($award);
157 $this->openTransaction();
158 $this->delete();
159 $this->saveTransaction();
162 /* -( PhabricatorConduitResultInterface )---------------------------------- */
165 public function getFieldSpecificationsForConduit() {
166 return array(
167 id(new PhabricatorConduitSearchFieldSpecification())
168 ->setKey('name')
169 ->setType('string')
170 ->setDescription(pht('The name of the badge.')),
171 id(new PhabricatorConduitSearchFieldSpecification())
172 ->setKey('creatorPHID')
173 ->setType('phid')
174 ->setDescription(pht('User PHID of the creator.')),
175 id(new PhabricatorConduitSearchFieldSpecification())
176 ->setKey('status')
177 ->setType('string')
178 ->setDescription(pht('Active or archived status of the badge.')),
182 public function getFieldValuesForConduit() {
183 return array(
184 'name' => $this->getName(),
185 'creatorPHID' => $this->getCreatorPHID(),
186 'status' => $this->getStatus(),
190 public function getConduitSearchAttachments() {
191 return array();
194 /* -( PhabricatorNgramInterface )------------------------------------------ */
197 public function newNgrams() {
198 return array(
199 id(new PhabricatorBadgesBadgeNameNgrams())
200 ->setValue($this->getName()),