Exemplo n.º 1
0
 public function map($hash, $title = true)
 {
     if (strlen($hash) < 1) {
         $hash = '9999999999';
     }
     if (Hashes::$items == null) {
         $this->getItems();
     }
     $object = Hashes::$items->filter(function ($item) use($hash) {
         return $item->hash == $hash;
     })->first();
     if ($object instanceof Hash) {
         if ($title) {
             return $object->title;
         }
         return $object;
     } else {
         if ($this->allowedRetry) {
             $this->updateHashes();
             return $this->map($hash, $title);
         } else {
             $classified = Hash::where('hash', '9999999999')->first();
             if ($title) {
                 return $classified->title;
             }
             return $classified;
             // throw new HashNotLocatedException($hash);
         }
     }
 }
 /**
  * Execute the job.
  *
  * @return Collection
  */
 public function handle()
 {
     return $this->bookings->filter(function ($booking) {
         $value = 0;
         $payed = 0;
         foreach ($booking->customer_booking as $customer) {
             if ($customer->price) {
                 $value += $customer->price->price;
             }
         }
         foreach ($booking->payment as $payment) {
             $payed += $payment->value;
         }
         if ($value === $payed) {
             return true;
         }
         return false;
     })->sortByDesc('id');
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 public function match(array $models, Collection $results, $relation)
 {
     $match = $this->matchPHP;
     foreach ($models as $model) {
         $value = $results->filter(function ($result) use($match, $model) {
             return $match($model, $result);
         });
         if ($value->count()) {
             $model->setRelation($relation, $value);
         }
     }
     return $models;
 }
Exemplo n.º 5
0
 /**
  * Get all roles as collection.
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function getRoles()
 {
     if (!$this->roles) {
         $this->roles = $this->grantedRoles()->get();
         $deniedRoles = $this->deniedRoles()->get();
         foreach ($deniedRoles as $role) {
             $deniedRoles = $deniedRoles->merge($role->descendants());
         }
         foreach ($this->roles as $role) {
             if (!$deniedRoles->contains($role)) {
                 $this->roles = $this->roles->merge($role->descendants());
             }
         }
         $this->roles = $this->roles->filter(function ($role) use($deniedRoles) {
             return !$deniedRoles->contains($role);
         });
     }
     return $this->roles;
 }
Exemplo n.º 6
0
 /**
  * Match the eagerly loaded results to their parents.
  *
  * @param  array   $models
  * @param  \Illuminate\Database\Eloquent\Collection  $results
  * @param  string  $relation
  * @return array
  */
 public function match(array $models, Collection $results, $relation)
 {
     // We will need the parent node placeholder so that we use it to extract related results.
     $parent = $this->query->getQuery()->modelAsNode($this->parent->getTable());
     /**
      * Looping into all the parents to match back onto their children using
      * the primary key to map them onto the correct instances, every single
      * result will be having both instances at each Collection item, held by their
      * node placeholder.
      */
     foreach ($models as $model) {
         $matched = $results->filter(function ($result) use($parent, $model) {
             if ($result[$parent] instanceof Model) {
                 // In the case of fetching nested relations, we will get an array
                 // with the first key being the model we need, and the other being
                 // the related model so we'll just take the first model out of the array.
                 if (is_array($model)) {
                     $model = reset($model);
                 }
                 return $model->getKey() == $result[$parent]->getKey();
             }
         });
         // Now that we have the matched parents we know where to add the relations.
         // Sometimes we have more than a match so we gotta catch them all!
         foreach ($matched as $match) {
             // In the case of fetching nested relations, we will get an array
             // with the first key being the model we need, and the other being
             // the related model so we'll just take the first model out of the array.
             if (is_array($model)) {
                 $model = reset($model);
             }
             $model->setRelation($relation, $match[$relation]);
         }
     }
     return $models;
 }
Exemplo n.º 7
0
 /**
  * Search through the record list for one matching the provided path.
  * @param  string $path
  * @param  \Illuminate\Database\Eloquent\Collection $existing_media
  * @return \Plank\Mediable\Media|null
  */
 protected function getRecordForFile($path, $existing_media)
 {
     $directory = File::cleanDirname($path);
     $filename = pathinfo($path, PATHINFO_FILENAME);
     $extension = pathinfo($path, PATHINFO_EXTENSION);
     return $existing_media->filter(function (Media $media) use($directory, $filename, $extension) {
         return $media->directory == $directory && $media->filename == $filename && $media->extension == $extension;
     })->first();
 }
 /**
  * Execute the job.
  *
  * @return Collection
  */
 public function handle()
 {
     return $this->bookings->filter(function ($booking) {
         return !$booking->payment->count() ? true : false;
     })->sortByDesc('id');
 }
Exemplo n.º 9
0
 /**
  * Match the eagerly loaded results to their parents.
  *
  * @param  array   $models
  * @param  \Illuminate\Database\Eloquent\Collection  $results
  * @param  string  $relation
  * @return array
  */
 public function matchOneOrMany(array $models, Collection $results, $relation, $type)
 {
     // We will need the parent node placeholder so that we use it to extract related results.
     $parent = $this->query->getQuery()->modelAsNode($this->parent->getTable());
     /**
      * Looping into all the parents to match back onto their children using
      * the primary key to map them onto the correct instances, every single
      * result will be having both instances at each Collection item, held by their
      * node placeholder.
      */
     foreach ($models as $model) {
         $matched = $results->filter(function ($result) use($parent, $relation, $model) {
             if ($result[$parent] instanceof Model) {
                 return $model->getKey() == $result[$parent]->getKey();
             }
         });
         // Now that we have the matched parents we know where to add the relations.
         // Sometimes we have more than a match so we gotta catch them all!
         foreach ($matched as $match) {
             if ($type == 'many') {
                 $collection = $model->getRelation($relation);
                 $collection->push($match[$relation]);
                 $model->setRelation($relation, $collection);
             } else {
                 $model->setRelation($relation, $match[$relation]);
             }
         }
     }
     return $models;
 }
 /**
  * Get items from collection whose properties match a given attribute and value
  *
  * @param  Collection  $collection
  * @param  string      $attribute
  * @param  mixed       $value
  *
  * @return Collection
  */
 protected function getByAttributeFromCollection(Collection $collection, $attribute, $value = null)
 {
     return $collection->filter(function ($item) use($attribute, $value) {
         if (isset($item->{$attribute}) && $value) {
             return $item->{$attribute} == $value;
         }
         return false;
     });
 }
Exemplo n.º 11
0
 /**
  * Filters a forum collection by the "canView" permission
  *
  * @param Collection $forums
  *
  * @return Collection
  */
 private function filterUnviewableForums(Collection $forums)
 {
     return $forums->filter(function (Forum $forum) {
         return $this->permissionChecker->hasPermission('forum', $forum->getContentId(), $forum::getViewablePermission(), $this->guard->user());
     });
 }
Exemplo n.º 12
0
 public function transformPost(\Post $post, Collection $favorites, Collection $subscriptions)
 {
     $response = ['id' => $post->id, 'text' => $post->text, 'created_at' => $post->created_at, 'updated_at' => $post->updated_at, 'user' => $this->transformUserToSmall($post->user), 'attachments' => $this->transformAttachments($post), 'comments_count' => $post->comments->count(), 'likes' => $post->likes->count(), 'commented' => $post->commented(), 'liked' => $post->liked() ? 1 : 0, 'is_fav' => $favorites->filter(function ($favorite) use($post) {
         return $favorite->id == $post->id;
     })->count() == 1 ? 1 : 0, 'category' => ['id' => $post->category->id, 'title' => $post->category->title, 'subscribed' => $subscriptions->filter(function ($subscription) use($post) {
         return $subscription->id == $post->category->id;
     })->count() == 1 ? 1 : 0]];
     //		if ($comments)
     //			$response['comments'] = $this->transformComments($post->comments);
     return $response;
 }
Exemplo n.º 13
0
 /**
  * Check if node is sibling for roots in collection
  *
  * @param Tree       $node  Tree node
  * @param Collection $roots Collection of roots
  *
  * @return bool
  */
 private function siblingOfRoot(Tree $node, Collection $roots)
 {
     return (bool) $roots->filter(function ($item) use($node) {
         return $node->isSibling($item);
     })->first();
 }
Exemplo n.º 14
0
 public function returnProjectModels(Collection $collection)
 {
     $user = \Authorization::user();
     $wishlist = WishModel::where('user_id', '=', $user->id)->get();
     if ($user->userable_type == BuyerModel::class) {
         $collection->filter(function ($item) use($wishlist) {
             $wishlist->contains('project_id', $item->id) ? $item->wishlisted = true : ($item->wishlisted = false);
             return $item;
         });
     }
     return $this->withCollection($collection, new ProjectTransformer());
 }
Exemplo n.º 15
0
 /**
  * Retrieve all the forming guilds.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $guilds
  * @return array
  */
 protected function getFormingGuilds(Collection $guilds)
 {
     return $guilds->filter(function ($guild) {
         return $guild->isForming();
     });
 }