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

adds user contexts to userevents. #5361

Merged
merged 3 commits into from
Apr 30, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
ilios_api_version: v3.10
ilios_api_version: v3.11
env(TRUSTED_PROXIES):
env(ILIOS_REDIS_URL):
env(ILIOS_CACHE_DECRYPTION_KEY):
Expand Down
5 changes: 5 additions & 0 deletions src/Classes/CalendarEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ class CalendarEvent
#[IA\Expose]
#[IA\Type('array')]
public array $courseTerms = [];

#[IA\Expose]
#[IA\Type('array<string>')]
public array $userContexts = [];

/**
* Clean out all the data for draft or scheduled events
*
Expand Down
22 changes: 22 additions & 0 deletions src/Classes/CalendarEventUserContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Classes;

/**
* Constant interface, defines all the user contexts for calendar events.
* @package App\Classes
*/
interface CalendarEventUserContext
{
public const LEARNER = 'learner';

public const INSTRUCTOR = 'instructor';

public const COURSE_DIRECTOR = 'course director';

public const COURSE_ADMINISTRATOR = 'course administrator';

public const SESSION_ADMINISTRATOR = 'session administrator';
}
206 changes: 155 additions & 51 deletions src/Repository/UserRepository.php

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions src/Traits/CalendarEventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ trait CalendarEventRepository
/**
* Convert offerings into CalendarEvent() objects
*/
protected function createEventObjectsForOfferings(array $results): array
protected function createEventObjectsForOfferings(array $results, array $userContexts = []): array
{
return array_map(fn($arr) => $this->createEventObjectForOffering($arr), $results);
return array_map(fn($arr) => $this->createEventObjectForOffering($arr, $userContexts), $results);
}

protected function createEventObjectForOffering(array $arr): CalendarEvent
protected function createEventObjectForOffering(array $arr, array $userContexts = []): CalendarEvent
{
$event = new CalendarEvent();
$event->name = $arr['title'];
Expand All @@ -56,18 +56,19 @@ protected function createEventObjectForOffering(array $arr): CalendarEvent
$event->supplemental = $arr['supplemental'];
$event->attendanceRequired = $arr['attendanceRequired'];
$event->school = $arr['schoolId'];
$event->userContexts = $userContexts;
return $event;
}

/**
* Convert IlmSessions into CalendarEvent() objects
*/
protected function createEventObjectsForIlmSessions(array $results): array
protected function createEventObjectsForIlmSessions(array $results, array $userContexts = []): array
{
return array_map(fn($arr) => $this->createEventObjectForIlmSession($arr), $results);
return array_map(fn($arr) => $this->createEventObjectForIlmSession($arr, $userContexts), $results);
}

protected function createEventObjectForIlmSession(array $arr): CalendarEvent
protected function createEventObjectForIlmSession(array $arr, array $userContexts = []): CalendarEvent
{
$event = new CalendarEvent();
$event->name = $arr['title'];
Expand All @@ -93,6 +94,7 @@ protected function createEventObjectForIlmSession(array $arr): CalendarEvent
$event->supplemental = $arr['supplemental'];
$event->attendanceRequired = $arr['attendanceRequired'];
$event->school = $arr['schoolId'];
$event->userContexts = $userContexts;
return $event;
}

Expand Down
1 change: 1 addition & 0 deletions tests/Classes/UserEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ public function testCreateFromCalendarEvent()
$this->assertSame($calendarEvent->instructionalNotes, $userEvent->instructionalNotes);
$this->assertSame($calendarEvent->startDate, $userEvent->startDate);
$this->assertSame($calendarEvent->sessionDescription, $userEvent->sessionDescription);
$this->assertSame($calendarEvent->userContexts, $userEvent->userContexts);
}
}
36 changes: 36 additions & 0 deletions tests/Endpoints/UsereventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Tests\Endpoints;

use App\Classes\CalendarEventUserContext;
use App\Entity\Offering;
use App\Entity\OfferingInterface;
use App\Tests\DataLoader\CourseData;
Expand Down Expand Up @@ -226,6 +227,8 @@ public function testGetEvents(): void
$this->assertSame(6, $events[0]['postrequisites'][0]['offering']);
$this->assertSame(3, $events[0]['postrequisites'][0]['session']);
$this->assertEmpty($events[0]['prerequisites']);
$this->assertCount(1, $events[0]['userContexts']);
$this->assertEquals(CalendarEventUserContext::INSTRUCTOR, $events[0]['userContexts'][0]);

$this->assertSame($events[1]['offering'], 4, 'offering is correct for event 1');
$this->assertSame(
Expand Down Expand Up @@ -307,6 +310,8 @@ public function testGetEvents(): void
$this->assertSame(6, $events[1]['postrequisites'][0]['offering']);
$this->assertSame(3, $events[1]['postrequisites'][0]['session']);
$this->assertEmpty($events[1]['prerequisites']);
$this->assertCount(1, $events[1]['userContexts']);
$this->assertEquals(CalendarEventUserContext::LEARNER, $events[1]['userContexts'][0]);

$this->assertSame($events[2]['offering'], 5, 'offering is correct for event 2');
$this->assertSame(
Expand Down Expand Up @@ -392,6 +397,8 @@ public function testGetEvents(): void
$this->assertSame(6, $events[2]['postrequisites'][0]['offering']);
$this->assertSame(3, $events[2]['postrequisites'][0]['session']);
$this->assertEmpty($events[2]['prerequisites']);
$this->assertCount(1, $events[2]['userContexts']);
$this->assertEquals(CalendarEventUserContext::INSTRUCTOR, $events[2]['userContexts'][0]);

$this->assertSame($events[3]['offering'], 6, 'offering is correct for event 3');
$this->assertSame($events[3]['startDate'], $offerings[5]['startDate'], 'startDate is correct for event 3');
Expand Down Expand Up @@ -467,6 +474,8 @@ public function testGetEvents(): void
$sessionIds = array_unique(array_column($events[3]['prerequisites'], 'session'));
sort($sessionIds);
$this->assertSame([2], $sessionIds);
$this->assertCount(1, $events[3]['userContexts']);
$this->assertEquals(CalendarEventUserContext::COURSE_DIRECTOR, $events[3]['userContexts'][0]);

$this->assertSame($events[4]['offering'], 7, 'offering is correct for event 4');
$this->assertSame($events[4]['startDate'], $offerings[6]['startDate'], 'startDate is correct for event 4');
Expand Down Expand Up @@ -542,6 +551,8 @@ public function testGetEvents(): void
$sessionIds = array_unique(array_column($events[4]['prerequisites'], 'session'));
sort($sessionIds);
$this->assertSame([2], $sessionIds);
$this->assertCount(1, $events[4]['userContexts']);
$this->assertEquals(CalendarEventUserContext::COURSE_DIRECTOR, $events[4]['userContexts'][0]);

$this->assertSame($events[5]['ilmSession'], 1, 'ilmSession is correct for 5');
$this->assertSame($events[5]['startDate'], $ilmSessions[0]['dueDate'], 'dueDate is correct for 5');
Expand Down Expand Up @@ -604,6 +615,10 @@ public function testGetEvents(): void
);
$this->assertEmpty($events[5]['postrequisites']);
$this->assertEmpty($events[5]['prerequisites']);
$this->assertCount(3, $events[5]['userContexts']);
$this->assertEquals(CalendarEventUserContext::LEARNER, $events[5]['userContexts'][0]);
$this->assertEquals(CalendarEventUserContext::INSTRUCTOR, $events[5]['userContexts'][1]);
$this->assertEquals(CalendarEventUserContext::COURSE_DIRECTOR, $events[5]['userContexts'][2]);

$this->assertSame($events[6]['ilmSession'], 2, 'ilmSession is correct for event 6');
$this->assertSame($events[6]['startDate'], $ilmSessions[1]['dueDate'], 'dueDate is correct for event 6');
Expand Down Expand Up @@ -665,6 +680,9 @@ public function testGetEvents(): void
);
$this->assertEmpty($events[6]['postrequisites']);
$this->assertEmpty($events[6]['prerequisites']);
$this->assertCount(2, $events[6]['userContexts']);
$this->assertEquals(CalendarEventUserContext::INSTRUCTOR, $events[6]['userContexts'][0]);
$this->assertEquals(CalendarEventUserContext::COURSE_DIRECTOR, $events[6]['userContexts'][1]);

$this->assertSame($events[7]['ilmSession'], 3, 'ilmSession is correct for event 7');
$this->assertSame($events[7]['startDate'], $ilmSessions[2]['dueDate'], 'dueDate is correct for event 7');
Expand Down Expand Up @@ -726,6 +744,9 @@ public function testGetEvents(): void
);
$this->assertEmpty($events[7]['postrequisites']);
$this->assertEmpty($events[7]['prerequisites']);
$this->assertCount(2, $events[7]['userContexts']);
$this->assertEquals(CalendarEventUserContext::INSTRUCTOR, $events[7]['userContexts'][0]);
$this->assertEquals(CalendarEventUserContext::COURSE_DIRECTOR, $events[7]['userContexts'][1]);

$this->assertSame($events[8]['ilmSession'], 4, 'ilmSession is correct for event 8');
$this->assertSame($events[8]['startDate'], $ilmSessions[3]['dueDate'], 'dueDate is correct for event 8');
Expand Down Expand Up @@ -787,6 +808,9 @@ public function testGetEvents(): void
);
$this->assertEmpty($events[8]['postrequisites']);
$this->assertEmpty($events[8]['prerequisites']);
$this->assertCount(2, $events[8]['userContexts']);
$this->assertEquals(CalendarEventUserContext::LEARNER, $events[8]['userContexts'][0]);
$this->assertEquals(CalendarEventUserContext::COURSE_DIRECTOR, $events[8]['userContexts'][1]);

$this->assertSame(
$events[9]['url'],
Expand Down Expand Up @@ -870,6 +894,9 @@ public function testGetEvents(): void
);
$this->assertSame(0, count($events[9]['postrequisites']));
$this->assertEmpty($events[9]['prerequisites']);
$this->assertCount(2, $events[9]['userContexts']);
$this->assertEquals(CalendarEventUserContext::LEARNER, $events[9]['userContexts'][0]);
$this->assertEquals(CalendarEventUserContext::INSTRUCTOR, $events[9]['userContexts'][1]);

/** @var OfferingInterface $offering */
$offering = $this->fixtures->getReference('offerings8', Offering::class);
Expand Down Expand Up @@ -925,6 +952,9 @@ public function testGetEvents(): void
$this->assertEmpty($events[10]['postrequisites']);
$this->assertSame(3, count($events[10]['prerequisites']));
$sessionIds = array_unique(array_column($events[10]['prerequisites'], 'session'));
$this->assertCount(1, $events[10]['userContexts']);
$this->assertEquals(CalendarEventUserContext::COURSE_DIRECTOR, $events[10]['userContexts'][0]);

sort($sessionIds);
$this->assertSame([2], $sessionIds);
foreach ($events as $event) {
Expand Down Expand Up @@ -998,6 +1028,9 @@ public function testGetEventsBySessionForCourseDirector(): void
$this->assertSame($sessionId, $events[1]['session']);
$this->assertSame(8, $events[2]['offering']);
$this->assertSame($sessionId, $events[2]['session']);
foreach ($events as $event) {
$this->assertContains(CalendarEventUserContext::COURSE_DIRECTOR, $event['userContexts']);
}
}

public function testGetEventsBySessionForLearner(): void
Expand All @@ -1020,6 +1053,9 @@ public function testGetEventsBySessionForLearner(): void
$this->assertSame($sessionId, $events[0]['session']);
$this->assertSame(2, $events[1]['offering']);
$this->assertSame($sessionId, $events[1]['session']);
foreach ($events as $event) {
$this->assertContains(CalendarEventUserContext::LEARNER, $event['userContexts']);
}
}

public function testAttachedInstructorsUseDisplayNameAndPronouns(): void
Expand Down