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

release #322

Merged
merged 8 commits into from
Mar 19, 2024
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: 4 additions & 1 deletion app/Models/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class Course extends \EscolaLms\Courses\Models\Course implements Productable

public function attachToUser(User $user, int $quantity = 1, ?Product $product = null): void
{
$this->users()->syncWithoutDetaching($user->getKey());
$productUser = $product?->users()->where('user_id', $user->getKey())->first()?->pivot;

$this->users()->syncWithoutDetaching([$user->getKey() => ['end_date' => $productUser?->end_date]]);

event(new CourseAssigned($user, $this));
event(new CourseAccessStarted($user, $this));
}
Expand Down
30 changes: 30 additions & 0 deletions app/Models/Dictionary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Models;

use EscolaLms\Cart\Contracts\Productable;
use EscolaLms\Cart\Contracts\ProductableTrait;
use EscolaLms\Cart\Models\Product;
use EscolaLms\Core\Models\User;
use EscolaLms\Courses\Events\CourseAccessStarted;
use EscolaLms\Courses\Events\CourseAssigned;
use EscolaLms\Courses\Events\CourseFinished;
use EscolaLms\Courses\Events\CourseUnassigned;
use EscolaLms\Dictionaries\Models\Dictionary as BaseDictionary;

class Dictionary extends BaseDictionary implements Productable
{
use ProductableTrait;

public function attachToUser(User $user, int $quantity = 1, ?Product $product = null): void
{
$productUser = $product?->users()->where('user_id', $user->getKey())->first()?->pivot;

$this->users()->syncWithoutDetaching([$user->getKey() => ['end_date' => $productUser?->end_date]]);
}

public function detachFromUser(User $user, int $quantity = 1, ?Product $product = null): void
{
$this->users()->detach($user->getKey());
}
}
10 changes: 10 additions & 0 deletions app/Providers/ShopServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Consultation;
use App\Models\Course;
use App\Models\Dictionary;
use App\Models\StationaryEvent;
use App\Models\Webinar;
use EscolaLms\Cart\Facades\Shop;
Expand All @@ -14,6 +15,7 @@
use EscolaLms\Consultations\Http\Resources\ConsultationTermsResource;
use EscolaLms\Courses\Http\Resources\CourseListResource;
use EscolaLms\Courses\Http\Resources\CourseSimpleResource;
use EscolaLms\Dictionaries\Http\Resources\DictionaryResource;
use EscolaLms\StationaryEvents\Http\Resources\StationaryEventResource;
use EscolaLms\Webinar\Http\Resources\WebinarSimpleResource;
use Illuminate\Contracts\Container\BindingResolutionException;
Expand Down Expand Up @@ -84,6 +86,14 @@ function($element) {
$element
)
);
Shop::registerProductableClass(Dictionary::class);
DictionaryResource::extend(
fn ($element) =>
$this->registerProductToResource(
Dictionary::class,
$element
)
);
}

private function registerProductToResource(string $class, $element): array
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"escolalms/courses": "^0",
"escolalms/courses-import-export": "^0.1.21",
"escolalms/csv-users": "^0",
"escolalms/dictionaries": "^0",
"escolalms/files": "^0",
"escolalms/headless-h5p": "^0",
"escolalms/images": "^0",
Expand Down
Loading
Loading