Skip to content

Commit

Permalink
fix: some instructors teaching wrong course (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
jxjj authored Sep 17, 2024
1 parent 0114f77 commit 57d4f8c
Show file tree
Hide file tree
Showing 20 changed files with 515 additions and 255 deletions.
14 changes: 14 additions & 0 deletions app/Contracts/CourseInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Contracts;

interface CourseInterface {
public function getSubject(): string; // "HIST"
public function getCatalogNumber(): string; // "1001W"
public function getTitle(): string; // "History of the World"
public function getCourseCode(): string; // "HIST-1001W"
public function getCourseType(): string; // "LEC"
public function getCourseLevel(): string; // "UGRD"
public function getSource(): string; // "local" or "sis"
public function getApiId(): string; // "HIST-1001W"
}
18 changes: 18 additions & 0 deletions app/Contracts/CourseSectionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Contracts;

interface CourseSectionInterface {
public function getApiId(): string;
public function getCourseApiId(): string;
public function getDBId(): int | null;
public function getTermId(): int;
public function getClassSection(): string;
public function getEnrollmentCap(): int;
public function getEnrollmentTotal(): int;
public function getWaitlistCap(): int;
public function getWaitlistTotal(): int;
public function isCancelled(): bool;
public function isPublished(): bool;
public function getSource(): string;
}
13 changes: 13 additions & 0 deletions app/Contracts/EnrollmentInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Contracts;

interface EnrollmentInterface {
public function getApiId(): string;
public function getDBId(): int | null;
public function getEmplid(): int;
public function getSectionApiId(): string;
public function getSectionDBId(): int | null;
public function getRole(): string;
public function getSource(): string;
}
45 changes: 32 additions & 13 deletions app/Course.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Contracts\CourseInterface;

/**
* @mixin IdeHelperCourse
*/
class Course extends Model {
class Course extends Model implements CourseInterface {
use HasFactory;

protected $fillable = [
Expand All @@ -21,22 +22,40 @@ class Course extends Model {
'level',
];

public function courseCode(): Attribute {
return Attribute::make(
get: fn (mixed $value, array $attributes) => join('-', [
$attributes['subject'],
$attributes['catalog_number'],
]),
);
}

public function group() {
return $this->belongsTo(Group::class);
}

public function getSourceAttribute() {
// courses could be persisted locally or in the sis
// anything returned from our local database is considered 'local'
public function getSubject(): string {
return $this->subject;
}

public function getCatalogNumber(): string {
return $this->catalog_number;
}

public function getTitle(): string {
return $this->title;
}

public function getCourseCode(): string {
return $this->getSubject() . '-' . $this->getCatalogNumber();
}

public function getCourseType(): string {
return $this->type;
}

public function getCourseLevel(): string {
return $this->level;
}

public function getSource(): string {
return 'local';
}

public function getApiId(): string {
return $this->getCourseCode();
}

}
61 changes: 60 additions & 1 deletion app/CourseSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Contracts\CourseSectionInterface;

/**
* @mixin IdeHelperCourseSection
*/
class CourseSection extends Model {
class CourseSection extends Model implements CourseSectionInterface {
use HasFactory;

protected $fillable = [
Expand All @@ -32,4 +33,62 @@ public function group() {
public function enrollments() {
return $this->hasMany(Enrollment::class);
}

public function getApiId(): string {
return join('-',[
$this->getCourseApiId(),
$this->class_section,
$this->term_id
]);
}

public function getCourseApiId(): string
{
return $this->course_id; // "HIST-1001W"
}

public function getDBId(): int | null {
return $this->id;
}

public function getTermId(): int {
return $this->term_id;
}

public function getClassSection(): string {
return $this->class_section;
}

public function getCourse(): Course {
return $this->course;
}

public function getEnrollmentCap(): int {
return 0;
}

public function getEnrollmentTotal(): int {
return 0;
}

public function getWaitlistCap(): int {
return 0;
}

public function getWaitlistTotal(): int {
return 0;
}

public function isCancelled(): bool {
return $this->is_cancelled;
}

public function isPublished(): bool {
return $this->is_published;
}

public function getSource(): string {
return 'local';
}

}
73 changes: 73 additions & 0 deletions app/DTOs/SISCourseDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace App\DTOs;

use App\Contracts\CourseInterface;

class SISCourseDTO implements CourseInterface {

public string $SUBJECT;
public string $CATALOG_NUMBER;
public string $DESCRIPTION;
public string $COMPONENT_CLASS;
public string $ACADEMIC_CAREER;

/**
* create a new SISCourseDTO instance.
*
* @param object{
* SUBJECT: string,
* CATALOG_NUMBER: string,
* DESCRIPTION: string,
* COMPONENT_CLASS: string,
* ACADEMIC_CAREER: string,
* } $course An associative array with course data.
*/
public function __construct($course) {
$this->SUBJECT = $course->SUBJECT;
$this->CATALOG_NUMBER = $course->CATALOG_NUMBER;
$this->DESCRIPTION = $course->DESCRIPTION;
$this->COMPONENT_CLASS = $course->COMPONENT_CLASS ?? 'Unknown';
$this->ACADEMIC_CAREER = $course->ACADEMIC_CAREER;
}

public function getSubject(): string
{
return $this->SUBJECT;
}

public function getCatalogNumber(): string
{
return $this->CATALOG_NUMBER;
}

public function getTitle(): string
{
return $this->DESCRIPTION;
}

public function getCourseCode(): string
{
return $this->SUBJECT . '-' . $this->CATALOG_NUMBER;
}

public function getCourseType(): string
{
return $this->COMPONENT_CLASS;
}

public function getCourseLevel(): string
{
return $this->ACADEMIC_CAREER;
}

public function getSource(): string
{
return 'sis';
}

public function getApiId(): string
{
return $this->getCourseCode();
}
}
116 changes: 116 additions & 0 deletions app/DTOs/SISCourseSectionDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

namespace App\DTOs;

use App\Contracts\CourseInterface;
use App\Contracts\CourseSectionInterface;

class SISCourseSectionDTO implements CourseSectionInterface {
private SISCourseDTO $course;
private int $termId;
private string $classSection;
private int $enrollmentCap;
private int $enrollmentTotal;
private int $waitlistCap;
private int $waitlistTotal;
private bool $isCancelled;
private bool $isPublished;

/**
*
* @param object{
* id: int,
* TERM: int,
* INSTRUCTOR_EMPLID: int,
* ACADEMIC_ORG: int,
* SUBJECT: string,
* CLASS_SECTION: string,
* INSTRUCTOR_ROLE: string,
* CATALOG_NUMBER: string,
* CLASS_NUMBER: int,
* ACADEMIC_CAREER: string,
* DESCRIPTION: string,
* COMPONENT_CLASS: string,
* ENROLLMENT_CAP: int,
* ENROLLMENT_TOTAL: int,
* WAITLIST_CAP: int,
* WAITLIST_TOTAL: int,
* CANCELLED: int,
* ENROLLMENTS: array
* } $rawClassData - The raw class data from the SIS
* @return void
*/
public function __construct($rawClassData) {
$this->course = new SISCourseDTO($rawClassData);
$this->termId = $rawClassData->TERM;
$this->classSection = $rawClassData->CLASS_SECTION;
$this->enrollmentCap = $rawClassData->ENROLLMENT_CAP;
$this->enrollmentTotal = $rawClassData->ENROLLMENT_TOTAL;
$this->waitlistCap = $rawClassData->WAITLIST_CAP;
$this->waitlistTotal = $rawClassData->WAITLIST_TOTAL;
$this->isCancelled = $rawClassData->CANCELLED === 1;
$this->isPublished = true;
}

public function getApiId(): string {
return join('-',[
$this->course->getApiId(),
$this->classSection,
$this->termId
]);
}

public function getDBId(): int | null {
// not stored in the local db
return null;
}

public function getTermId(): int {
return $this->termId;
}

public function getClassSection(): string
{
return $this->classSection;
}

public function getEnrollmentCap(): int
{
return $this->enrollmentCap;
}

public function getEnrollmentTotal(): int
{
return $this->enrollmentTotal;
}

public function getWaitlistCap(): int
{
return $this->waitlistCap;
}

public function getWaitlistTotal(): int
{
return $this->waitlistTotal;
}

public function isCancelled(): bool
{
return $this->isCancelled;
}

public function isPublished(): bool
{
return $this->isPublished;
}

public function getCourseApiId(): string
{
return $this->course->getApiId();
}

public function getSource(): string
{
return 'sis';
}
}
Loading

0 comments on commit 57d4f8c

Please sign in to comment.