private function buildCommentForm(PhabricatorBadgesBadge $badge) { $viewer = $this->getViewer(); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); $add_comment_header = $is_serious ? pht('Add Comment') : pht('Render Honors'); $draft = PhabricatorDraft::newFromUserAndKey($viewer, $badge->getPHID()); return id(new PhabricatorApplicationTransactionCommentView())->setUser($viewer)->setObjectPHID($badge->getPHID())->setDraft($draft)->setHeaderText($add_comment_header)->setAction($this->getApplicationURI('/comment/' . $badge->getID() . '/'))->setSubmitButtonName(pht('Add Comment')); }
private function buildDetailsView(PhabricatorBadgesBadge $badge) { $viewer = $this->getViewer(); $view = id(new PHUIPropertyListView())->setUser($viewer); $description = $badge->getDescription(); if (strlen($description)) { $view->addTextContent(new PHUIRemarkupView($viewer, $description)); } $badge = id(new PHUIBadgeView())->setIcon($badge->getIcon())->setHeader($badge->getName())->setSubhead($badge->getFlavor())->setQuality($badge->getQuality()); $view->addTextContent($badge); return $view; }
public function getTitle() { $author_phid = $this->getAuthorPHID(); $object_phid = $this->getObjectPHID(); $old = $this->getOldValue(); $new = $this->getNewValue(); $type = $this->getTransactionType(); switch ($type) { case self::TYPE_NAME: if ($old === null) { return pht('%s created this badge.', $this->renderHandleLink($author_phid)); } else { return pht('%s renamed this badge from "%s" to "%s".', $this->renderHandleLink($author_phid), $old, $new); } break; case self::TYPE_FLAVOR: if ($old === null) { return pht('%s set the flavor text for this badge.', $this->renderHandleLink($author_phid)); } else { return pht('%s updated the flavor text for this badge.', $this->renderHandleLink($author_phid)); } break; case self::TYPE_DESCRIPTION: if ($old === null) { return pht('%s set the description for this badge.', $this->renderHandleLink($author_phid)); } else { return pht('%s updated the description for this badge.', $this->renderHandleLink($author_phid)); } break; case self::TYPE_ICON: if ($old === null) { return pht('%s set the icon for this badge as "%s".', $this->renderHandleLink($author_phid), $new); } else { $icon_map = PhabricatorBadgesBadge::getIconNameMap(); $icon_new = idx($icon_map, $new, $new); $icon_old = idx($icon_map, $old, $old); return pht('%s updated the icon for this badge from "%s" to "%s".', $this->renderHandleLink($author_phid), $icon_old, $icon_new); } break; case self::TYPE_QUALITY: if ($old === null) { return pht('%s set the quality for this badge as "%s".', $this->renderHandleLink($author_phid), $new); } else { $qual_map = PhabricatorBadgesBadge::getQualityNameMap(); $qual_new = idx($qual_map, $new, $new); $qual_old = idx($qual_map, $old, $old); return pht('%s updated the quality for this badge from "%s" to "%s".', $this->renderHandleLink($author_phid), $qual_old, $qual_new); } break; } return parent::getTitle(); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); if ($id) { $badge = id(new PhabricatorBadgesQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$badge) { return new Aphront404Response(); } $is_new = false; } else { $badge = PhabricatorBadgesBadge::initializeNewBadge($viewer); $is_new = true; } if ($is_new) { $title = pht('Create Badge'); $button_text = pht('Create Badge'); $cancel_uri = $this->getApplicationURI(); } else { $title = pht('Edit %s', $badge->getName()); $button_text = pht('Save Changes'); $cancel_uri = $this->getApplicationURI('view/' . $id . '/'); } $e_name = true; $v_name = $badge->getName(); $v_icon = $badge->getIcon(); $v_flav = $badge->getFlavor(); $v_desc = $badge->getDescription(); $v_qual = $badge->getQuality(); $v_stat = $badge->getStatus(); $v_edit = $badge->getEditPolicy(); $validation_exception = null; if ($request->isFormPost()) { $v_name = $request->getStr('name'); $v_flav = $request->getStr('flavor'); $v_desc = $request->getStr('description'); $v_icon = $request->getStr('icon'); $v_stat = $request->getStr('status'); $v_qual = $request->getStr('quality'); $v_view = $request->getStr('viewPolicy'); $v_edit = $request->getStr('editPolicy'); $type_name = PhabricatorBadgesTransaction::TYPE_NAME; $type_flav = PhabricatorBadgesTransaction::TYPE_FLAVOR; $type_desc = PhabricatorBadgesTransaction::TYPE_DESCRIPTION; $type_icon = PhabricatorBadgesTransaction::TYPE_ICON; $type_qual = PhabricatorBadgesTransaction::TYPE_QUALITY; $type_stat = PhabricatorBadgesTransaction::TYPE_STATUS; $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; $xactions = array(); $xactions[] = id(new PhabricatorBadgesTransaction())->setTransactionType($type_name)->setNewValue($v_name); $xactions[] = id(new PhabricatorBadgesTransaction())->setTransactionType($type_flav)->setNewValue($v_flav); $xactions[] = id(new PhabricatorBadgesTransaction())->setTransactionType($type_desc)->setNewValue($v_desc); $xactions[] = id(new PhabricatorBadgesTransaction())->setTransactionType($type_icon)->setNewValue($v_icon); $xactions[] = id(new PhabricatorBadgesTransaction())->setTransactionType($type_qual)->setNewValue($v_qual); $xactions[] = id(new PhabricatorBadgesTransaction())->setTransactionType($type_stat)->setNewValue($v_stat); $xactions[] = id(new PhabricatorBadgesTransaction())->setTransactionType($type_edit)->setNewValue($v_edit); $editor = id(new PhabricatorBadgesEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true); try { $editor->applyTransactions($badge, $xactions); $return_uri = $this->getApplicationURI('view/' . $badge->getID() . '/'); return id(new AphrontRedirectResponse())->setURI($return_uri); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; $e_name = $ex->getShortMessage($type_name); } } if ($is_new) { $icon_uri = $this->getApplicationURI('icon/'); } else { $icon_uri = $this->getApplicationURI('icon/' . $badge->getID() . '/'); } $icon_display = PhabricatorBadgesIcon::renderIconForChooser($v_icon); $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($badge)->execute(); $form = id(new AphrontFormView())->setUser($viewer)->appendChild(id(new AphrontFormTextControl())->setName('name')->setLabel(pht('Name'))->setValue($v_name)->setError($e_name))->appendChild(id(new AphrontFormTextControl())->setName('flavor')->setLabel(pht('Flavor Text'))->setValue($v_flav))->appendChild(id(new AphrontFormChooseButtonControl())->setLabel(pht('Icon'))->setName('icon')->setDisplayValue($icon_display)->setButtonText(pht('Choose Icon...'))->setChooseURI($icon_uri)->setValue($v_icon))->appendChild(id(new AphrontFormSelectControl())->setName('quality')->setLabel(pht('Quality'))->setValue($v_qual)->setOptions($badge->getQualityNameMap()))->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Status'))->setName('status')->setValue($v_stat)->setOptions($badge->getStatusNameMap()))->appendChild(id(new PhabricatorRemarkupControl())->setUser($viewer)->setName('description')->setLabel(pht('Description'))->setValue($v_desc))->appendChild(id(new AphrontFormPolicyControl())->setName('editPolicy')->setPolicyObject($badge)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setValue($v_edit)->setPolicies($policies))->appendChild(id(new AphrontFormSubmitControl())->setValue($button_text)->addCancelButton($cancel_uri)); $crumbs = $this->buildApplicationCrumbs(); if ($is_new) { $crumbs->addTextCrumb(pht('Create Badge')); } else { $crumbs->addTextCrumb($badge->getName(), '/badges/view/' . $badge->getID() . '/'); $crumbs->addTextCrumb(pht('Edit')); } $box = id(new PHUIObjectBoxView())->setValidationException($validation_exception)->setHeaderText($title)->appendChild($form); return $this->buildApplicationPage(array($crumbs, $box), array('title' => $title)); }
protected function newEditableObject() { return PhabricatorBadgesBadge::initializeNewBadge($this->getViewer()); }
<?php $table = new PhabricatorBadgesBadge(); $conn_w = $table->establishConnection('w'); $iterator = new LiskMigrationIterator($table); foreach ($iterator as $badge) { $id = $badge->getID(); echo pht('Adding mail key for badge %d...', $id); echo "\n"; queryfx($conn_w, 'UPDATE %T SET mailKey = %s WHERE id = %d', $table->getTableName(), Filesystem::readRandomCharacters(20), $id); }