Skip to content

Commit

Permalink
added service method to support getting in progress courses
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanirelan authored Mar 19, 2021
1 parent 47f0852 commit 77aefde
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/services/PlayTrackerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Craft;
use craft\base\Component;
use craft\db\Query;
use craft\elements\Entry;


/**
Expand Down Expand Up @@ -135,6 +136,28 @@ public function getInProgressCourseVideosByEntryId($entryId, $userId) {
return $inProgressVideos;
}

public function getInProgressCourses($userId, $limit)
{
$inProgressCourses = (new Query())
->select(['{{%playtracker_playtrackerrecord}}.entryId'])
->distinct()
->from(['{{%playtracker_playtrackerrecord}}'])
->where(['{{%playtracker_playtrackerrecord}}.userId' => $userId])
->andWhere('{{%playtracker_playtrackerrecord}}.rowId != 0')
->limit($limit)
->all();

$entryIds = [];

foreach ($inProgressCourses as $course) {
$entryIds[] = $course['entryId'];
}

$entries = implode(", ", $entryIds);

return Entry::find()->section('courses')->id($entryIds)->all();
}

/**
* @param $playData
* @return bool
Expand Down

0 comments on commit 77aefde

Please sign in to comment.