Changeset View
Changeset View
Standalone View
Standalone View
src/applications/badges/phid/PhabricatorBadgesPHIDType.php
- This file was added.
<?php | |||||
final class PhabricatorBadgesPHIDType extends PhabricatorPHIDType { | |||||
const TYPECONST = 'BDGE'; | |||||
public function getTypeName() { | |||||
return pht('Badge'); | |||||
} | |||||
public function newObject() { | |||||
return new PhabricatorBadge(); | |||||
} | |||||
public function getPHIDTypeApplicationClass() { | |||||
return 'PhabricatorBadgesApplication'; | |||||
} | |||||
protected function buildQueryForObjects( | |||||
PhabricatorObjectQuery $query, | |||||
array $phids) { | |||||
return id(new PhabricatorBadgesQuery()) | |||||
->withPHIDs($phids); | |||||
} | |||||
public function loadHandles( | |||||
PhabricatorHandleQuery $query, | |||||
array $handles, | |||||
array $objects) { | |||||
foreach ($handles as $phid => $handle) { | |||||
$badge = $objects[$phid]; | |||||
$id = $badge->getID(); | |||||
$name = $badge->getName(); | |||||
if ($badge->isClosed()) { | |||||
$handle->setStatus(PhabricatorObjectHandle::STATUS_CLOSED); | |||||
} | |||||
$handle->setName($name); | |||||
$handle->setFullName("{$name}"); | |||||
$handle->setURI("/badges/view/{$id}/"); | |||||
epriestley: You can omit this if it's the same as `setName()`. | |||||
} | |||||
} | |||||
public function loadNamedObjects( | |||||
PhabricatorObjectQuery $query, | |||||
array $names) { | |||||
$id_map = array(); | |||||
foreach ($names as $name) { | |||||
$id = (int)substr($name, 1); | |||||
$id_map[$id][] = $name; | |||||
} | |||||
$objects = id(new PhabricatorBadgesQuery()) | |||||
->setViewer($query->getViewer()) | |||||
->withIDs(array_keys($id_map)) | |||||
->execute(); | |||||
$results = array(); | |||||
foreach ($objects as $id => $object) { | |||||
foreach (idx($id_map, $id, array()) as $name) { | |||||
$results[$name] = $object; | |||||
} | |||||
} | |||||
return $results; | |||||
} | |||||
Done Inline ActionsSince this PHIDType does not implement canLoadNamedObject() (and should not -- I think badges aren't core/important enough to get monograms), this method will never be called. You can just remove it. epriestley: Since this `PHIDType` does not implement `canLoadNamedObject()` (and should not -- I think… | |||||
} |
You can omit this if it's the same as setName().