MDL-37523 theme_mymobile: Removed a renderer from mymobile/renderers.php and added...
[moodle.git] / theme / mymobile / renderers / mod_choice_renderer.php
1 <?php
3 include_once ($CFG->dirroot. '/mod/choice/renderer.php');
5 class theme_mymobile_mod_choice_renderer extends mod_choice_renderer {
7     /**
8      * Returns HTML to display choices of option
9      * @param object $options
10      * @param int  $coursemoduleid
11      * @param bool $vertical
12      * @return string
13      */
14     public function display_options($options, $coursemoduleid, $vertical = false) {
15         $layoutclass = 'horizontal';
16         if ($vertical) {
17             $layoutclass = 'vertical';
18         }
19         $target = new moodle_url('/mod/choice/view.php');
20         //changed below to post from target john
21         $attributes = array('method'=>'POST', 'action'=>$target, 'class'=> $layoutclass);
23         $html = html_writer::start_tag('form', $attributes);
24         $html .= html_writer::start_tag('ul', array('class'=>'choices', 'data-role'=>'controlgroup' ));
26         $availableoption = count($options['options']);
27         foreach ($options['options'] as $option) {
28             $html .= html_writer::start_tag('li', array('class'=>'option'));
29             $option->attributes->name = 'answer';
30             $option->attributes->type = 'radio';
31             $option->attributes->id = 'answer'.html_writer::random_id();
33             $labeltext = $option->text;
34             if (!empty($option->attributes->disabled)) {
35                 $labeltext .= ' ' . get_string('full', 'choice');
36                 $availableoption--;
37             }
39             $html .= html_writer::empty_tag('input', (array)$option->attributes);
40             $html .= html_writer::tag('label', $labeltext, array('for'=>$option->attributes->id));
41             $html .= html_writer::end_tag('li');
42         }
43         $html .= html_writer::tag('li','', array('class'=>'clearfloat'));
44         $html .= html_writer::end_tag('ul');
45         $html .= html_writer::tag('div', '', array('class'=>'clearfloat'));
46         $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
47         $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=>$coursemoduleid));
49         if (!empty($options['hascapability']) && ($options['hascapability'])) {
50             if ($availableoption < 1) {
51                $html .= html_writer::tag('label', get_string('choicefull', 'choice'));
52             } else {
53                 $html .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('savemychoice','choice'), 'class'=>'button'));
54             }
56             if (!empty($options['allowupdate']) && ($options['allowupdate'])) {
57                 $url = new moodle_url('view.php', array('id'=>$coursemoduleid, 'action'=>'delchoice', 'sesskey'=>sesskey()));
58                 $html .= html_writer::link($url, get_string('removemychoice','choice'));
59             }
60         } else {
61             $html .= html_writer::tag('label', get_string('havetologin', 'choice'));
62         }
64         $html .= html_writer::end_tag('ul');
65         $html .= html_writer::end_tag('form');
67         return $html;
68     }
70     /**
71      * Returns HTML to display choices result
72      *
73      * TODO: There are differences between this method and the mod choice renderers function.
74      *       This needs to be checked VERY careful as the minor changes look like they
75      *       may lead to regressions.
76      *
77      * @param object $choices
78      * @param bool $forcepublish
79      * @return string
80      */
81     public function display_publish_name_vertical($choices) {
82         $html ='';
83         $html .= html_writer::tag('h2',format_string(get_string("responses", "choice")), array('class'=>'main'));
85         $attributes = array('method'=>'POST');
86         $attributes['action'] = new moodle_url('/mod/choice/view.php');
87         $attributes['id'] = 'attemptsform';
89         if ($choices->viewresponsecapability) {
90             $html .= html_writer::start_tag('form', $attributes);
91             $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=> $choices->coursemoduleid));
92             $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey()));
93             $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode', 'value'=>'overview'));
94         }
96         $table = new html_table();
97         $table->cellpadding = 0;
98         $table->cellspacing = 0;
99         $table->attributes['class'] = 'results names ';
100         $table->tablealign = 'center';
101         $table->data = array();
103         $count = 0;
104         ksort($choices->options);
106         $columns = array();
107         foreach ($choices->options as $optionid => $options) {
108             $coldata = '';
109             if ($choices->showunanswered && $optionid == 0) {
110                 $coldata .= html_writer::tag('div', format_string(get_string('notanswered', 'choice')), array('class'=>'option'));
111             } else if ($optionid > 0) {
112                 $coldata .= html_writer::tag('div', format_string($choices->options[$optionid]->text), array('class'=>'option'));
113             }
114             $numberofuser = 0;
115             if (!empty($options->user) && count($options->user) > 0) {
116                 $numberofuser = count($options->user);
117             }
119             $coldata .= html_writer::tag('div', ' ('.$numberofuser. ')', array('class'=>'numberofuser', 'title' => get_string('numberofuser', 'choice')));
120             $columns[] = $coldata;
121         }
123         $table->head = $columns;
125         $coldata = '';
126         $columns = array();
127         foreach ($choices->options as $optionid => $options) {
128             $coldata = '';
129             if ($choices->showunanswered || $optionid > 0) {
130                 if (!empty($options->user)) {
131                     foreach ($options->user as $user) {
132                         $data = '';
133                         if (empty($user->imagealt)){
134                             $user->imagealt = '';
135                         }
137                         if ($choices->viewresponsecapability && $choices->deleterepsonsecapability  && $optionid > 0) {
138                             $attemptaction = html_writer::checkbox('attemptid[]', $user->id,'');
139                             $data .= html_writer::tag('div', $attemptaction, array('class'=>'attemptaction'));
140                         }
141                         $userimage = $this->output->user_picture($user, array('courseid'=>$choices->courseid));
142                         $data .= html_writer::tag('div', $userimage, array('class'=>'image'));
144                         $userlink = new moodle_url('/user/view.php', array('id'=>$user->id,'course'=>$choices->courseid));
145                         $name = html_writer::tag('a', fullname($user, $choices->fullnamecapability), array('href'=>$userlink, 'class'=>'username'));
146                         $data .= html_writer::tag('div', $name, array('class'=>'fullname'));
147                         $data .= html_writer::tag('div','', array('class'=>'clearfloat'));
148                         $coldata .= html_writer::tag('div', $data, array('class'=>'user'));
149                     }
150                 }
151             }
153             $columns[] = $coldata;
154             $count++;
155         }
157         $table->data[] = $columns;
158         foreach ($columns as $d) {
159             $table->colclasses[] = 'data';
160         }
161         $html .= html_writer::tag('div', html_writer::table($table), array('class'=>'response'));
163         $actiondata = '';
164         if ($choices->viewresponsecapability && $choices->deleterepsonsecapability) {
165             $selecturl = new moodle_url('#');
167             $selectallactions = new component_action('click',"select_all_in", array('div',null,'tablecontainer'));
168             $selectall = new action_link($selecturl, get_string('selectall'), $selectallactions);
169             $actiondata .= $this->output->render($selectall) . ' / ';
171             $deselectallactions = new component_action('click',"deselect_all_in", array('div',null,'tablecontainer'));
172             $deselectall = new action_link($selecturl, get_string('deselectall'), $deselectallactions);
173             $actiondata .= $this->output->render($deselectall);
174             //below john fixed
175             $actiondata .= html_writer::tag('label', ' ' . get_string('withselected', 'choice') . ' ', array('for'=>'menuaction'));
177             $actionurl = new moodle_url('/mod/choice/view.php', array('sesskey'=>sesskey(), 'action'=>'delete_confirmation()'));
178             $select = new single_select($actionurl, 'action', array('delete'=>get_string('delete')), null, array(''=>get_string('moveselectedusersto', 'choice')), 'attemptsform');
180             $actiondata .= $this->output->render($select);
181         }
182         $html .= html_writer::tag('div', $actiondata, array('class'=>'responseaction'));
184         if ($choices->viewresponsecapability) {
185             $html .= html_writer::end_tag('form');
186         }
188         return $html;
189     }