-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.php
111 lines (91 loc) · 3.83 KB
/
renderer.php
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
class block_superiframe_renderer extends plugin_renderer_base {
//Here we return all the content that the goes in the block
/**
* @param $block_id
*
* @return string
*/
public function fetch_block_content($block_id){
global $USER ,$DB;
$def_config = get_config('block_superiframe');
try {
$configdata = $DB->get_field('block_instances','configdata',array('id' => $block_id));
if($configdata){
$config = unserialize(base64_decode($configdata));
}
} catch (\Exception $e ) {
$config = $def_config;
}
$content = '';
$content .= '<br />' . get_string('welcomeuser','block_superiframe',$USER) . '<br/>';
$link = new moodle_url('/blocks/superiframe/view.php',array('blockid' => $block_id ));
$content .= html_writer::link( $link , get_string('gotosuperiframe', 'block_superiframe') , array('title' => $config->url ) ) ;
$content .= '<br/>(' . $config->url . ')';
return $content ;
}
//Here we aggregate all the pieces of content of the view page and displays them
/**
* @param $url
* @param $block_id
*
* @internal param $width
* @internal param $height
*/
public function display_view_page($url , $block_id ){
global $USER , $PAGE;
// get default block configuration
$def_config = get_config('block_superiframe');
// start output to browser
echo $this->output->header();
// check for capability to show user details
if(has_capability('block/superiframe:seeuserdetail' , $PAGE->context )){
// create a link to the user's list of entries in this glossary
$userpicture = $this->output->user_picture($USER, array('size'=>65));
$elementUrl = new moodle_url('/user/view.php', array('id' => $USER->id));
$elementLink = html_writer::link($elementUrl,$userpicture);
echo '<br/>' . fullname($USER);
echo '<br/>' . $elementLink;
}
// show the heading
echo $this->output->heading(get_string('pluginname', 'block_superiframe'),5);
echo '<br/>';
$sizes = array();
$sizes['custom'] = ['width' => $def_config->width , 'height' => $def_config->height ] ;
$sizes['small'] = ['width' => 300 , 'height' => 200 ] ;
$sizes['medium'] = ['width' => 600 , 'height' => 400 ] ;
$sizes['large'] = ['width' => 900 , 'height' => 600 ] ;
// get the parameter if exists
$size = optional_param('size','custom',PARAM_TEXT);
// check if the parameter is within the array of predefined parameter sets
if( ! array_key_exists( $size , $sizes ) ){
$size = 'custom';
}
//fetch the size of the iframe
$width = $sizes[$size]['width'];
$height = $sizes[$size]['height'];
echo $this->show_links( $sizes , $block_id );
$iframe_attr = array();
$iframe_attr['src'] = $url ;
$iframe_attr['width'] = $width ;
$iframe_attr['height'] = $height ;
$iframe_attr['class'] = 'block_superiframe_iframe' ;
$iframe = html_writer::tag('iframe','',$iframe_attr);
echo '<br/><br/>' . $iframe ;
// send footer out to browser
echo $this->output->footer();
}
/**
* @param $sizes
* @param $block_id
*
* @return string
*/
private function show_links(array $sizes , $block_id ){
$links = '';
foreach( $sizes as $key => $value){
$links[] = html_writer::link( new moodle_url('/blocks/superiframe/view.php',array( 'blockid' => $block_id ,'size' => $key)) , get_string('link_'.$key,'block_superiframe')) ;
}
return html_writer::div(implode(' ',$links),'block_superiframe_sizes');
}
}