/** * QueryFilter constructor. * * @param InputParser $parser * @param Collection $collection * @param Container $app */ public function __construct(InputParser $parser, Collection $collection, Container $app) { $this->parser = $parser; $this->collection = $collection; $this->filters = $parser->getFilters(); $this->sorts = $parser->getSorts(); $this->appliedFilters = $collection->make(); $this->appliedSorts = $collection->make(); $this->app = $app; }
/** * @param $vulnerabilities * @param $version * @param null $found_vulnerabilities * * @return bool */ public function isVulnerable($vulnerabilities, $version, &$found_vulnerabilities = null) { $found_vulnerabilities = Collection::make($vulnerabilities)->filter(function ($v) use($version) { return $this->semver->lessThan($version, $v->fixed_in); }); return $found_vulnerabilities->count() > 0; }
/** * Array of language files grouped by file name. * * ex: ['user' => ['en' => 'user.php', 'nl' => 'user.php']] * * @return array */ public function files() { $files = Collection::make($this->disk->allFiles($this->path)); $filesByFile = $files->groupBy(function ($file) { $fileName = $file->getBasename('.' . $file->getExtension()); if (Str::contains($file->getPath(), 'vendor')) { $fileName = str_replace('.php', '', $file->getFileName()); $packageName = basename(dirname($file->getPath())); return "{$packageName}::{$fileName}"; } else { return $fileName; } })->map(function ($files) { return $files->keyBy(function ($file) { return basename($file->getPath()); })->map(function ($file) { return $file->getRealPath(); }); }); // If the path does not contain "vendor" then we're looking at the // main language files of the application, in this case we will // neglect all vendor files. if (!Str::contains($this->path, 'vendor')) { $filesByFile = $this->neglectVendorFiles($filesByFile); } return $filesByFile; }
/** * Get the results as a collection of model instances. * * @return Collection */ protected function collectModels() { $modelClass = get_class($this->model); return Collection::make($this->query())->map(function ($result) use($modelClass) { return new $modelClass($result); }); }
protected static function checkType($types) { $types = Collection::make($types); if (!$types->contains(static::TYPE)) { throw new DomainException('Invalid contact type: ' . $types->implode(',')); } }
/** * Create order record. * * @return \Illuminate\Http\JsonResponse */ public function store() { try { \DB::beginTransaction(); $items = Collection::make(\Input::get('items')); $order = new Order(); // create the order $order->save(); // Attach items to order $items->each(function ($item) use($order) { $order->addItem($item); }); // Calculate commission & profit /** @var \Paxifi\Support\Commission\CalculatorInterface $calculator */ $calculator = \App::make('Paxifi\\Support\\Commission\\CalculatorInterface'); $calculator->setCommissionRate($order->OrderDriver()->getCommissionRate()); $order->setCommission($calculator->calculateCommission($order)); $order->setProfit($calculator->calculateProfit($order)); // save order $order->save(); \DB::commit(); return $this->setStatusCode(201)->respondWithItem(Order::find($order->id)); } catch (ModelNotFoundException $e) { return $this->errorWrongArgs('Invalid product id'); } catch (\InvalidArgumentException $e) { return $this->errorWrongArgs($e->getMessage()); } catch (\Exception $e) { return $this->errorInternalError(); } }
public function getModels(array $models = []) { foreach ($models as &$model) { $model = $this->model->newFromQuery($model); } return Collection::make($models); }
function length_aware_paginator($items, $perPage, $currentPage = null, array $options = []) { $currentPage = $currentPage ?: LengthAwarePaginator::resolveCurrentPage(); $startIndex = $currentPage * $perPage - $perPage; $paginatedItems = Collection::make($items)->slice($startIndex, $perPage); return new LengthAwarePaginator($paginatedItems, $items->count(), $perPage, $currentPage, ['path' => LengthAwarePaginator::resolveCurrentPath()]); }
/** * @param Collection $collection * @return \Illuminate\Support\Collection */ public function collection(Collection $collection) { $activities = $collection->map(function ($item) { return self::single(Collection::make($item)); }); return $activities; }
/** * @param array|Collection $data */ public function __construct($data = []) { $this->data = $data; if (!$this->data instanceof Collection) { $this->data = Collection::make($this->data); } }
public function testModels() { $this->search->shouldReceive('config->models')->with([1, 2, 3, 4, 5], ['limit' => 2, 'offset' => 3])->andReturn([[1, 2, 3, 4, 5], 5]); $this->assertEquals(Collection::make([1, 2, 3, 4, 5]), $this->runner->models('test', ['limit' => 2, 'offset' => 3])); $this->assertEquals(5, $this->runner->getCachedCount('test')); $this->assertEquals(0, $this->runner->getCachedCount('other test')); }
/** * Devuelve una lista de los distintas salas de la colección de * exhibiciones dada. * * * @param $exhibitions Lista de exhibiciones. * @return Collection Lista de todas las distintas salas de las exhibiciones dadas. */ public function getAuditoriums($exhibitions) { $auditoriums = $exhibitions->reduce(function ($accum, $exhibition) { return $accum->merge($exhibition->auditoriums); }, Collection::make([])); return $auditoriums; }
public function setUp() { $claims = ['sub' => new Subject(1), 'iss' => new Issuer('http://example.com'), 'exp' => new Expiration(time() + 3600), 'nbf' => new NotBefore(time()), 'iat' => new IssuedAt(time()), 'jti' => new JwtId('foo')]; $this->validator = Mockery::mock('Tymon\\JWTAuth\\Validators\\PayloadValidator'); $this->validator->shouldReceive('setRefreshFlow->check'); $this->payload = new Payload(Collection::make($claims), $this->validator); }
/** * @return static */ public function getTemplateList() { $templates = Collection::make(); $templates->put('default::page.default', '默认模板'); static::$dispatcher->fire(new GetTemplateList($templates)); return $templates; }
public function show_docket($id) { $delivery_history = DeliveryHistory::find($id); $input = unserialize($delivery_history->input); $quote = QuoteRequest::find($delivery_history->qr_id); $delivery_address = CustomerAddress::find($input['delivery_address']); // Create PDF $qtys = isset($input['number']) ? $input['number'] : ''; if (isset($input['number'])) { // Quantities are not equal $collection = Collection::make($input['number']); $numbers = $collection->flip()->map(function () { return 0; }); foreach ($collection as $item) { $numbers[$item] += 1; } $html = view('jobs.docket', compact('input', 'quote', 'delivery_address', 'qtys', 'numbers')); } else { // Quantities are equal $html = view('jobs.docket', compact('input', 'quote', 'delivery_address', 'qtys')); } $dompdf = PDF::loadHTML($html); return $dompdf->stream(); }
/** * @param \Illuminate\Support\Collection|IComponent[]|array $components * @return $this */ public function setComponents($components) { $this->components = Collection::make($components); foreach ($components as $component) { $component->attachTo($this); } return $this; }
/** * Run query and get all finding models. * * @param $query * @param $options * @return array */ public function models($query, array $options = []) { $hits = $this->run($query); list($models, $totalCount) = $this->search->config()->models($hits, $options); // Remember total number of results. $this->setCachedCount($query, $totalCount); return Collection::make($models); }
/** * Find and initialise the extensions. * * @param array $paths * @return array */ public function findAndInitialiseExtensions(array $paths) { // Find the extensions. $extensions = $this->finder->findExtensions($paths); // Create the collection of extensions. $this->collection = Collection::make($extensions); return $extensions; }
public function addColumn($column) { if (NULL === $this->columns) { $this->columns = Collection::make([]); } $this->columns->push($column); return $this; }
/** * @test */ public function it_can_set_a_new_order() { $newOrder = Collection::make(Dummy::all()->lists('id'))->shuffle()->toArray(); Dummy::setNewOrder($newOrder); foreach (Dummy::orderBy('order_column')->get() as $i => $dummy) { $this->assertEquals($newOrder[$i], $dummy->id); } }
/** * Get the html boolean attributes. * * @return \Illuminate\Support\Collection */ public function getAttributes() { if (self::$attributes === null) { $attributes = $this->loadJson($this->resource('HtmlBooleanAttributes.json'))->attributes; self::$attributes = Collection::make($attributes); } return self::$attributes; }
public static function byYear($year) { $values = self::all()[2016]; foreach ($values as $key => $value) { $values[$key]['year'] = $year; } return Collection::make($values); }
protected function plucked($data) { return Collection::make($data)->map(function ($item) { $key = $item[$this->pluck_key]; $value = $item[$this->pluck_value]; return [$key => $value]; })->toArray(); }
/** * Replace the bound URL generator. * * @return void */ protected function replaceBoundUrlGenerator() { $this->app->bindShared('url', function ($app) { $routes = Collection::make($app['router']->getRoutes())->merge($app['router']->getApiGroups()->getRoutes()); return new UrlGenerator($routes, $app->rebinding('request', function ($app, $request) { $app['url']->setRequest($request); })); }); }
public function getPersonTypeByRole($role) { $m = PersonType::where('role', $role)->first(); if (count($m) > 0) { return $m->persons()->lists('name', 'id_person')->prepend('Selecione', 0); } else { return Collection::make([0 => 'Selecione']); } }
public static function getArray($array, $key) { self::$key = $key; $collection = Collection::make($array); $id = $collection->map(function ($od) { return $od[self::$key]; }); return $id->flatten()->toArray(); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { if ($this->systemAdmin) { $departments = Department::all(); } else { $departments = Collection::make([Auth::user()->department]); } return view('admin.department.index', ['departments' => $departments, 'title' => trans('admin.departments'), 'url' => $this->systemAdmin ? action('Admin\\DepartmentController@create') : '']); }
/** * InstallCommand constructor. * @param \Illuminate\Contracts\Foundation\Application $application * @param \Illuminate\Filesystem\Filesystem $filesystem */ public function __construct(Application $application, Filesystem $filesystem) { parent::__construct(); $this->notadd = $application; $this->config = $this->notadd->make('config'); $this->data = Collection::make(); $this->filesystem = $filesystem; $this->setting = $this->notadd->make('setting'); }
protected static function registerRelations() { if (!static::$relations) { $supported = [HasOne::class => HasOneWrapper::class, BelongsTo::class => BelongsToWrapper::class, BelongsToMany::class => BelongsToManyWrapper::class, HasMany::class => HasManyWrapper::class]; static::$relations = Collection::make([]); foreach ($supported as $rel => $wrapperName) { static::$relations[$rel] = ['className' => $wrapperName]; } } }
/** @test */ public function it_can_set_a_new_order_without_trashed_models() { $this->setUpSoftDeletes(); DummyWithSoftDeletes::first()->delete(); $newOrder = Collection::make(DummyWithSoftDeletes::pluck('id'))->shuffle(); DummyWithSoftDeletes::setNewOrder($newOrder); foreach (DummyWithSoftDeletes::orderBy('order_column')->get() as $i => $dummy) { $this->assertEquals($newOrder[$i], $dummy->id); } }