Skip to content

Commit

Permalink
Merge pull request #2 from CraftQuest/feature/in-progress-courses
Browse files Browse the repository at this point in the history
added variable to get in progress courses
  • Loading branch information
ryanirelan authored Mar 20, 2021
2 parents 8f222a4 + 77aefde commit b36c66c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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
6 changes: 5 additions & 1 deletion src/variables/PlayTrackerVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public function getInProgressVideos($userId) {
return $result;
}

public function getInProgressCourses($userId, $limit) {
return PlayTracker::$plugin->playTrackerService->getInProgressCourses($userId, $limit);
}

/**
* Gets Current Timestamp
*
Expand All @@ -82,4 +86,4 @@ public function currentTimestamp($playdata) {
$result = PlayTracker::$plugin->playTrackerService->getCurrentTimestamp($playdata);
return $result;
}
}
}

0 comments on commit b36c66c

Please sign in to comment.