Skip to content

Commit

Permalink
make event to work with membership table
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 17, 2024
1 parent ff6062a commit d0a1cff
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/Events/AddMembership.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Events;

use App\Models\Membership;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class AddMembership
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public Membership $membership;


/**
* Create a new event instance.
*/
public function __construct(Membership $membership)
{
$this->membership = $membership;
}

}
2 changes: 2 additions & 0 deletions app/Jobs/FolderAddEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public function handle(): void
{
$federationMembershipId = Membership::select('federation_id')
->where('entity_id', $this->entity->id)
->where('approved', 1)
->get();


$diskName = config('storageCfg.name');

foreach ($federationMembershipId as $fedId) {
Expand Down
37 changes: 37 additions & 0 deletions app/Listeners/SendNewMemberToSaveJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Listeners;

use App\Events\AddMembership;
use App\Jobs\EduGainAddEntity;
use App\Jobs\FolderAddEntity;
use App\Models\Entity;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

class SendNewMemberToSaveJob
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}

/**
* Handle the event.
*/
public function handle(AddMembership $event): void
{
$entityId = $event->membership->entity_id;
$entity = Entity::find($entityId);


if ($entity->approved == 1 && $event->membership->approved == 1 ) {
Log::info(" dispatch FolderAddEntity from Listener SendNewMemberToSaveJob");
}

}
}
8 changes: 8 additions & 0 deletions app/Models/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Events\AddMembership;
use Illuminate\Database\Eloquent\Relations\Pivot;

class Membership extends Pivot
Expand Down Expand Up @@ -31,4 +32,11 @@ public function approver()
{
return $this->belongsTo('App\Models\User', 'approved_by');
}

protected $dispatchesEvents = [
'updated' => AddMembership::class,
// 'deleted' => DeleteEntity::class,

];

}
5 changes: 5 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace App\Providers;

use App\Events\AddMembership;
use App\Events\CreateEntity;
use App\Events\DeleteEntity;
use App\Events\FederationApprove;
use App\Events\UpdateEntity;
use App\Listeners\CreateFederationFolder;
use App\Listeners\SendCreatedEntityToSaveJob;
use App\Listeners\SendDeletedEntityToDeleteJob;
use App\Listeners\SendNewMemberToSaveJob;
use App\Listeners\SendUpdatedEntityToSaveJob;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
Expand Down Expand Up @@ -38,6 +40,9 @@ class EventServiceProvider extends ServiceProvider
DeleteEntity::class => [
SendDeletedEntityToDeleteJob::class,
],
AddMembership::class => [
SendNewMemberToSaveJob::class,
],

];

Expand Down

0 comments on commit d0a1cff

Please sign in to comment.