aboutsummaryrefslogtreecommitdiff
path: root/lib/activities/CoursewareContext.php
blob: 66cd991b3954e4c0290423a7594958ab573bb343 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

namespace Studip\Activity;

class CoursewareContext extends Context
{
    protected $courseware;
    protected $context;
    protected $range_id;

    public function __construct($courseware, $observer)
    {
        $this->courseware = $courseware;
        $this->observer = $observer;

        $id = explode('_' , $this->courseware->id);
        $this->context = $id[0];
        $this->range_id = $id[1];
    }

    protected function getProvider()
    {
        $this->addProvider('Studip\Activity\CoursewareProvider');

        return $this->provider;
    }

    public function getRangeId()
    {
        return $this->range_id;
    }

    public function getContextType()
    {
        if ($this->context === 'user') {
            return \Context::USER;
        }

        if ($this->context === 'course') {
            return \Context::COURSE;
        }

        throw new \UnexpectedValueException("Unknown context type {$this->context}");
    }

    public function getContextFullname($format = 'default')
    {
        if ($this->context === 'user') {
            $user = \User::find($this->range_id);

            return $user->getFullName($format);
        }

        if ($this->context === 'course') {
            $course = \Course::find($this->range_id);

            return $course->getFullName($format);
        }

        throw new \UnexpectedValueException("Unknown context {$this->context}");
    }

}