Add method to check when user is a tutor

pull/5824/head
Angel Fernando Quiroz Campos 12 months ago
parent 30a79c678a
commit 2db0656f12
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 9
      src/CoreBundle/Entity/Course.php
  2. 5
      src/CoreBundle/Entity/User.php

@ -455,18 +455,23 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith
}
public function hasSubscriptionByUser(User $user): bool
{
return (bool) $this->getSubscriptionByUser($user);
}
public function getSubscriptionByUser(User $user): ?CourseRelUser
{
$users = $this->getUsers();
if (0 === $users->count()) {
return false;
return null;
}
$matching = $users->filter(
fn (CourseRelUser $subscription) => $subscription->getUser()->getId() === $user->getId()
);
return $matching->count() > 0;
return $matching->count() > 0 ? $matching->first() : null;
}
/**

@ -2406,4 +2406,9 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
return $match->count() > 0 ? $match->first() : null;
}
public function isCourseTutor(?Course $course = null, ?Session $session = null): bool
{
return $session?->hasCoachInCourseList($user) || $course?->getSubscriptionByUser($user)?->isTutor();
}
}

Loading…
Cancel
Save