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


PHP Collection::count方法代码示例

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


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

示例1: isEnabledKey

 /**
  * Return true if all API Key are still enable
  *
  * @param Collection $keys
  * @return bool
  */
 protected function isEnabledKey(Collection $keys)
 {
     // count keys with enable value and compare it to total keys number
     $enabledKeys = $keys->filter(function ($item) {
         return $item->enabled == 1;
     })->count();
     if ($enabledKeys == $keys->count() && $keys->count() != 0) {
         return true;
     }
     return false;
 }
开发者ID:warlof,项目名称:slackbot,代码行数:17,代码来源:AbstractSlack.php

示例2: totalItems

 /**
  * Return the total number of rows in the table.
  * @return int
  */
 public function totalItems()
 {
     if ($this->paginator) {
         return $this->paginator->total();
     }
     return $this->items->count();
 }
开发者ID:breachofmind,项目名称:birdmin,代码行数:11,代码来源:Table.php

示例3: render

 /**
  * Render the likes into a string.
  *
  * @param Collection $likesCollection  The likes to render.
  *
  * @param string     $viewAllLikesLink The link to view all of the likes for the content.
  *
  * @return string
  */
 public function render(Collection $likesCollection, $viewAllLikesLink)
 {
     $numLikesToList = $this->settings->get('posts.likes_to_show', 3);
     $numOtherLikes = $likesCollection->count() - $numLikesToList;
     $userId = $this->guard->user()->getAuthIdentifier();
     $likes = [];
     $likesCollection = $likesCollection->filter(function (Like $like) use(&$likes, &$numLikesToList, $userId) {
         if ($like->user->id === $userId) {
             $like->user->name = $this->lang->get('likes.current_user');
             $likes[] = $like;
             $numLikesToList--;
             return false;
         }
         return true;
     });
     $numLikesInCollection = $likesCollection->count();
     if ($numLikesInCollection > 0 && $numLikesToList > 0) {
         if ($numLikesInCollection < $numLikesToList) {
             $numLikesToList = $numLikesInCollection;
         }
         $randomLikes = $likesCollection->random($numLikesToList);
         if (!is_array($randomLikes)) {
             // random returns a single model if $numLikesToList is 1...
             $randomLikes = array($randomLikes);
         }
         foreach ($randomLikes as $key => $like) {
             $likes[] = $like;
         }
     }
     return $this->viewFactory->make('likes.list', compact('numOtherLikes', 'likes', 'viewAllLikesLink'))->render();
 }
开发者ID:Adamzynoni,项目名称:mybb2,代码行数:40,代码来源:RenderLikes.php

示例4: getMeta

 /**
  * Gets meta data
  *
  * @param string $key
  * @param null|mixed $default
  * @param bool $raw
  * @return Collection
  */
 public function getMeta($key, $default = null, $raw = false)
 {
     $meta = $this->meta()->where('key', $key)->get();
     if ($raw) {
         $collection = $meta;
     } else {
         $collection = new Collection();
         foreach ($meta as $m) {
             $collection->put($m->id, $m->value);
         }
     }
     if (0 == $collection->count()) {
         return $default;
     }
     return $collection->count() <= 1 ? $collection->first() : $collection;
 }
开发者ID:AlexanderPoellmann,项目名称:laravel-meta,代码行数:24,代码来源:HasMeta.php

示例5: performFail

 /**
  * performFail.
  *
  * @author Casper Rasmussen <cr@nodes.dk>
  * @return void
  */
 private function performFail()
 {
     $this->failedCarbons->prepend(new Carbon());
     if ($this->failedCarbons->count() > 3) {
         $this->failedCarbons->pop();
     }
 }
开发者ID:nodes-php,项目名称:translate,代码行数:13,代码来源:NStack.php

示例6: getResponses

 /**
  * Get array of nested responses in "execute" response
  *
  * @param array $executeResponse
  * @return array
  */
 protected function getResponses(array $executeResponse)
 {
     if (isset($executeResponse['error'])) {
         return array_fill(0, $this->requests->count(), $executeResponse['error']);
     }
     $errors = isset($executeResponse['execute_errors']) ? $executeResponse['execute_errors'] : [];
     return array_map(function ($response) use(&$errors) {
         return $response ?: array_shift($errors);
     }, $executeResponse['response']);
 }
开发者ID:atehnix,项目名称:laravel-vk-requester,代码行数:16,代码来源:SendBatch.php

示例7: send

 /**
  * Sends a push message
  *
  * @param string $title
  * @param string $message
  * @param Collection $users
  */
 public function send($title, $message, $users)
 {
     if ($users->count() == 0) {
         PastPush::create(['title' => $title, 'message' => $message]);
     }
     foreach ($users->chunk($this->batchSize) as $userBatch) {
         $registrationIds = $this->getRegistrationIds($userBatch);
         $response = $this->sendNotifications($title, $message, $registrationIds);
         $this->logPushNotification($title, $message, $response, $userBatch);
     }
 }
开发者ID:vanlonden,项目名称:pusher,代码行数:18,代码来源:Pusher.php

示例8: getPagination

 /**
  * Calculate the pagination data
  *
  * @param  \Illuminate\Database\Eloquent\Collection $records
  * @param  integer                                  $total
  * @param  integer                                  $page
  * @param  integer                                  %from
  * @return array
  */
 public function getPagination($records, $total, $page, $from)
 {
     $to = $from + $records->count();
     $last = ceil($total / $this->perPage);
     $prev = $page - 1;
     $next = $page + 1;
     if ($prev < 1) {
         $prev = 1;
     }
     if ($next > $last) {
         $next = $last;
     }
     return compact('from', 'to', 'total', 'next', 'prev');
 }
开发者ID:scottbedard,项目名称:oc-shop-plugin,代码行数:23,代码来源:RelationPicker.php

示例9: scopeTaggedWith

 /**
  * @param Builder $builder
  * @param Collection $tags
  * @return Builder
  */
 public function scopeTaggedWith(Builder $builder, Collection $tags)
 {
     /** @var MorphToMany $relation */
     $relation = $this->tags();
     $key = $this->getTable() . '.' . $this->getKeyName();
     if ($tags->count()) {
         $builder->join($relation->getTable(), function ($join) use($relation, $key, $tags) {
             $join->on($relation->getForeignKey(), '=', $key);
             $join->where($relation->getMorphType(), '=', $relation->getMorphClass());
             $join->whereIn($relation->getOtherKey(), $tags->keys()->toArray());
         });
     } else {
         $builder->whereNull($this->getTable());
     }
     return $builder;
 }
开发者ID:jaffle-be,项目名称:framework,代码行数:21,代码来源:Taggable.php

示例10: postUpdate

 public function postUpdate($tournament)
 {
     if ($tournament->user != Auth::user()->id) {
         return Redirect::to('tournaments');
     }
     $tournament->name = Input::get('name');
     $maps = array_keys(Input::get('maps', []));
     $players = array_keys(Input::get('players.ids', []));
     $names = array_keys(Input::get('players.names', []));
     if (is_null($tournament->name)) {
         return Redirect::back();
     }
     $total = count($names) + count($players);
     if (ceil($total / 2) != count($maps)) {
         return Redirect::back();
     }
     $tournament->save();
     $tournament->maps()->detach();
     foreach ($maps as $map) {
         $tournament->maps()->attach($map);
     }
     $tournament->players()->detach();
     foreach ($players as $player) {
         $tournament->players()->attach($player);
     }
     $scenarii = new Collection();
     $tournament->maps->each(function ($map) use(&$scenarii, $tournament) {
         if ($scenarii->count() < 2) {
             $scenarii = Scenario::where('season', Carbon::now()->year)->get()->shuffle();
         }
         $map->scenarii($tournament)->attach($scenarii->pop()->id, ['tournament' => $tournament->id]);
         $map->scenarii($tournament)->attach($scenarii->pop()->id, ['tournament' => $tournament->id]);
     });
     foreach ($names as $name) {
         $player = new Player();
         $player->name = $name;
         $player->user = Auth::user()->id;
         $player->save();
         $tournament->players()->attach($player->id);
     }
     if ($total % 2 != 0) {
         $tournament->players()->attach(User::fantom()->id);
     }
     return Redirect::to('tournaments/' . $tournament->id);
 }
开发者ID:romainmasc,项目名称:jackmarshall,代码行数:45,代码来源:TournamentsController.php

示例11: searchResultFormat

 public function searchResultFormat(Collection $result)
 {
     $cp = new CoursePresenter();
     $html = "";
     if ($result->count() == 0) {
         $html .= "<tr>" . "  <td>1</td>" . "  <td>沒有課程</td>" . "  <td>阿飄教授</td>" . "  <td>幽靈學院</td>" . "  <td>沒有學分</td>" . "  <td>沒有評鑑</td>" . "  <td>1200</td>" . "  <td>X</td>" . "</tr>";
     } else {
         foreach ($result as $key => $course) {
             $counter = $key + 1;
             $html .= "<tr>" . "  <td> {$counter} </td>" . "  <td><a href='/course/" . $course->id . "'>" . $course->course_nameCH . "</a></td>" . "  <td>" . $course->professor . "</td>" . "  <td>";
             $html .= $cp->getDepartmantNameByCode($course->course_department);
             $html .= "  </td>" . "  <td>";
             $html .= $cp->getGradeNameByNum($course->course_grade);
             $html .= "  </td>" . "  <td>" . $course->judge_people . "</td>" . "  <td>" . $course->current_rank . "</td>" . "  <td>" . $course->time1 . "</td>" . "  <td>" . $course->time2 . "</td>" . "  <td>" . $course->place . "</td>" . "  <td id='pinArea" . $course->id . "'><a href='#searching' class='glyphicon glyphicon-pushpin' onclick='pinAjax(" . $course->id . ", 1)'></a></td>";
             $html .= "</tr>";
         }
         return $html;
     }
     return $html;
 }
开发者ID:e19940604,项目名称:Cyinf,代码行数:20,代码来源:SearchResultFormatPresenter.php

示例12: index

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request, $id = null)
 {
     $projects = $this->employee->listProjectUserBelong();
     if ($id == null) {
         $id = Project::pluck('id');
     }
     $detailfeatures = array();
     $features = Project::find($id)->features()->get();
     $detailfeatures = new Collection();
     foreach ($features as $key_fea => $value_fea) {
         $detaiFeas = $value_fea->detailfeatures()->get();
         foreach ($detaiFeas as $key => $value) {
             $detailfeatures->add($value);
         }
     }
     $page = Input::get('page') == NULL ? 1 : Input::get('page');
     $path = $request->url;
     $count = $detailfeatures->count();
     $pagiDetailfeatures = new \Illuminate\Pagination\LengthAwarePaginator($detailfeatures, $count, 5, $page);
     $pagiDetailfeatures->setPath($path);
     $detailfeatures = $detailfeatures->slice($pagiDetailfeatures->firstItem() - 1, 5);
     return view('manageproject.manageproject', compact('projects', 'detailfeatures', 'pagiDetailfeatures'));
 }
开发者ID:phanngoc,项目名称:internal-tool,代码行数:28,代码来源:ManageProjectController.php

示例13: renderSection

 /**
  * @param Page       $page
  * @param Section    $section
  * @param Collection $content
  * @return mixed
  */
 public function renderSection(Page $page, Section $section, Collection $content)
 {
     $isContentMode = Session::get('mode') == 'content';
     $isModePublic = $section->isPublic();
     // Dispatch all the blocks in this section
     $blocks = array();
     foreach ($content as $item) {
         if ($item->section_id == $section->id) {
             $blocks[] = $this->renderContent($item);
         }
     }
     if (!$content->count() || implode('', $blocks) === '') {
         return;
     }
     if ($isContentMode) {
         // Build the form for adding a content block in this section
         $fb = App::make('Boyhagemann\\Content\\Controller\\ContentController')->init('create')->getFormBuilder();
         $fb->url(URL::route('admin.content.store'));
         $fb->defaults(array('section_id' => $section->id, 'page_id' => $section->page_id));
         $form = $fb->build();
     }
     Event::fire('content.dispatch.renderSection', array(&$blocks, $section, $page, $isContentMode, $isModePublic));
     return View::make('content::section', compact('blocks', 'section', 'form', 'isContentMode', 'isModePublic'));
 }
开发者ID:boyhagemann,项目名称:content,代码行数:30,代码来源:DispatchController.php

示例14: processEmail

 public function processEmail($message)
 {
     if (Email::where('gmail_uid', $message->id)->count() == 0) {
         $mail = new Email();
         $service = Mailbox::getGmailService();
         $user = 'me';
         try {
             $message_data = $service->users_messages->get($user, $message->id);
         } catch (Exception $e) {
             print 'An error occurred: ' . $e->getMessage();
         }
         foreach ($message_data->getPayload()->headers as $header) {
             if ($header['name'] == 'Subject') {
                 $mail->subject = $header['value'];
             }
             if ($header['name'] == 'Cc') {
                 $mail->cc = $header['value'];
             }
             if ($header['name'] == 'From') {
                 $from_pos = strpos($header['value'], "<");
                 $from_name = substr($header['value'], 0, $from_pos);
                 $from_address = substr($header['value'], $from_pos + 1, -1);
                 $mail->sender_name = $from_name;
                 $mail->sender_address = $from_address;
             }
             if ($header['name'] == 'Date') {
                 $mail->received_at = Carbon::createFromFormat('D, d M Y H:i:s T', $header['value']);
             }
         }
         $mail->mailbox_id = $this->id;
         $attachments = new Collection();
         if ($message_data->getPayload()->body['size'] == 0) {
             foreach ($message_data->getPayload()->parts as $part) {
                 if (count($part->parts) > 0) {
                     foreach ($part->parts as $subpart) {
                         if ($subpart->mimeType == 'text/html') {
                             $mail->mimetype = 'text/html';
                             $mail->content = base64_decode(strtr($subpart->getBody()->data, '-_,', '+/='));
                         }
                     }
                 }
                 if ($part->mimeType == 'text/html') {
                     $mail->mimetype = 'text/html';
                     $mail->content = base64_decode(strtr($part->getBody()->data, '-_,', '+/='));
                 }
                 if ($part['filename'] != '') {
                     $attachment_data = $service->users_messages_attachments->get("me", $message->id, $part->getBody()->attachmentId);
                     $file_raw_data = base64_decode(strtr($attachment_data->data, array('-' => '+', '_' => '/')));
                     $stored_filename = $message->id . '-' . time() . '-' . $part['filename'];
                     $fh = fopen(public_path() . "/email_attachments/" . $stored_filename, "w+");
                     fwrite($fh, $file_raw_data);
                     fclose($fh);
                     $attachment = new EmailAttachment();
                     $attachment->file_path = "email_attachments/" . $stored_filename;
                     $attachment->file_name = $part['filename'];
                     $attachment->save();
                     $attachments->push($attachment);
                 }
             }
             if (!$mail->content) {
                 foreach ($message_data->getPayload()->parts as $part) {
                     if ($part->mimeType == 'text/plain') {
                         $mail->mimetype = 'text/plain';
                         $mail->content = base64_decode(strtr($part->getBody()->data, '-_,', '+/='));
                     }
                 }
             }
         } else {
             $mail->mimetype = 'text/plain';
             $mail->content = base64_decode(strtr($message_data->getPayload()->body['data'], '-_,', '+/='));
         }
         $mail->gmail_uid = $message->id;
         $mail->save();
         if ($attachments->count() > 0) {
             foreach ($attachments as $a) {
                 $a->email_id = $mail->id;
                 $a->save();
             }
         }
         $mail->matchToPatient();
         $mail->addProcessedLabel();
     }
 }
开发者ID:VoodooPrawn,项目名称:finest,代码行数:83,代码来源:Mailbox.php

示例15: choose_from_collection

 public static function choose_from_collection(\Illuminate\Database\Eloquent\Collection $collection)
 {
     assert($collection->count(), 'Collection empty!');
     return $collection->get($collection->keys()[mt_rand() % $collection->count()]);
 }
开发者ID:klsandbox,项目名称:randomhelper,代码行数:5,代码来源:RandomHelper.php


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