aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/Courseware/UserProgressesHelper.php
blob: 04f80407c88906db200a142b0f402ea9de9bbf83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php

namespace JsonApi\Routes\Courseware;

use Courseware\Block;
use Courseware\UserProgress;
use JsonApi\Errors\RecordNotFoundException;

trait UserProgressesHelper
{
    private function findWithId(string $userProgressId)
    {
        list($userId, $blockId) = explode('_', $userProgressId);
        if (!($user = \User::find($userId)) || !($block = Block::find($blockId))) {
            throw new RecordNotFoundException();
        }

        return UserProgress::getUserProgress($user, $block);
    }
}