本文整理汇总了PHP中mpull函数的典型用法代码示例。如果您正苦于以下问题:PHP mpull函数的具体用法?PHP mpull怎么用?PHP mpull使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mpull函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildQueryFromSavedQuery
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved)
{
$query = id(new PhortuneSubscriptionQuery());
$viewer = $this->requireViewer();
$merchant = $this->getMerchant();
$account = $this->getAccount();
if ($merchant) {
$can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $merchant, PhabricatorPolicyCapability::CAN_EDIT);
if (!$can_edit) {
throw new Exception(pht('You can not query subscriptions for a merchant you do not ' . 'control.'));
}
$query->withMerchantPHIDs(array($merchant->getPHID()));
} else {
if ($account) {
$can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $account, PhabricatorPolicyCapability::CAN_EDIT);
if (!$can_edit) {
throw new Exception(pht('You can not query subscriptions for an account you are not ' . 'a member of.'));
}
$query->withAccountPHIDs(array($account->getPHID()));
} else {
$accounts = id(new PhortuneAccountQuery())->withMemberPHIDs(array($viewer->getPHID()))->execute();
if ($accounts) {
$query->withAccountPHIDs(mpull($accounts, 'getPHID'));
} else {
throw new Exception(pht('You have no accounts!'));
}
}
}
return $query;
}
示例2: willFilterPage
protected function willFilterPage(array $comments)
{
if ($this->needReplyToComments) {
$reply_phids = array();
foreach ($comments as $comment) {
$reply_phid = $comment->getReplyToCommentPHID();
if ($reply_phid) {
$reply_phids[] = $reply_phid;
}
}
if ($reply_phids) {
$reply_comments = newv(get_class($this), array())->setViewer($this->getViewer())->setParentQuery($this)->withPHIDs($reply_phids)->execute();
$reply_comments = mpull($reply_comments, null, 'getPHID');
} else {
$reply_comments = array();
}
foreach ($comments as $key => $comment) {
$reply_phid = $comment->getReplyToCommentPHID();
if (!$reply_phid) {
$comment->attachReplyToComment(null);
continue;
}
$reply = idx($reply_comments, $reply_phid);
if (!$reply) {
$this->didRejectResult($comment);
unset($comments[$key]);
continue;
}
$comment->attachReplyToComment($reply);
}
}
return $comments;
}
示例3: execute
public function execute(PhutilArgumentParser $args)
{
$can_recover = id(new PhabricatorPeopleQuery())->setViewer($this->getViewer())->withIsAdmin(true)->execute();
if (!$can_recover) {
throw new PhutilArgumentUsageException(pht('This Phabricator installation has no recoverable administrator ' . 'accounts. You can use `bin/accountadmin` to create a new ' . 'administrator account or make an existing user an administrator.'));
}
$can_recover = mpull($can_recover, 'getUsername');
sort($can_recover);
$can_recover = implode(', ', $can_recover);
$usernames = $args->getArg('username');
if (!$usernames) {
throw new PhutilArgumentUsageException(pht('You must specify the username of the account to recover.'));
} else {
if (count($usernames) > 1) {
throw new PhutilArgumentUsageException(pht('You can only recover the username for one account.'));
}
}
$username = head($usernames);
$user = id(new PhabricatorPeopleQuery())->setViewer($this->getViewer())->withUsernames(array($username))->executeOne();
if (!$user) {
throw new PhutilArgumentUsageException(pht('No such user "%s". Recoverable administrator accounts are: %s.', $username, $can_recover));
}
if (!$user->getIsAdmin()) {
throw new PhutilArgumentUsageException(pht('You can only recover administrator accounts, but %s is not an ' . 'administrator. Recoverable administrator accounts are: %s.', $username, $can_recover));
}
$engine = new PhabricatorAuthSessionEngine();
$onetime_uri = $engine->getOneTimeLoginURI($user, null, PhabricatorAuthSessionEngine::ONETIME_RECOVER);
$console = PhutilConsole::getConsole();
$console->writeOut(pht('Use this link to recover access to the "%s" account from the web ' . 'interface:', $username));
$console->writeOut("\n\n");
$console->writeOut(' %s', $onetime_uri);
$console->writeOut("\n\n");
$console->writeOut(pht('After logging in, you can use the "Auth" application to add or ' . 'restore authentication providers and allow normal logins to ' . 'succeed.') . "\n");
return 0;
}
示例4: getGitResult
protected function getGitResult(ConduitAPIRequest $request)
{
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$commit = $drequest->getSymbolicCommit();
$commit_filter = null;
if ($commit) {
$commit_filter = $this->loadTagNamesForCommit($commit);
}
$name_filter = $request->getValue('names', null);
$all_tags = $this->loadGitTagList();
$all_tags = mpull($all_tags, null, 'getName');
if ($name_filter !== null) {
$all_tags = array_intersect_key($all_tags, array_fuse($name_filter));
}
if ($commit_filter !== null) {
$all_tags = array_intersect_key($all_tags, $commit_filter);
}
$tags = array_values($all_tags);
$offset = $request->getValue('offset');
$limit = $request->getValue('limit');
if ($offset) {
$tags = array_slice($tags, $offset);
}
if ($limit) {
$tags = array_slice($tags, 0, $limit);
}
if ($request->getValue('needMessages')) {
$this->loadMessagesForTags($all_tags);
}
return mpull($tags, 'toDictionary');
}
示例5: willFilterPage
protected function willFilterPage(array $page)
{
if ($this->needSecrets) {
$secret_ids = mpull($page, 'getSecretID');
$secret_ids = array_filter($secret_ids);
$secrets = array();
if ($secret_ids) {
$secret_objects = id(new PassphraseSecret())->loadAllWhere('id IN (%Ld)', $secret_ids);
foreach ($secret_objects as $secret) {
$secret_data = $secret->getSecretData();
$secrets[$secret->getID()] = new PhutilOpaqueEnvelope($secret_data);
}
}
foreach ($page as $key => $credential) {
$secret_id = $credential->getSecretID();
if (!$secret_id) {
$credential->attachSecret(null);
} else {
if (isset($secrets[$secret_id])) {
$credential->attachSecret($secrets[$secret_id]);
} else {
unset($page[$key]);
}
}
}
}
return $page;
}
示例6: renderEditControl
public function renderEditControl(array $handles)
{
$engines = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorApplicationSearchEngine')->loadObjects();
$value = $this->getFieldValue();
$queries = array();
$seen = false;
foreach ($engines as $engine_class => $engine) {
$engine->setViewer($this->getViewer());
$engine_queries = $engine->loadEnabledNamedQueries();
$query_map = mpull($engine_queries, 'getQueryName', 'getQueryKey');
asort($query_map);
foreach ($query_map as $key => $name) {
$queries[$engine_class][] = array('key' => $key, 'name' => $name);
if ($key == $value) {
$seen = true;
}
}
}
if (strlen($value) && !$seen) {
$name = pht('Custom Query ("%s")', $value);
} else {
$name = pht('(None)');
}
$options = array($value => $name);
$app_control_key = $this->getFieldConfigValue('control.application');
Javelin::initBehavior('dashboard-query-panel-select', array('applicationID' => $this->getFieldControlID($app_control_key), 'queryID' => $this->getFieldControlID(), 'options' => $queries, 'value' => array('key' => strlen($value) ? $value : null, 'name' => $name)));
return id(new AphrontFormSelectControl())->setID($this->getFieldControlID())->setLabel($this->getFieldName())->setCaption($this->getCaption())->setName($this->getFieldKey())->setValue($this->getFieldValue())->setOptions($options);
}
示例7: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getViewer();
$pager = new PHUIPagerView();
$pager->setURI($request->getRequestURI(), 'page');
$pager->setOffset($request->getInt('page'));
$query = id(new PhabricatorTokenReceiverQuery());
$objects = $query->setViewer($viewer)->executeWithOffsetPager($pager);
$counts = $query->getTokenCounts();
$handles = array();
$phids = array();
if ($counts) {
$phids = mpull($objects, 'getPHID');
$handles = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs($phids)->execute();
}
$list = new PHUIObjectItemListView();
foreach ($phids as $object) {
$count = idx($counts, $object, 0);
$item = id(new PHUIObjectItemView());
$handle = $handles[$object];
$item->setHeader($handle->getFullName());
$item->setHref($handle->getURI());
$item->addAttribute(pht('Tokens: %s', $count));
$list->addItem($item);
}
$title = pht('Token Leader Board');
$box = id(new PHUIObjectBoxView())->setHeaderText($title)->setObjectList($list);
$nav = $this->buildSideNav();
$nav->setCrumbs($this->buildApplicationCrumbs()->addTextCrumb($title));
$nav->selectFilter('leaders/');
$nav->appendChild($box);
$nav->appendChild($pager);
return $this->newPage()->setTitle($title)->appendChild($nav);
}
示例8: renderResultList
protected function renderResultList(array $polls, PhabricatorSavedQuery $query, array $handles)
{
assert_instances_of($polls, 'PhabricatorSlowvotePoll');
$viewer = $this->requireViewer();
$list = id(new PHUIObjectItemListView())->setUser($viewer);
$phids = mpull($polls, 'getAuthorPHID');
foreach ($polls as $poll) {
$date_created = phabricator_datetime($poll->getDateCreated(), $viewer);
if ($poll->getAuthorPHID()) {
$author = $handles[$poll->getAuthorPHID()]->renderLink();
} else {
$author = null;
}
$item = id(new PHUIObjectItemView())->setUser($viewer)->setObject($poll)->setObjectName('V' . $poll->getID())->setHeader($poll->getQuestion())->setHref('/V' . $poll->getID())->addIcon('none', $date_created);
if ($poll->getIsClosed()) {
$item->setStatusIcon('fa-ban grey');
$item->setDisabled(true);
} else {
$item->setStatusIcon('fa-bar-chart');
}
$description = $poll->getDescription();
if (strlen($description)) {
$item->addAttribute(id(new PhutilUTF8StringTruncator())->setMaximumGlyphs(120)->truncateString($poll->getDescription()));
}
if ($author) {
$item->addByline(pht('Author: %s', $author));
}
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No polls found.'));
return $result;
}
示例9: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$post = id(new PhamePostQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_VIEW))->executeOne();
if (!$post) {
return new Aphront404Response();
}
$view_uri = '/post/view/' . $post->getID() . '/';
$view_uri = $this->getApplicationURI($view_uri);
if ($request->isFormPost()) {
$blog = id(new PhameBlogQuery())->setViewer($viewer)->withIDs(array($request->getInt('blog')))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
if ($blog) {
$post->setBlogPHID($blog->getPHID());
$post->save();
return id(new AphrontRedirectResponse())->setURI($view_uri . '?moved=1');
}
}
$blogs = id(new PhameBlogQuery())->setViewer($viewer)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))->execute();
$options = mpull($blogs, 'getName', 'getID');
asort($options);
$selected_value = null;
if ($post && $post->getBlog()) {
$selected_value = $post->getBlog()->getID();
}
$form = id(new PHUIFormLayoutView())->setUser($viewer)->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Blog'))->setName('blog')->setOptions($options)->setValue($selected_value));
return $this->newDialog()->setTitle(pht('Move Post'))->appendChild($form)->addSubmitButton(pht('Move Post'))->addCancelButton($view_uri);
}
示例10: buildPaymentMethodsSection
private function buildPaymentMethodsSection(PhortuneAccount $account)
{
$request = $this->getRequest();
$viewer = $request->getUser();
$can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $account, PhabricatorPolicyCapability::CAN_EDIT);
$id = $account->getID();
$header = id(new PHUIHeaderView())->setHeader(pht('Payment Methods'))->addActionLink(id(new PHUIButtonView())->setTag('a')->setHref($this->getApplicationURI($id . '/card/new/'))->setText(pht('Add Payment Method'))->setIcon(id(new PHUIIconView())->setIconFont('fa-plus')));
$list = id(new PHUIObjectItemListView())->setUser($viewer)->setNoDataString(pht('No payment methods associated with this account.'));
$methods = id(new PhortunePaymentMethodQuery())->setViewer($viewer)->withAccountPHIDs(array($account->getPHID()))->execute();
if ($methods) {
$this->loadHandles(mpull($methods, 'getAuthorPHID'));
}
foreach ($methods as $method) {
$id = $method->getID();
$item = new PHUIObjectItemView();
$item->setHeader($method->getFullDisplayName());
switch ($method->getStatus()) {
case PhortunePaymentMethod::STATUS_ACTIVE:
$item->setBarColor('green');
$disable_uri = $this->getApplicationURI('card/' . $id . '/disable/');
$item->addAction(id(new PHUIListItemView())->setIcon('fa-times')->setHref($disable_uri)->setDisabled(!$can_edit)->setWorkflow(true));
break;
case PhortunePaymentMethod::STATUS_DISABLED:
$item->setDisabled(true);
break;
}
$provider = $method->buildPaymentProvider();
$item->addAttribute($provider->getPaymentMethodProviderDescription());
$item->setImageURI($provider->getPaymentMethodIcon());
$edit_uri = $this->getApplicationURI('card/' . $id . '/edit/');
$item->addAction(id(new PHUIListItemView())->setIcon('fa-pencil')->setHref($edit_uri)->setDisabled(!$can_edit)->setWorkflow(!$can_edit));
$list->addItem($item);
}
return id(new PHUIObjectBoxView())->setHeader($header)->appendChild($list);
}
示例11: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$authority = $this->loadMerchantAuthority();
$cart_query = id(new PhortuneCartQuery())->setViewer($viewer)->withIDs(array($id))->needPurchases(true);
if ($authority) {
$cart_query->withMerchantPHIDs(array($authority->getPHID()));
}
$cart = $cart_query->executeOne();
if (!$cart) {
return new Aphront404Response();
}
$charges = id(new PhortuneChargeQuery())->setViewer($viewer)->withCartPHIDs(array($cart->getPHID()))->needCarts(true)->withStatuses(array(PhortuneCharge::STATUS_HOLD, PhortuneCharge::STATUS_CHARGED))->execute();
if ($charges) {
$providers = id(new PhortunePaymentProviderConfigQuery())->setViewer($viewer)->withPHIDs(mpull($charges, 'getProviderPHID'))->execute();
$providers = mpull($providers, null, 'getPHID');
} else {
$providers = array();
}
foreach ($charges as $charge) {
if ($charge->isRefund()) {
// Don't update refunds.
continue;
}
$provider_config = idx($providers, $charge->getProviderPHID());
if (!$provider_config) {
throw new Exception(pht('Unable to load provider for charge!'));
}
$provider = $provider_config->buildProvider();
$provider->updateCharge($charge);
}
return id(new AphrontRedirectResponse())->setURI($cart->getDetailURI($authority));
}
示例12: willFilterPage
protected function willFilterPage(array $accounts)
{
if ($this->needImages) {
$file_phids = mpull($accounts, 'getProfileImagePHID');
$file_phids = array_filter($file_phids);
if ($file_phids) {
// NOTE: We use the omnipotent viewer here because these files are
// usually created during registration and can't be associated with
// the correct policies, since the relevant user account does not exist
// yet. In effect, if you can see an ExternalAccount, you can see its
// profile image.
$files = id(new PhabricatorFileQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs($file_phids)->execute();
$files = mpull($files, null, 'getPHID');
} else {
$files = array();
}
$default_file = null;
foreach ($accounts as $account) {
$image_phid = $account->getProfileImagePHID();
if ($image_phid && isset($files[$image_phid])) {
$account->attachProfileImageFile($files[$image_phid]);
} else {
if ($default_file === null) {
$default_file = PhabricatorFile::loadBuiltin($this->getViewer(), 'profile.png');
}
$account->attachProfileImageFile($default_file);
}
}
}
return $accounts;
}
示例13: processRequest
public function processRequest()
{
$request = $this->getRequest();
$user = $request->getUser();
$views = array(self::VIEW_ALL => 'All Slowvotes', self::VIEW_CREATED => 'Created', self::VIEW_VOTED => 'Voted In');
$view = isset($views[$this->view]) ? $this->view : self::VIEW_ALL;
$side_nav = $this->renderSideNav($views, $view);
$pager = new AphrontPagerView();
$pager->setOffset($request->getInt('page'));
$pager->setURI($request->getRequestURI(), 'page');
$polls = $this->loadPolls($pager, $view);
$phids = mpull($polls, 'getAuthorPHID');
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
$rows = array();
foreach ($polls as $poll) {
$rows[] = array('V' . $poll->getID(), phutil_render_tag('a', array('href' => '/V' . $poll->getID()), phutil_escape_html($poll->getQuestion())), $handles[$poll->getAuthorPHID()]->renderLink(), phabricator_date($poll->getDateCreated(), $user), phabricator_time($poll->getDateCreated(), $user));
}
$table = new AphrontTableView($rows);
$table->setColumnClasses(array('', 'pri wide', '', '', 'right'));
$table->setHeaders(array('ID', 'Poll', 'Author', 'Date', 'Time'));
$panel = new AphrontPanelView();
$panel->setHeader($this->getTableHeader($view));
$panel->setCreateButton('Create Slowvote', '/vote/create/');
$panel->appendChild($table);
$panel->appendChild($pager);
$side_nav->appendChild($panel);
return $this->buildStandardPageResponse($side_nav, array('title' => 'Slowvotes'));
}
示例14: buildPackagePropertyView
private function buildPackagePropertyView(PhabricatorOwnersPackage $package)
{
$viewer = $this->getViewer();
$view = id(new PHUIPropertyListView())->setUser($viewer);
$primary_phid = $package->getPrimaryOwnerPHID();
if ($primary_phid) {
$primary_owner = $viewer->renderHandle($primary_phid);
} else {
$primary_owner = phutil_tag('em', array(), pht('None'));
}
$view->addProperty(pht('Primary Owner'), $primary_owner);
// TODO: needOwners() this on the Query.
$owners = $package->loadOwners();
if ($owners) {
$owner_list = $viewer->renderHandleList(mpull($owners, 'getUserPHID'));
} else {
$owner_list = phutil_tag('em', array(), pht('None'));
}
$view->addProperty(pht('Owners'), $owner_list);
if ($package->getAuditingEnabled()) {
$auditing = pht('Enabled');
} else {
$auditing = pht('Disabled');
}
$view->addProperty(pht('Auditing'), $auditing);
$description = $package->getDescription();
if (strlen($description)) {
$view->addSectionHeader(pht('Description'));
$view->addTextContent($output = PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($description), 'default', $viewer));
}
return $view;
}
示例15: willApplyRules
public function willApplyRules(PhabricatorUser $viewer, array $values, array $objects)
{
$viewer_phid = $viewer->getPHID();
if (!$viewer_phid) {
return;
}
if (empty($this->memberships[$viewer_phid])) {
$this->memberships[$viewer_phid] = array();
}
foreach ($objects as $key => $object) {
$cache = $this->getTransactionHint($object);
if ($cache === null) {
continue;
}
unset($objects[$key]);
if (isset($cache[$viewer_phid])) {
$this->memberships[$viewer_phid][$object->getPHID()] = true;
}
}
if (!$objects) {
return;
}
$object_phids = mpull($objects, 'getPHID');
$edge_query = id(new PhabricatorEdgeQuery())->withSourcePHIDs(array($viewer_phid))->withDestinationPHIDs($object_phids)->withEdgeTypes(array(PhabricatorProjectMemberOfProjectEdgeType::EDGECONST));
$edge_query->execute();
$memberships = $edge_query->getDestinationPHIDs();
if (!$memberships) {
return;
}
$this->memberships[$viewer_phid] += array_fill_keys($memberships, true);
}