|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 defined('MOODLE_INTERNAL') || die(); 00028 00032 class workshopallocation_manual_renderer extends mod_workshop_renderer { 00033 00035 // External rendering API 00037 00044 protected function render_workshopallocation_manual_allocations(workshopallocation_manual_allocations $data) { 00045 $allocations = $data->allocations; // array prepared array of all allocations data 00046 $userinfo = $data->userinfo; // names and pictures of all required users 00047 $authors = $data->authors; // array potential reviewees 00048 $reviewers = $data->reviewers; // array potential submission reviewers 00049 $hlauthorid = $data->hlauthorid; // int id of the author to highlight 00050 $hlreviewerid = $data->hlreviewerid; // int id of the reviewer to highlight 00051 $selfassessment = $data->selfassessment; // bool is the self-assessment allowed in this workshop? 00052 00053 if (empty($allocations)) { 00054 return ''; 00055 } 00056 00057 // convert user collections into drop down menus 00058 $authors = array_map('fullname', $authors); 00059 $reviewers = array_map('fullname', $reviewers); 00060 00061 $table = new html_table(); 00062 $table->attributes['class'] = 'allocations'; 00063 $table->head = array(get_string('participantreviewedby', 'workshop'), 00064 get_string('participant', 'workshop'), 00065 get_string('participantrevierof', 'workshop')); 00066 $table->rowclasses = array(); 00067 $table->colclasses = array('reviewedby', 'peer', 'reviewerof'); 00068 $table->data = array(); 00069 foreach ($allocations as $allocation) { 00070 $row = array(); 00071 $row[] = $this->helper_reviewers_of_participant($allocation, $userinfo, $reviewers, $selfassessment); 00072 $row[] = $this->helper_participant($allocation, $userinfo); 00073 $row[] = $this->helper_reviewees_of_participant($allocation, $userinfo, $authors, $selfassessment); 00074 $thisrowclasses = array(); 00075 if ($allocation->userid == $hlauthorid) { 00076 $thisrowclasses[] = 'highlightreviewedby'; 00077 } 00078 if ($allocation->userid == $hlreviewerid) { 00079 $thisrowclasses[] = 'highlightreviewerof'; 00080 } 00081 $table->rowclasses[] = implode(' ', $thisrowclasses); 00082 $table->data[] = $row; 00083 } 00084 00085 return $this->output->container(html_writer::table($table), 'manual-allocator'); 00086 } 00087 00089 // Internal helper methods 00091 00097 protected function helper_participant(stdclass $allocation, array $userinfo) { 00098 $o = $this->output->user_picture($userinfo[$allocation->userid], array('courseid' => $this->page->course->id)); 00099 $o .= fullname($userinfo[$allocation->userid]); 00100 $o .= $this->output->container_start(array('submission')); 00101 if (is_null($allocation->submissionid)) { 00102 $o .= $this->output->container(get_string('nosubmissionfound', 'workshop'), 'info'); 00103 } else { 00104 $o .= $this->output->container(format_string($allocation->submissiontitle), 'title'); 00105 if (is_null($allocation->submissiongrade)) { 00106 $o .= $this->output->container(get_string('nogradeyet', 'workshop'), array('grade', 'missing')); 00107 } else { 00108 $o .= $this->output->container(get_string('alreadygraded', 'workshop'), array('grade', 'missing')); 00109 } 00110 } 00111 $o .= $this->output->container_end(); 00112 return $o; 00113 } 00114 00120 protected function helper_reviewers_of_participant(stdclass $allocation, array $userinfo, array $reviewers, $selfassessment) { 00121 $o = ''; 00122 if (is_null($allocation->submissionid)) { 00123 $o .= $this->output->container(get_string('nothingtoreview', 'workshop'), 'info'); 00124 } else { 00125 $exclude = array(); 00126 if (! $selfassessment) { 00127 $exclude[$allocation->userid] = true; 00128 } 00129 // todo add an option to exclude users without own submission 00130 $options = array_diff_key($reviewers, $exclude); 00131 if ($options) { 00132 $handler = new moodle_url($this->page->url, array('mode' => 'new', 'of' => $allocation->userid, 'sesskey' => sesskey())); 00133 $select = new single_select($handler, 'by', $options, '', array(''=>get_string('chooseuser', 'workshop')), 'addreviewof' . $allocation->userid); 00134 $select->set_label(get_string('addreviewer', 'workshopallocation_manual')); 00135 $o .= $this->output->render($select); 00136 } 00137 } 00138 $o .= html_writer::start_tag('ul', array()); 00139 foreach ($allocation->reviewedby as $reviewerid => $assessmentid) { 00140 $o .= html_writer::start_tag('li', array()); 00141 $o .= $this->output->user_picture($userinfo[$reviewerid], array('courseid' => $this->page->course->id, 'size' => 16)); 00142 $o .= fullname($userinfo[$reviewerid]); 00143 00144 // delete icon 00145 $handler = new moodle_url($this->page->url, array('mode' => 'del', 'what' => $assessmentid, 'sesskey' => sesskey())); 00146 $o .= $this->helper_remove_allocation_icon($handler); 00147 00148 $o .= html_writer::end_tag('li'); 00149 } 00150 $o .= html_writer::end_tag('ul'); 00151 return $o; 00152 } 00153 00159 protected function helper_reviewees_of_participant(stdclass $allocation, array $userinfo, array $authors, $selfassessment) { 00160 $o = ''; 00161 if (is_null($allocation->submissionid)) { 00162 $o .= $this->output->container(get_string('withoutsubmission', 'workshop'), 'info'); 00163 } 00164 $exclude = array(); 00165 if (! $selfassessment) { 00166 $exclude[$allocation->userid] = true; 00167 $o .= $this->output->container(get_string('selfassessmentdisabled', 'workshop'), 'info'); 00168 } 00169 // todo add an option to exclude users without own submission 00170 $options = array_diff_key($authors, $exclude); 00171 if ($options) { 00172 $handler = new moodle_url($this->page->url, array('mode' => 'new', 'by' => $allocation->userid, 'sesskey' => sesskey())); 00173 $select = new single_select($handler, 'of', $options, '', array(''=>get_string('chooseuser', 'workshop')), 'addreviewby' . $allocation->userid); 00174 $select->set_label(get_string('addreviewee', 'workshopallocation_manual')); 00175 $o .= $this->output->render($select); 00176 } else { 00177 $o .= $this->output->container(get_string('nothingtoreview', 'workshop'), 'info'); 00178 } 00179 $o .= html_writer::start_tag('ul', array()); 00180 foreach ($allocation->reviewerof as $authorid => $assessmentid) { 00181 $o .= html_writer::start_tag('li', array()); 00182 $o .= $this->output->user_picture($userinfo[$authorid], array('courseid' => $this->page->course->id, 'size' => 16)); 00183 $o .= fullname($userinfo[$authorid]); 00184 00185 // delete icon 00186 $handler = new moodle_url($this->page->url, array('mode' => 'del', 'what' => $assessmentid, 'sesskey' => sesskey())); 00187 $o .= $this->helper_remove_allocation_icon($handler); 00188 00189 $o .= html_writer::end_tag('li'); 00190 } 00191 $o .= html_writer::end_tag('ul'); 00192 return $o; 00193 } 00194 00201 protected function helper_remove_allocation_icon($link) { 00202 return $this->output->action_icon($link, new pix_icon('t/delete', 'X')); 00203 } 00204 }