Example #1
0
 /**
  * @param $imei
  * @param Collection|null $traza
  * @return array
  */
 private function setUnitsCollection($imei, Collection $traza = null, Collection $modeloInfo = null)
 {
     $result = [];
     if (!$traza == null) {
         return $result = ['imei' => $imei, 'sl' => $traza->first()->Codigo, 'fechaHora' => $traza->first()->FechaHora, 'carrier' => $this->findInCollection($modeloInfo, 'Campo', 'CARRIER')->Valor, 'salesModel' => $this->findInCollection($modeloInfo, 'Campo', 'SALESMODEL')->Valor, 'partNumber' => $this->findInCollection($modeloInfo, 'Campo', 'PART_NUMBER')->Valor];
     } else {
         return $result = ['imei' => $imei, 'sl' => 'Sin resultados', 'fechaHora' => '-', 'carrier' => '-', 'salesModel' => '-', 'partNumber' => '-'];
     }
 }
Example #2
0
 public function upload(PhotoUploadRequest $request)
 {
     $user = Auth::user();
     $destinationPath = 'uploads/';
     if ($request->hasFile('files')) {
         $photos = new Collection();
         $i = 0;
         foreach ($request->file('files') as $file) {
             $extension = $file->getClientOriginalExtension();
             $new_filename = time() . uniqid() . str_random(rand(5, 15)) . '.' . $extension;
             $file->move($destinationPath, $new_filename);
             $photos[$i] = new Photo();
             $photos[$i]->content_type = $file->getClientMimeType();
             $photos[$i]->disk_name = $new_filename;
             $photos[$i]->file_name = $file->getClientOriginalName();
             $photos[$i]->path = $destinationPath . $new_filename;
             $photos[$i]->file_size = $file->getClientSize();
             $photos[$i]->user_id = $user->id;
             $photos[$i]->save();
             $i++;
         }
         return $photos->first();
     }
     return response()->json(['status' => 'error']);
 }
Example #3
0
 /**
  * Format an Eloquent collection.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $collection
  * @return string
  */
 public function formatEloquentCollection($collection)
 {
     if ($collection->isEmpty()) {
         return $this->encode([]);
     }
     $key = str_plural($collection->first()->getTable());
     return $this->encode([$key => $collection->toArray()]);
 }
Example #4
0
 /**
  * shouldTryAgain.
  *
  * @author Casper Rasmussen <*****@*****.**>
  * @return bool
  */
 private function shouldTryAgain()
 {
     if ($this->failedCarbons->count() < $this->maxNetworkRetries) {
         return true;
     }
     /** @var Carbon $carbon */
     $carbon = $this->failedCarbons->first();
     if ($carbon->diffInSeconds(Carbon::now()) >= $this->retryNetworkAfterSec) {
         return true;
     }
     return false;
 }
Example #5
0
 /**
  * Format an Eloquent collection.
  *
  * @param \Illuminate\Database\Eloquent\Collection $collection
  *
  * @return string
  */
 public function formatEloquentCollection($collection)
 {
     if ($collection->isEmpty()) {
         return $this->encode([]);
     }
     $model = $collection->first();
     $key = str_plural($model->getTable());
     if (!$model::$snakeAttributes) {
         $key = camel_case($key);
     }
     return $this->encode([$key => $collection->toArray()]);
 }
Example #6
0
 public function match(array $models, Collection $results, $relation)
 {
     $match = $this->matchPHP;
     foreach ($models as $model) {
         $value = $results->first(function ($result) use($match, $model) {
             return $match($model, $result);
         });
         if ($value) {
             $model->setRelation($relation, $value);
         }
     }
     return $models;
 }
 /**
  * @param \Illuminate\Database\Eloquent\Collection|static[] $collection
  */
 public function generateArrayData($collection)
 {
     $modelObject = $collection->first();
     $arrayData = array();
     foreach ($collection as $item) {
         $row = array();
         foreach ($modelObject->getListAttributes() as $index => $value) {
             $row[] = $item->{$index};
         }
         $pk = $modelObject->getPrimaryKey();
         $href = route('admin_edit', ['model' => $this->model->getUrlName(), 'id' => "{$pk}:{$item->{$pk}}"]);
         $row[] = "<a href='{$href}'>Editar</a>";
         $arrayData[] = $row;
     }
     return $arrayData;
 }
Example #8
0
 /**
  * Extract the model instance and model keys from the given parameters.
  *
  * @param  string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection  $model
  * @param  array|null  $keys
  * @return array
  */
 public static function extractModelAndKeys($model, array $keys = null)
 {
     if (is_null($keys)) {
         if ($model instanceof Model) {
             return [$model, [$model->getKey()]];
         }
         if ($model instanceof Collection) {
             return [$model->first(), $model->modelKeys()];
         }
     } else {
         if (is_string($model)) {
             $model = new $model();
         }
         return [$model, $keys];
     }
 }
 /**
  * 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;
 }
 /**
  * Display one or more prospects.
  *
  * @note We're using the 'table()' function which expects an array
  *       of arrays (i.e. rows of data items/fields)
  *
  * @param Collection $prospects
  * @param bool $forceList
  * @param int $maxLen
  */
 protected function showProspects($prospects, $forceList = false, $maxLen = 76)
 {
     if (empty($prospects) || $prospects->isEmpty()) {
         $this->info('No prospect records to display');
         return;
     }
     if ($prospects->count() > 1 || $forceList) {
         $rows = $prospects->toArray();
         $this->table(array_keys($rows[0]), $rows);
     } else {
         $prospect = $prospects->first();
         $data = $prospect->toArray();
         $rows = [];
         foreach ($data as $k => $v) {
             $rows[] = [$k, is_string($v) ? str_limit($v, $maxLen) : $v];
         }
         $this->table(['field', 'value'], $rows);
     }
     $this->info('');
     // Print a blank line
 }
Example #11
0
 /**
  * Odgovor servera u slučaju pokušaja rezerviranja kada postoje nenaplaćene rezervacije.
  * @param \Illuminate\Database\Eloquent\Collection $nenaplaceneRezervacije Nenaplaćene rezervacije
  * @return Response
  */
 private function nenaplaceno($nenaplaceneRezervacije)
 {
     Session::flash(self::DANGER_MESSAGE_KEY, 'Nije dozvoljeno praviti rezervaiju dok ne naplatite sve odrađene.<br/>' . 'Primjerice rezervacija ' . $nenaplaceneRezervacije->first()->link() . ' nije naplaćena.');
     return Redirect::route('home');
 }
 public function testFirstReturnsFirstItemInCollection()
 {
     $c = new Collection(array('foo', 'bar'));
     $this->assertEquals('foo', $c->first());
 }
 /**
  * Find the item entry of a specific product key in a collection of items.
  *
  * @param  \Illuminate\Database\Eloquent\Collection $items
  * @param  mixed                                    $key   The product's primary key.
  *
  * @return \REDACTED\Wastage\ItemModel|null
  */
 protected function findProductItem(Collection $items, $key)
 {
     if ($key instanceof ItemModel) {
         $key = $key->getKey();
     }
     return $items->first(function ($id, $item) use($key) {
         return $item->product_id == $key;
     });
 }
Example #14
0
 public function first()
 {
     return $this->data->first();
 }
Example #15
0
 /**
  * Updates the current user's searched hashtags with the specified hashtag
  * $terms and returns the number of hashtags updated or -1 on failure.
  *
  * @param  Collection   $hashtags hashtag collection to update
  * @param  array|string $terms hashtag terms to update with
  * @return integer
  */
 protected function updateUserHashtags(Collection $hashtags, array $terms)
 {
     $num_updates = 0;
     foreach ($terms as $id => $term) {
         // remove whitespace, convert to lowercase
         $term = strtolower(preg_replace('/\\s+/', '', $term));
         if (!empty(trim($term))) {
             // verify hashtag term does not already exists
             $hashtag = $hashtags->first(function ($key, $value) use($id, $term) {
                 return $value->id != $id && $value->term == $term;
             });
             if (isset($hashtag)) {
                 // indicate error has occured
                 $num_updates = -1;
                 \Session::put('error_hashtag_edit_id', $id);
                 \Session::flash('flash_message', 'Hashtag \'' . $term . '\' already exists.');
                 break;
             }
             // update hashtag term if not the same
             $hashtag = $hashtags->find($id);
             if (isset($hashtag) && $hashtag->term != $term) {
                 $hashtag->term = $term;
                 $hashtag->save();
                 $num_updates++;
             }
         }
     }
     return $num_updates;
 }