当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::pluck方法代码示例

本文整理汇总了PHP中Illuminate\Support\Collection::pluck方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::pluck方法的具体用法?PHP Collection::pluck怎么用?PHP Collection::pluck使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Collection的用法示例。


在下文中一共展示了Collection::pluck方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mergeInfo

 /**
  * Merge client info subentity
  * @param  \Illuminate\Support\Collection $clients
  */
 protected function mergeInfo($clients)
 {
     $infos = $this->manager->clientInfo->where('clientID', 'in', $clients->pluck('id'))->get();
     foreach ($infos as $clientID => $info) {
         $clients[$clientID]->info = $info;
     }
 }
开发者ID:mreschke,项目名称:repository,代码行数:11,代码来源:ClientStore.php

示例2: commonBalanceInPeriod

 /**
  * @param            $object
  * @param Carbon     $start
  * @param Carbon     $end
  * @param Collection $accounts
  *
  * @return string
  */
 protected function commonBalanceInPeriod($object, Carbon $start, Carbon $end, Collection $accounts)
 {
     $ids = $accounts->pluck('id')->toArray();
     $entry = $object->transactionjournals()->transactionTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE])->before($end)->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->whereIn('accounts.id', $ids)->after($start)->first([DB::raw('SUM(`transactions`.`amount`) as `journalAmount`')]);
     $amount = $entry->journalAmount;
     return $amount;
 }
开发者ID:zjean,项目名称:firefly-iii,代码行数:15,代码来源:ComponentRepository.php

示例3: getAccountReport

 /**
  * This method generates a full report for the given period on all
  * given accounts.
  *
  * a special consideration for accounts that did exist on this exact day.
  * we also grab the balance from today just in case, to see if that changes things.
  * it's a fall back for users who (rightly so) start keeping score at the first of
  * the month and find the first report lacking / broken.
  *
  * @param Carbon     $start
  * @param Carbon     $end
  * @param Collection $accounts
  *
  * @return AccountCollection
  */
 public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts) : AccountCollection
 {
     $startAmount = '0';
     $endAmount = '0';
     $diff = '0';
     $ids = $accounts->pluck('id')->toArray();
     $yesterday = clone $start;
     $yesterday->subDay();
     $startSet = $this->getSet($ids, $yesterday);
     // get balances for start.
     $backupSet = $this->getSet($ids, $start);
     $endSet = $this->getSet($ids, $end);
     $accounts->each(function (Account $account) use($startSet, $endSet, $backupSet) {
         return self::reportFilter($account, $startSet, $endSet, $backupSet);
     });
     // summarize:
     foreach ($accounts as $account) {
         $startAmount = bcadd($startAmount, $account->startBalance);
         $endAmount = bcadd($endAmount, $account->endBalance);
         $diff = bcadd($diff, bcsub($account->endBalance, $account->startBalance));
     }
     $object = new AccountCollection();
     $object->setStart($startAmount);
     $object->setEnd($endAmount);
     $object->setDifference($diff);
     $object->setAccounts($accounts);
     return $object;
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:43,代码来源:AccountReportHelper.php

示例4: processFilter

 /**
  * @author WN
  * @param Collection $partialRefunds
  * @return Collection
  */
 private function processFilter(Collection $partialRefunds)
 {
     $statuses = $partialRefunds->pluck('status')->unique()->flip();
     foreach ($statuses as $key => $value) {
         $statuses[$key] = ucfirst($key);
     }
     return $statuses;
 }
开发者ID:paybreak,项目名称:basket,代码行数:13,代码来源:PartialRefundsController.php

示例5: getDefaultsUrl

 public static function getDefaultsUrl()
 {
     $defaults = [];
     foreach (self::$defaults as $default) {
         $defaults[] = self::buildImageUrl($default);
     }
     $defaults = new Collection($defaults);
     return $defaults->pluck('path');
 }
开发者ID:bsampaio,项目名称:Laravel-MemeServer,代码行数:9,代码来源:Image.php

示例6: getBillsForAccounts

 /**
  * @param Collection $accounts
  *
  * @return Collection
  */
 public function getBillsForAccounts(Collection $accounts)
 {
     $ids = $accounts->pluck('id')->toArray();
     $set = Auth::user()->bills()->leftJoin('transaction_journals', function (JoinClause $join) {
         $join->on('transaction_journals.bill_id', '=', 'bills.id')->whereNull('transaction_journals.deleted_at');
     })->leftJoin('transactions', function (JoinClause $join) {
         $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0);
     })->whereIn('transactions.account_id', $ids)->whereNull('transaction_journals.deleted_at')->groupBy('bills.id')->get(['bills.*']);
     $set = $set->sortBy(function (Bill $bill) {
         $int = $bill->active == 1 ? 0 : 1;
         return $int . strtolower($bill->name);
     });
     return $set;
 }
开发者ID:webenhanced,项目名称:firefly-iii,代码行数:19,代码来源:BillRepository.php

示例7: getAccountReport

 /**
  * This method generates a full report for the given period on all
  * given accounts
  *
  * @param Carbon     $start
  * @param Carbon     $end
  * @param Collection $accounts
  *
  * @return AccountCollection
  */
 public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts)
 {
     $startAmount = '0';
     $endAmount = '0';
     $diff = '0';
     $ids = $accounts->pluck('id')->toArray();
     $yesterday = clone $start;
     $yesterday->subDay();
     bcscale(2);
     // get balances for start.
     $startSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->whereIn('accounts.id', $ids)->whereNull('transaction_journals.deleted_at')->whereNull('transactions.deleted_at')->where('transaction_journals.date', '<=', $yesterday->format('Y-m-d'))->groupBy('accounts.id')->get(['accounts.id', DB::Raw('SUM(`transactions`.`amount`) as `balance`')]);
     // and end:
     $endSet = Account::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->whereIn('accounts.id', $ids)->whereNull('transaction_journals.deleted_at')->whereNull('transactions.deleted_at')->where('transaction_journals.date', '<=', $end->format('Y-m-d'))->groupBy('accounts.id')->get(['accounts.id', DB::Raw('SUM(`transactions`.`amount`) as `balance`')]);
     $accounts->each(function (Account $account) use($startSet, $endSet) {
         /**
          * The balance for today always incorporates transactions
          * made on today. So to get todays "start" balance, we sub one
          * day.
          */
         //
         $currentStart = $startSet->filter(function (Account $entry) use($account) {
             return $account->id == $entry->id;
         });
         if ($currentStart->first()) {
             $account->startBalance = $currentStart->first()->balance;
         }
         $currentEnd = $endSet->filter(function (Account $entry) use($account) {
             return $account->id == $entry->id;
         });
         if ($currentEnd->first()) {
             $account->endBalance = $currentEnd->first()->balance;
         }
     });
     // summarize:
     foreach ($accounts as $account) {
         $startAmount = bcadd($startAmount, $account->startBalance);
         $endAmount = bcadd($endAmount, $account->endBalance);
         $diff = bcadd($diff, bcsub($account->endBalance, $account->startBalance));
     }
     $object = new AccountCollection();
     $object->setStart($startAmount);
     $object->setEnd($endAmount);
     $object->setDifference($diff);
     $object->setAccounts($accounts);
     return $object;
 }
开发者ID:zjean,项目名称:firefly-iii,代码行数:56,代码来源:AccountReportHelper.php

示例8: average

 public static function average(\Illuminate\Support\Collection $posts)
 {
     $count = $posts->count();
     $comments = $posts->pluck('comments')->avg();
     $pictures = $posts->pluck('pictures')->avg();
     $wordCount = $posts->pluck('wordCount')->avg();
     $totalWords = $posts->pluck('wordCount')->sum();
     $emotionalScore = $posts->pluck('emotionalScore')->avg();
     $emotionalScoreX = $posts->pluck('emotionalScoreX')->avg();
     $emotionalScoreY = $posts->pluck('emotionalScoreY')->avg();
     $ego = $posts->pluck('ego')->map(function ($item, $key) {
         return count($item);
     })->avg();
     $comments = round($comments, 2);
     $pictures = round($pictures, 2);
     $wordCount = round($wordCount, 2);
     $ego = round($ego, 2);
     $wordCounts = $posts->pluck('lemmas');
     $words = [];
     foreach ($wordCounts as $k => $subArray) {
         foreach ($subArray as $key => $value) {
             if (!isset($words[$key])) {
                 $words[$key] = 0;
             }
             $words[$key] += $value;
         }
     }
     arsort($words);
     $words = array_slice($words, 0, 5000);
     $words = array_filter($words, function ($value) {
         return $value > 2;
     });
     // collect($words)->filter(function ($key, $value) {
     // 	return $value > 2;
     // })->toArray();
     return compact('count', 'comments', 'pictures', 'wordCount', 'ego', 'words', 'totalWords', 'emotionalScore', 'emotionalScoreX', 'emotionalScoreY');
 }
开发者ID:ArturKp,项目名称:bloglyzer,代码行数:37,代码来源:StatisticsService.php

示例9: budgetYearOverview

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength) // at 43, its ok.
  * @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5.
  *
  * @param Carbon     $start
  * @param Carbon     $end
  * @param Collection $accounts
  *
  * @return Collection
  */
 public function budgetYearOverview(Carbon $start, Carbon $end, Collection $accounts) : Collection
 {
     // chart properties for cache:
     $cache = new CacheProperties();
     $cache->addProperty($start);
     $cache->addProperty($end);
     $cache->addProperty('budget-year');
     $cache->addProperty($accounts->pluck('id')->toArray());
     if ($cache->has()) {
         return $cache->get();
     }
     $current = clone $start;
     $return = new Collection();
     $set = $this->repository->getBudgets();
     $budgets = [];
     $spent = [];
     $headers = $this->createYearHeaders($current, $end);
     /** @var Budget $budget */
     foreach ($set as $budget) {
         $id = $budget->id;
         $budgets[$id] = $budget->name;
         $current = clone $start;
         $budgetData = $this->getBudgetSpentData($current, $end, $budget, $accounts);
         $sum = $budgetData['sum'];
         $spent[$id] = $budgetData['spent'];
         if (bccomp('0', $sum) === 0) {
             // not spent anything.
             unset($spent[$id]);
             unset($budgets[$id]);
         }
     }
     $return->put('headers', $headers);
     $return->put('budgets', $budgets);
     $return->put('spent', $spent);
     $cache->store($return);
     return $return;
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:47,代码来源:BudgetReportHelper.php

示例10: mergeGroups

 /**
  * Merge groups subentity with client
  * @param  \Illuminate\Support\Collection $clients
  */
 protected function mergeGroups($clients)
 {
     $groups = $this->manager->group->byClients($clients->pluck('id'));
     foreach ($groups as $clientID => $group) {
         $clients[$clientID]->groups = collect($group);
     }
 }
开发者ID:mreschke,项目名称:repository,代码行数:11,代码来源:ClientStore.php

示例11: tagReport

 /**
  * Returns an array of tags and their comparitive size with amounts bla bla.
  *
  * @param Carbon     $start
  * @param Carbon     $end
  * @param Collection $accounts
  *
  * @return array
  */
 public function tagReport(Carbon $start, Carbon $end, Collection $accounts) : array
 {
     $ids = $accounts->pluck('id')->toArray();
     $set = Tag::leftJoin('tag_transaction_journal', 'tags.id', '=', 'tag_transaction_journal.tag_id')->leftJoin('transaction_journals', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')->leftJoin('transactions AS source', function (JoinClause $join) {
         $join->on('source.transaction_journal_id', '=', 'transaction_journals.id')->where('source.amount', '<', '0');
     })->leftJoin('transactions AS destination', function (JoinClause $join) {
         $join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('destination.amount', '>', '0');
     })->where('transaction_journals.date', '>=', $start->format('Y-m-d'))->where('transaction_journals.date', '<=', $end->format('Y-m-d'))->where(function (Builder $q) use($ids) {
         $q->whereIn('source.account_id', $ids)->whereIn('destination.account_id', $ids, 'xor');
     })->get(['tags.id', 'tags.tag', 'transaction_journals.id as journal_id', 'destination.amount']);
     $collection = [];
     if ($set->count() === 0) {
         return $collection;
     }
     /** @var Tag $entry */
     foreach ($set as $entry) {
         // less than zero? multiply to be above zero.
         $amount = $entry->amount;
         $id = intval($entry->id);
         $previousAmount = $collection[$id]['amount'] ?? '0';
         $collection[$id] = ['id' => $id, 'tag' => $entry->tag, 'amount' => bcadd($previousAmount, $amount)];
     }
     // cleanup collection (match "fonts")
     $max = strval(max(array_column($collection, 'amount')));
     foreach ($collection as $id => $entry) {
         $size = bcdiv($entry['amount'], $max, 4);
         if (bccomp($size, '0.25') === -1) {
             $size = '0.5';
         }
         $collection[$id]['fontsize'] = $size;
     }
     return $collection;
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:42,代码来源:ReportHelper.php

示例12: expense

 /**
  * This method returns all the "out" transaction journals for the given account and given period. The amount
  * is stored in "journalAmount".
  *
  * @param Collection $accounts
  * @param Carbon     $start
  * @param Carbon     $end
  *
  * @return Collection
  */
 public function expense(Collection $accounts, Carbon $start, Carbon $end)
 {
     $ids = $accounts->pluck('id')->toArray();
     $set = Auth::user()->transactionjournals()->leftJoin('transactions as t_from', function (JoinClause $join) {
         $join->on('t_from.transaction_journal_id', '=', 'transaction_journals.id')->where('t_from.amount', '<', 0);
     })->leftJoin('transactions as t_to', function (JoinClause $join) {
         $join->on('t_to.transaction_journal_id', '=', 'transaction_journals.id')->where('t_to.amount', '>', 0);
     })->leftJoin('accounts', 't_to.account_id', '=', 'accounts.id')->transactionTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER, TransactionType::OPENING_BALANCE])->before($end)->after($start)->whereIn('t_from.account_id', $ids)->whereNotIn('t_to.account_id', $ids)->get(['transaction_journals.*', 't_from.amount as journalAmount', 'accounts.id as account_id', 'accounts.name as account_name']);
     return $set;
 }
开发者ID:webenhanced,项目名称:firefly-iii,代码行数:20,代码来源:ReportQuery.php

示例13: spentPerBudgetPerAccount

 /**
  * Returns a list of expenses (in the field "spent", grouped per budget per account.
  *
  * @param Collection $budgets
  * @param Collection $accounts
  * @param Carbon     $start
  * @param Carbon     $end
  *
  * @return Collection
  */
 public function spentPerBudgetPerAccount(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end)
 {
     $accountIds = $accounts->pluck('id')->toArray();
     $budgetIds = $budgets->pluck('id')->toArray();
     $set = Auth::user()->transactionjournals()->leftJoin('transactions AS t_from', function (JoinClause $join) {
         $join->on('transaction_journals.id', '=', 't_from.transaction_journal_id')->where('t_from.amount', '<', 0);
     })->leftJoin('transactions AS t_to', function (JoinClause $join) {
         $join->on('transaction_journals.id', '=', 't_to.transaction_journal_id')->where('t_to.amount', '>', 0);
     })->leftJoin('budget_transaction_journal', 'transaction_journals.id', '=', 'budget_transaction_journal.transaction_journal_id')->whereIn('t_from.account_id', $accountIds)->whereNotIn('t_to.account_id', $accountIds)->where(function (Builder $q) use($budgetIds) {
         $q->whereIn('budget_transaction_journal.budget_id', $budgetIds);
         $q->orWhereNull('budget_transaction_journal.budget_id');
     })->after($start)->before($end)->groupBy('t_from.account_id')->groupBy('budget_transaction_journal.budget_id')->transactionTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER, TransactionType::OPENING_BALANCE])->get(['t_from.account_id', 'budget_transaction_journal.budget_id', DB::Raw('SUM(`t_from`.`amount`) AS `spent`')]);
     return $set;
 }
开发者ID:zjean,项目名称:firefly-iii,代码行数:24,代码来源:BudgetRepository.php

示例14: spentInPeriodWithoutBudget

 /**
  * @param Collection $accounts
  * @param Carbon     $start
  * @param Carbon     $end
  *
  * @return string
  */
 public function spentInPeriodWithoutBudget(Collection $accounts, Carbon $start, Carbon $end) : string
 {
     $types = [TransactionType::WITHDRAWAL];
     $query = $this->user->transactionJournals()->distinct()->transactionTypes($types)->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')->leftJoin('transactions as source', function (JoinClause $join) {
         $join->on('source.transaction_journal_id', '=', 'transaction_journals.id')->where('source.amount', '<', 0);
     })->leftJoin('transactions as destination', function (JoinClause $join) {
         $join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('destination.amount', '>', 0);
     })->leftJoin('budget_transaction', 'source.id', '=', 'budget_transaction.transaction_id')->whereNull('budget_transaction_journal.id')->whereNull('budget_transaction.id')->before($end)->after($start)->whereNull('source.deleted_at')->whereNull('destination.deleted_at')->where('transaction_journals.completed', 1);
     if ($accounts->count() > 0) {
         $accountIds = $accounts->pluck('id')->toArray();
         $set = join(', ', $accountIds);
         $query->whereRaw('(source.account_id in (' . $set . ') XOR destination.account_id in (' . $set . '))');
     }
     $ids = $query->get(['transaction_journals.id'])->pluck('id')->toArray();
     $sum = '0';
     if (count($ids) > 0) {
         $sum = strval($this->user->transactions()->whereIn('transaction_journal_id', $ids)->where('amount', '<', '0')->whereNull('transactions.deleted_at')->sum('amount'));
     }
     return $sum;
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:27,代码来源:BudgetRepository.php

示例15: getJournalsInRange

 /**
  * Returns a collection of ALL journals, given a specific account and a date range.
  *
  * @param Collection $accounts
  * @param Carbon     $start
  * @param Carbon     $end
  *
  * @return Collection
  */
 public function getJournalsInRange(Collection $accounts, Carbon $start, Carbon $end) : Collection
 {
     $query = $this->user->transactionJournals()->expanded()->sortCorrectly();
     $query->where('transaction_journals.completed', 1);
     $query->before($end);
     $query->after($start);
     if ($accounts->count() > 0) {
         $ids = $accounts->pluck('id')->toArray();
         // join source and destination:
         $query->leftJoin('transactions as source', function (JoinClause $join) {
             $join->on('source.transaction_journal_id', '=', 'transaction_journals.id')->where('source.amount', '<', 0);
         });
         $query->leftJoin('transactions as destination', function (JoinClause $join) {
             $join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('destination.amount', '>', 0);
         });
         $query->where(function (Builder $q) use($ids) {
             $q->whereIn('destination.account_id', $ids);
             $q->orWhereIn('source.account_id', $ids);
         });
     }
     $set = $query->get(TransactionJournal::queryFields());
     return $set;
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:32,代码来源:JournalRepository.php


注:本文中的Illuminate\Support\Collection::pluck方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。