-
Notifications
You must be signed in to change notification settings - Fork 0
/
course_media.classes.inc
74 lines (62 loc) · 1.74 KB
/
course_media.classes.inc
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
64
65
66
67
68
69
70
71
72
73
74
<?php
class CourseObjectMedia extends CourseObject {
function take() {
parent::take();
$options = $this->getOptions();
// Get view mode
$view_mode = $options['media_view_mode'];
// Get file media view
$file = file_load($options['media']['fid']);
$view = file_view_file($file, $view_mode);
// Set Fulfillment when media is shown
$this->getFulfillment()->setComplete()->save();
return $view;
}
function getTakeType() {
return 'content';
}
/**
* Course media options.
*/
public function optionsDefinition() {
$options = parent::optionsDefinition();
// Media default value
$options['media'] = '';
$options['media_view_mode'] = 'media_original';
return $options;
}
/**
* Add options only for media
*/
public function optionsForm(&$form, &$form_state) {
parent::optionsForm($form, $form_state);
$defaults = $this->getOptions();
// Media view mode
// TODO get view modes from media module.
$form['media_form']['media_view_mode'] = array(
'#type' => 'select',
'#title' => t('View mode'),
'#options' => array(
'media_original'=> t('Original'),
'media_link' => t('Link'),
'media_preview' => t('Preview'),
'media_small'=> t('Small'),
'media_large'=> t('Large')
),
'#default_value' => $defaults['media_view_mode']
);
// Media form
$form['media_form']['media'] = array(
'#type' => 'media',
'#title' => 'Media',
'#description' => 'Select media for Course object',
'#tree' => true,
'#default_value' => $defaults['media'],
'#media_options' => array(
'global' => array(
'file_directory' => 'media',
),
)
);
}
}