Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods interfaces #67

Merged
merged 4 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Models/EscaperoomLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tipoff\EscapeRoom\Models;

use DrewRoberts\Media\Models\Image;
use Tipoff\Locations\Models\Location;
use Tipoff\Support\Models\BaseModel;
use Tipoff\Support\Traits\HasCreator;
Expand All @@ -22,14 +21,14 @@ class EscaperoomLocation extends BaseModel
*/
public function location()
{
return $this->belongsTo(Location::class);
return $this->belongsTo(app('location'));
}

/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function teamPhoto()
{
return $this->belongsTo(Image::class, 'team_image_id');
return $this->belongsTo(app('image'), 'team_image_id');
}
}
5 changes: 2 additions & 3 deletions src/Models/EscaperoomMarket.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tipoff\EscapeRoom\Models;

use DrewRoberts\Media\Models\Image;
use Tipoff\Locations\Models\Location;
use Tipoff\Support\Models\BaseModel;
use Tipoff\Support\Traits\HasCreator;
Expand All @@ -22,14 +21,14 @@ class EscaperoomMarket extends BaseModel
*/
public function location()
{
return $this->belongsTo(Location::class);
return $this->belongsTo(app('location'));
}

/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function teamPhoto()
{
return $this->belongsTo(Image::class, 'team_image_id');
return $this->belongsTo(app('image'), 'team_image_id');
}
}
46 changes: 43 additions & 3 deletions src/Models/EscaperoomRate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@

namespace Tipoff\EscapeRoom\Models;

use Tipoff\Support\Contracts\Booking\BookingRateInterface;
use Tipoff\Support\Models\BaseModel;
use Tipoff\Support\Traits\HasCreator;
use Tipoff\Support\Traits\HasPackageFactory;
use Tipoff\Support\Traits\HasUpdater;

class EscaperoomRate extends BaseModel
class EscaperoomRate extends BaseModel /*implements BookingRateInterface*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drewroberts @sl0wik I have to do this here, because this class has no relation to satisfy neither category nor getCategory methods..

{
use HasCreator;
use HasUpdater;
use HasPackageFactory;

protected $casts = [];

public $amount;

protected static function boot()
{
parent::boot();
Expand Down Expand Up @@ -122,12 +125,14 @@ public function getRouteKeyName()
* @param bool $isPrivate
* @return int
*/
public function getAmount(int $participants, bool $isPrivate)
public function generateAmount(int $participants, bool $isPrivate): int
{
$key = ($isPrivate) ? 'private_' : 'public_';
$key = $key.$participants;

return $this->$key * $participants;
$this->amount = $this->$key * $participants;

return $this->amount;
}

/**
Expand Down Expand Up @@ -161,4 +166,39 @@ public function schedules()
{
return $this->hasMany(app('schedule'));
}

public function getAmount(): int
{
return $this->amount;
}

public function getLabel(): string
{
// @todo: implement getLabel
return "";
}

public function getSlug(): string
{
// @todo: implement getSlug
return "";
}

public function category(): Relation
{
// @todo: implement category
return null;
}

public function getCategory(): BookingRateCategoryInterface
{
// @todo: implement getCategory
return null;
}

public function getParticipantsLimit(): ?int
{
// @todo: implement getParticipantsLimit
return 1;
}
}
6 changes: 3 additions & 3 deletions src/Models/EscaperoomTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ protected static function boot()

public function rooms()
{
return $this->hasMany(Room::class);
return $this->hasMany(app('room'));
}

public function locations()
{
return $this->hasManyThrough(app('location'), Room::class, 'escaperoom_theme_id', 'id', 'id', 'location_id');
return $this->hasManyThrough(app('location'), app('room'), 'escaperoom_theme_id', 'id', 'id', 'location_id');
}

public function supervision()
{
return $this->belongsTo(Supervision::class);
return $this->belongsTo(app('supervision'));
}

public function images()
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Models/EscaperoomRateModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function always_return_amount(EscaperoomRate $model)
{
$isPrivate = (bool)rand(0, 1);
$participants = rand(1, 9);
$amount = $model->getAmount($participants, $isPrivate);
$amount = $model->generateAmount($participants, $isPrivate);
$this->assertIsInt($amount);
}

Expand Down