Ejemplo n.º 1
0
 /**
  * @param \HorseStories\Models\Horses\Horse $horse
  * @param int $type
  * @return int
  */
 public function getConnection(Horse $horse, $type)
 {
     $female = $horse->isFemale();
     switch ($type) {
         case Pedigree::MOTHER:
             if ($female) {
                 return 4;
             }
             return 3;
         case Pedigree::FATHER:
             if ($female) {
                 return 4;
             }
             return 3;
         case Pedigree::SON:
             if ($female) {
                 return 2;
             }
             return 1;
         case Pedigree::DAUGHTER:
             if ($female) {
                 return 2;
             }
             return 1;
     }
 }
Ejemplo n.º 2
0
 /**
  * @param \HorseStories\Models\Horses\Horse $horse
  * @param array $values
  */
 public function update(Horse $horse, array $values = [])
 {
     $horse->name = $values['name'];
     $horse->gender = $values['gender'];
     $horse->breed = $values['breed'];
     $horse->height = $values['height'];
     $horse->color = $values['color'];
     $horse->date_of_birth = DateTime::createFromFormat('d/m/Y', $values['date_of_birth']);
     $horse->life_number = $values['life_number'];
     $initialDisciplines = [];
     foreach ($horse->disciplines as $initialDiscipline) {
         $initialDisciplines[$initialDiscipline->id] = $initialDiscipline->discipline;
     }
     foreach ($values['disciplines'] as $discipline) {
         $horse->disciplines()->updateOrCreate(['discipline' => $discipline, 'horse_id' => $horse->id]);
     }
     $unwantedDisciplines = array_diff($initialDisciplines, $values['disciplines']);
     foreach ($unwantedDisciplines as $key => $values) {
         $this->disciplines->removeById($key);
     }
     $horse->save();
 }
Ejemplo n.º 3
0
 /**
  * @param array $values
  * @param bool $pedigree
  * @return \HorseStories\Models\Horses\Horse
  */
 public function create($values = [], $pedigree = false)
 {
     $horse = new Horse();
     $horse->name = $values['name'];
     if (!$pedigree) {
         $horse->user_id = $this->auth->user()->id;
     }
     $horse->gender = $values['gender'];
     $horse->breed = $values['breed'];
     $horse->life_number = $values['life_number'];
     $horse->color = $values['color'];
     $horse->date_of_birth = DateTime::createFromFormat('d/m/Y', $values['date_of_birth']);
     $horse->height = $values['height'];
     $horse->slug = $this->slugCreator->createForHorse($values['name']);
     $horse->save();
     if (array_key_exists('disciplines', $values)) {
         foreach ($values['disciplines'] as $discipline) {
             $horse->disciplines()->updateOrCreate(['discipline' => $discipline, 'horse_id' => $horse->id]);
         }
     }
     return $horse;
 }
Ejemplo n.º 4
0
 public function index($horseSlug)
 {
     $horse = Horse::with('pictures')->where('slug', $horseSlug)->firstOrFail();
     return view('horses.pictures.index', compact('horse'));
 }
Ejemplo n.º 5
0
 /**
  * @param string $title
  * @return string
  */
 public function createForHorse($title)
 {
     $slug = Str::slug($title);
     $slugCount = count($this->horse->whereRaw("slug REGEXP '^{$slug}(-[0-9]*)?\$'")->get());
     return $slugCount > 0 ? "{$slug}-{$slugCount}" : $slug;
 }
Ejemplo n.º 6
0
 public function index($horseSlug)
 {
     $horse = Horse::where('slug', $horseSlug)->firstOrFail();
     $followers = $this->followsRepository->findForHorse($horse);
     return view('follows.index', compact('horse', 'followers'));
 }
Ejemplo n.º 7
0
 /**
  * @param \HorseStories\Models\Horses\Horse $horse
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function findForHorse(Horse $horse)
 {
     return $horse->followers()->get();
 }
Ejemplo n.º 8
0
 /**
  * @param \HorseStories\Models\Users\User $user
  * @return array
  */
 public function findHorsesForSelect(User $user)
 {
     return $this->horse->with('statuses')->where('user_id', $user->id)->lists('name', 'id');
 }