本文整理汇总了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;
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
}
示例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']);
}
示例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);
}
}
示例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');
}
示例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;
}
示例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);
}
示例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;
}
示例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'));
}
示例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'));
}
示例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();
}
}
示例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()]);
}