Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/workshop/renderer.php
Go to the documentation of this file.
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 
00035 class mod_workshop_renderer extends plugin_renderer_base {
00036 
00038     // External API - methods to render workshop renderable components
00040 
00047     protected function render_workshop_message(workshop_message $message) {
00048 
00049         $text   = $message->get_message();
00050         $url    = $message->get_action_url();
00051         $label  = $message->get_action_label();
00052 
00053         if (empty($text) and empty($label)) {
00054             return '';
00055         }
00056 
00057         switch ($message->get_type()) {
00058         case workshop_message::TYPE_OK:
00059             $sty = 'ok';
00060             break;
00061         case workshop_message::TYPE_ERROR:
00062             $sty = 'error';
00063             break;
00064         default:
00065             $sty = 'info';
00066         }
00067 
00068         $o = html_writer::tag('span', $message->get_message());
00069 
00070         if (!is_null($url) and !is_null($label)) {
00071             $o .= $this->output->single_button($url, $label, 'get');
00072         }
00073 
00074         return $this->output->container($o, array('message', $sty));
00075     }
00076 
00077 
00084     protected function render_workshop_submission(workshop_submission $submission) {
00085 
00086         $o  = '';    // output HTML code
00087         $anonymous = $submission->is_anonymous();
00088         $classes = 'submission-full';
00089         if ($anonymous) {
00090             $classes .= ' anonymous';
00091         }
00092         $o .= $this->output->container_start($classes);
00093         $o .= $this->output->container_start('header');
00094 
00095         $title = format_string($submission->title);
00096 
00097         if ($this->page->url != $submission->url) {
00098             $title = html_writer::link($submission->url, $title);
00099         }
00100 
00101         $o .= $this->output->heading($title, 3, 'title');
00102 
00103         if (!$anonymous) {
00104             $author             = new stdclass();
00105             $author->id         = $submission->authorid;
00106             $author->firstname  = $submission->authorfirstname;
00107             $author->lastname   = $submission->authorlastname;
00108             $author->picture    = $submission->authorpicture;
00109             $author->imagealt   = $submission->authorimagealt;
00110             $author->email      = $submission->authoremail;
00111             $userpic            = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 64));
00112             $userurl            = new moodle_url('/user/view.php',
00113                                             array('id' => $author->id, 'course' => $this->page->course->id));
00114             $a                  = new stdclass();
00115             $a->name            = fullname($author);
00116             $a->url             = $userurl->out();
00117             $byfullname         = get_string('byfullname', 'workshop', $a);
00118             $oo  = $this->output->container($userpic, 'picture');
00119             $oo .= $this->output->container($byfullname, 'fullname');
00120 
00121             $o .= $this->output->container($oo, 'author');
00122         }
00123 
00124         $created = get_string('userdatecreated', 'workshop', userdate($submission->timecreated));
00125         $o .= $this->output->container($created, 'userdate created');
00126 
00127         if ($submission->timemodified > $submission->timecreated) {
00128             $modified = get_string('userdatemodified', 'workshop', userdate($submission->timemodified));
00129             $o .= $this->output->container($modified, 'userdate modified');
00130         }
00131 
00132         $o .= $this->output->container_end(); // end of header
00133 
00134         $content = format_text($submission->content, $submission->contentformat, array('overflowdiv'=>true));
00135         $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $this->page->context->id,
00136                                                         'mod_workshop', 'submission_content', $submission->id);
00137         $o .= $this->output->container($content, 'content');
00138 
00139         $o .= $this->helper_submission_attachments($submission->id, 'html');
00140 
00141         $o .= $this->output->container_end(); // end of submission-full
00142 
00143         return $o;
00144     }
00145 
00152     protected function render_workshop_submission_summary(workshop_submission_summary $summary) {
00153 
00154         $o  = '';    // output HTML code
00155         $anonymous = $summary->is_anonymous();
00156         $classes = 'submission-summary';
00157 
00158         if ($anonymous) {
00159             $classes .= ' anonymous';
00160         }
00161 
00162         $gradestatus = '';
00163 
00164         if ($summary->status == 'notgraded') {
00165             $classes    .= ' notgraded';
00166             $gradestatus = $this->output->container(get_string('nogradeyet', 'workshop'), 'grade-status');
00167 
00168         } else if ($summary->status == 'graded') {
00169             $classes    .= ' graded';
00170             $gradestatus = $this->output->container(get_string('alreadygraded', 'workshop'), 'grade-status');
00171         }
00172 
00173         $o .= $this->output->container_start($classes);  // main wrapper
00174         $o .= html_writer::link($summary->url, format_string($summary->title), array('class' => 'title'));
00175 
00176         if (!$anonymous) {
00177             $author             = new stdClass();
00178             $author->id         = $summary->authorid;
00179             $author->firstname  = $summary->authorfirstname;
00180             $author->lastname   = $summary->authorlastname;
00181             $author->picture    = $summary->authorpicture;
00182             $author->imagealt   = $summary->authorimagealt;
00183             $author->email      = $summary->authoremail;
00184             $userpic            = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 35));
00185             $userurl            = new moodle_url('/user/view.php',
00186                                             array('id' => $author->id, 'course' => $this->page->course->id));
00187             $a                  = new stdClass();
00188             $a->name            = fullname($author);
00189             $a->url             = $userurl->out();
00190             $byfullname         = get_string('byfullname', 'workshop', $a);
00191 
00192             $oo  = $this->output->container($userpic, 'picture');
00193             $oo .= $this->output->container($byfullname, 'fullname');
00194             $o  .= $this->output->container($oo, 'author');
00195         }
00196 
00197         $created = get_string('userdatecreated', 'workshop', userdate($summary->timecreated));
00198         $o .= $this->output->container($created, 'userdate created');
00199 
00200         if ($summary->timemodified > $summary->timecreated) {
00201             $modified = get_string('userdatemodified', 'workshop', userdate($summary->timemodified));
00202             $o .= $this->output->container($modified, 'userdate modified');
00203         }
00204 
00205         $o .= $gradestatus;
00206         $o .= $this->output->container_end(); // end of the main wrapper
00207         return $o;
00208     }
00209 
00216     protected function render_workshop_example_submission(workshop_example_submission $example) {
00217 
00218         $o  = '';    // output HTML code
00219         $classes = 'submission-full example';
00220         $o .= $this->output->container_start($classes);
00221         $o .= $this->output->container_start('header');
00222         $o .= $this->output->heading(format_string($example->title), 3, 'title');
00223         $o .= $this->output->container_end(); // end of header
00224 
00225         $content = format_text($example->content, $example->contentformat, array('overflowdiv'=>true));
00226         $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $this->page->context->id,
00227                                                         'mod_workshop', 'submission_content', $example->id);
00228         $o .= $this->output->container($content, 'content');
00229 
00230         $o .= $this->helper_submission_attachments($example->id, 'html');
00231 
00232         $o .= $this->output->container_end(); // end of submission-full
00233 
00234         return $o;
00235     }
00236 
00243     protected function render_workshop_example_submission_summary(workshop_example_submission_summary $summary) {
00244 
00245         $o  = '';    // output HTML code
00246 
00247         // wrapping box
00248         $o .= $this->output->box_start('generalbox example-summary ' . $summary->status);
00249 
00250         // title
00251         $o .= $this->output->container_start('example-title');
00252         $o .= html_writer::link($summary->url, format_string($summary->title), array('class' => 'title'));
00253 
00254         if ($summary->editable) {
00255             $o .= $this->output->action_icon($summary->editurl, new pix_icon('i/edit', get_string('edit')));
00256         }
00257         $o .= $this->output->container_end();
00258 
00259         // additional info
00260         if ($summary->status == 'notgraded') {
00261             $o .= $this->output->container(get_string('nogradeyet', 'workshop'), 'example-info nograde');
00262         } else {
00263             $o .= $this->output->container(get_string('gradeinfo', 'workshop' , $summary->gradeinfo), 'example-info grade');
00264         }
00265 
00266         // button to assess
00267         $button = new single_button($summary->assessurl, $summary->assesslabel, 'get');
00268         $o .= $this->output->container($this->output->render($button), 'example-actions');
00269 
00270         // end of wrapping box
00271         $o .= $this->output->box_end();
00272 
00273         return $o;
00274     }
00275 
00282     protected function render_workshop_user_plan(workshop_user_plan $plan) {
00283         $table = new html_table();
00284         $table->attributes['class'] = 'userplan';
00285         $table->head = array();
00286         $table->colclasses = array();
00287         $row = new html_table_row();
00288         $row->attributes['class'] = 'phasetasks';
00289         foreach ($plan->phases as $phasecode => $phase) {
00290             $title = html_writer::tag('span', $phase->title);
00291             $actions = '';
00292             foreach ($phase->actions as $action) {
00293                 switch ($action->type) {
00294                 case 'switchphase':
00295                     $actions .= $this->output->action_icon($action->url, new pix_icon('i/marker', get_string('switchphase', 'workshop')));
00296                     break;
00297                 }
00298             }
00299             if (!empty($actions)) {
00300                 $actions = $this->output->container($actions, 'actions');
00301             }
00302             $table->head[] = $this->output->container($title . $actions);
00303             $classes = 'phase' . $phasecode;
00304             if ($phase->active) {
00305                 $classes .= ' active';
00306             } else {
00307                 $classes .= ' nonactive';
00308             }
00309             $table->colclasses[] = $classes;
00310             $cell = new html_table_cell();
00311             $cell->text = $this->helper_user_plan_tasks($phase->tasks);
00312             $row->cells[] = $cell;
00313         }
00314         $table->data = array($row);
00315 
00316         return html_writer::table($table);
00317     }
00318 
00325     protected function render_workshop_allocation_init_result(workshop_allocation_init_result $result) {
00326 
00327         // start with the message
00328         $o = $this->render($result->get_message());
00329 
00330         // display the details about the process if available
00331         $info = $result->get_info();
00332         if (is_array($info) and !empty($info)) {
00333             $o .= html_writer::start_tag('ul', array('class' => 'allocation-init-results'));
00334             foreach ($info as $message) {
00335                 $parts  = explode('::', $message);
00336                 $text   = array_pop($parts);
00337                 $class  = implode(' ', $parts);
00338                 if (in_array('debug', $parts) && !debugging('', DEBUG_DEVELOPER)) {
00339                     // do not display allocation debugging messages
00340                     continue;
00341                 }
00342                 $o .= html_writer::tag('li', $text, array('class' => $class)) . "\n";
00343             }
00344             $o .= html_writer::end_tag('ul');
00345         }
00346 
00347         $o .= $this->output->continue_button($result->get_continue_url());
00348 
00349         return $o;
00350     }
00351 
00358     protected function render_workshop_grading_report(workshop_grading_report $gradingreport) {
00359 
00360         $data       = $gradingreport->get_data();
00361         $options    = $gradingreport->get_options();
00362         $grades     = $data->grades;
00363         $userinfo   = $data->userinfo;
00364 
00365         if (empty($grades)) {
00366             return '';
00367         }
00368 
00369         $table = new html_table();
00370         $table->attributes['class'] = 'grading-report';
00371 
00372         $sortbyfirstname = $this->helper_sortable_heading(get_string('firstname'), 'firstname', $options->sortby, $options->sorthow);
00373         $sortbylastname = $this->helper_sortable_heading(get_string('lastname'), 'lastname', $options->sortby, $options->sorthow);
00374         if (self::fullname_format() == 'lf') {
00375             $sortbyname = $sortbylastname . ' / ' . $sortbyfirstname;
00376         } else {
00377             $sortbyname = $sortbyfirstname . ' / ' . $sortbylastname;
00378         }
00379 
00380         $table->head = array();
00381         $table->head[] = $sortbyname;
00382         $table->head[] = $this->helper_sortable_heading(get_string('submission', 'workshop'), 'submissiontitle',
00383                 $options->sortby, $options->sorthow);
00384         $table->head[] = $this->helper_sortable_heading(get_string('receivedgrades', 'workshop'));
00385         if ($options->showsubmissiongrade) {
00386             $table->head[] = $this->helper_sortable_heading(get_string('submissiongradeof', 'workshop', $data->maxgrade),
00387                     'submissiongrade', $options->sortby, $options->sorthow);
00388         }
00389         $table->head[] = $this->helper_sortable_heading(get_string('givengrades', 'workshop'));
00390         if ($options->showgradinggrade) {
00391             $table->head[] = $this->helper_sortable_heading(get_string('gradinggradeof', 'workshop', $data->maxgradinggrade),
00392                     'gradinggrade', $options->sortby, $options->sorthow);
00393         }
00394 
00395         $table->rowclasses  = array();
00396         $table->colclasses  = array();
00397         $table->data        = array();
00398 
00399         foreach ($grades as $participant) {
00400             $numofreceived  = count($participant->reviewedby);
00401             $numofgiven     = count($participant->reviewerof);
00402             $published      = $participant->submissionpublished;
00403 
00404             // compute the number of <tr> table rows needed to display this participant
00405             if ($numofreceived > 0 and $numofgiven > 0) {
00406                 $numoftrs       = workshop::lcm($numofreceived, $numofgiven);
00407                 $spanreceived   = $numoftrs / $numofreceived;
00408                 $spangiven      = $numoftrs / $numofgiven;
00409             } elseif ($numofreceived == 0 and $numofgiven > 0) {
00410                 $numoftrs       = $numofgiven;
00411                 $spanreceived   = $numoftrs;
00412                 $spangiven      = $numoftrs / $numofgiven;
00413             } elseif ($numofreceived > 0 and $numofgiven == 0) {
00414                 $numoftrs       = $numofreceived;
00415                 $spanreceived   = $numoftrs / $numofreceived;
00416                 $spangiven      = $numoftrs;
00417             } else {
00418                 $numoftrs       = 1;
00419                 $spanreceived   = 1;
00420                 $spangiven      = 1;
00421             }
00422 
00423             for ($tr = 0; $tr < $numoftrs; $tr++) {
00424                 $row = new html_table_row();
00425                 if ($published) {
00426                     $row->attributes['class'] = 'published';
00427                 }
00428                 // column #1 - participant - spans over all rows
00429                 if ($tr == 0) {
00430                     $cell = new html_table_cell();
00431                     $cell->text = $this->helper_grading_report_participant($participant, $userinfo);
00432                     $cell->rowspan = $numoftrs;
00433                     $cell->attributes['class'] = 'participant';
00434                     $row->cells[] = $cell;
00435                 }
00436                 // column #2 - submission - spans over all rows
00437                 if ($tr == 0) {
00438                     $cell = new html_table_cell();
00439                     $cell->text = $this->helper_grading_report_submission($participant);
00440                     $cell->rowspan = $numoftrs;
00441                     $cell->attributes['class'] = 'submission';
00442                     $row->cells[] = $cell;
00443                 }
00444                 // column #3 - received grades
00445                 if ($tr % $spanreceived == 0) {
00446                     $idx = intval($tr / $spanreceived);
00447                     $assessment = self::array_nth($participant->reviewedby, $idx);
00448                     $cell = new html_table_cell();
00449                     $cell->text = $this->helper_grading_report_assessment($assessment, $options->showreviewernames, $userinfo,
00450                             get_string('gradereceivedfrom', 'workshop'));
00451                     $cell->rowspan = $spanreceived;
00452                     $cell->attributes['class'] = 'receivedgrade';
00453                     if (is_null($assessment) or is_null($assessment->grade)) {
00454                         $cell->attributes['class'] .= ' null';
00455                     } else {
00456                         $cell->attributes['class'] .= ' notnull';
00457                     }
00458                     $row->cells[] = $cell;
00459                 }
00460                 // column #4 - total grade for submission
00461                 if ($options->showsubmissiongrade and $tr == 0) {
00462                     $cell = new html_table_cell();
00463                     $cell->text = $this->helper_grading_report_grade($participant->submissiongrade, $participant->submissiongradeover);
00464                     $cell->rowspan = $numoftrs;
00465                     $cell->attributes['class'] = 'submissiongrade';
00466                     $row->cells[] = $cell;
00467                 }
00468                 // column #5 - given grades
00469                 if ($tr % $spangiven == 0) {
00470                     $idx = intval($tr / $spangiven);
00471                     $assessment = self::array_nth($participant->reviewerof, $idx);
00472                     $cell = new html_table_cell();
00473                     $cell->text = $this->helper_grading_report_assessment($assessment, $options->showauthornames, $userinfo,
00474                             get_string('gradegivento', 'workshop'));
00475                     $cell->rowspan = $spangiven;
00476                     $cell->attributes['class'] = 'givengrade';
00477                     if (is_null($assessment) or is_null($assessment->grade)) {
00478                         $cell->attributes['class'] .= ' null';
00479                     } else {
00480                         $cell->attributes['class'] .= ' notnull';
00481                     }
00482                     $row->cells[] = $cell;
00483                 }
00484                 // column #6 - total grade for assessment
00485                 if ($options->showgradinggrade and $tr == 0) {
00486                     $cell = new html_table_cell();
00487                     $cell->text = $this->helper_grading_report_grade($participant->gradinggrade);
00488                     $cell->rowspan = $numoftrs;
00489                     $cell->attributes['class'] = 'gradinggrade';
00490                     $row->cells[] = $cell;
00491                 }
00492 
00493                 $table->data[] = $row;
00494             }
00495         }
00496 
00497         return html_writer::table($table);
00498     }
00499 
00506     protected function render_workshop_feedback_author(workshop_feedback_author $feedback) {
00507         return $this->helper_render_feedback($feedback);
00508     }
00509 
00516     protected function render_workshop_feedback_reviewer(workshop_feedback_reviewer $feedback) {
00517         return $this->helper_render_feedback($feedback);
00518     }
00519 
00526     private function helper_render_feedback($feedback) {
00527 
00528         $o  = '';    // output HTML code
00529         $o .= $this->output->container_start('feedback feedbackforauthor');
00530         $o .= $this->output->container_start('header');
00531         $o .= $this->output->heading(get_string('feedbackby', 'workshop', s(fullname($feedback->get_provider()))), 3, 'title');
00532 
00533         $userpic = $this->output->user_picture($feedback->get_provider(), array('courseid' => $this->page->course->id, 'size' => 32));
00534         $o .= $this->output->container($userpic, 'picture');
00535         $o .= $this->output->container_end(); // end of header
00536 
00537         $content = format_text($feedback->get_content(), $feedback->get_format(), array('overflowdiv' => true));
00538         $o .= $this->output->container($content, 'content');
00539 
00540         $o .= $this->output->container_end();
00541 
00542         return $o;
00543     }
00544 
00551     protected function render_workshop_assessment(workshop_assessment $assessment) {
00552 
00553         $o = ''; // output HTML code
00554         $anonymous = is_null($assessment->reviewer);
00555         $classes = 'assessment-full';
00556         if ($anonymous) {
00557             $classes .= ' anonymous';
00558         }
00559 
00560         $o .= $this->output->container_start($classes);
00561         $o .= $this->output->container_start('header');
00562 
00563         if (!empty($assessment->title)) {
00564             $title = s($assessment->title);
00565         } else {
00566             $title = get_string('assessment', 'workshop');
00567         }
00568         if (($assessment->url instanceof moodle_url) and ($this->page->url != $assessment->url)) {
00569             $o .= $this->output->container(html_writer::link($assessment->url, $title), 'title');
00570         } else {
00571             $o .= $this->output->container($title, 'title');
00572         }
00573 
00574         if (!$anonymous) {
00575             $reviewer   = $assessment->reviewer;
00576             $userpic    = $this->output->user_picture($reviewer, array('courseid' => $this->page->course->id, 'size' => 32));
00577 
00578             $userurl    = new moodle_url('/user/view.php',
00579                                        array('id' => $reviewer->id, 'course' => $this->page->course->id));
00580             $a          = new stdClass();
00581             $a->name    = fullname($reviewer);
00582             $a->url     = $userurl->out();
00583             $byfullname = get_string('assessmentby', 'workshop', $a);
00584             $oo         = $this->output->container($userpic, 'picture');
00585             $oo        .= $this->output->container($byfullname, 'fullname');
00586 
00587             $o .= $this->output->container($oo, 'reviewer');
00588         }
00589 
00590         if (is_null($assessment->realgrade)) {
00591             $o .= $this->output->container(
00592                 get_string('notassessed', 'workshop'),
00593                 'grade nograde'
00594             );
00595         } else {
00596             $a              = new stdClass();
00597             $a->max         = $assessment->maxgrade;
00598             $a->received    = $assessment->realgrade;
00599             $o .= $this->output->container(
00600                 get_string('gradeinfo', 'workshop', $a),
00601                 'grade'
00602             );
00603 
00604             if (!is_null($assessment->weight) and $assessment->weight != 1) {
00605                 $o .= $this->output->container(
00606                     get_string('weightinfo', 'workshop', $assessment->weight),
00607                     'weight'
00608                 );
00609             }
00610         }
00611 
00612         $o .= $this->output->container_start('actions');
00613         foreach ($assessment->actions as $action) {
00614             $o .= $this->output->single_button($action->url, $action->label, $action->method);
00615         }
00616         $o .= $this->output->container_end(); // actions
00617 
00618         $o .= $this->output->container_end(); // header
00619 
00620         if (!is_null($assessment->form)) {
00621             $o .= print_collapsible_region_start('assessment-form-wrapper', uniqid('workshop-assessment'),
00622                     get_string('assessmentform', 'workshop'), '', false, true);
00623             $o .= $this->output->container(self::moodleform($assessment->form), 'assessment-form');
00624             $o .= print_collapsible_region_end(true);
00625         }
00626 
00627         $o .= $this->output->container_end(); // main wrapper
00628 
00629         return $o;
00630     }
00631 
00638     protected function render_workshop_example_assessment(workshop_example_assessment $assessment) {
00639         return $this->render_workshop_assessment($assessment);
00640     }
00641 
00648     protected function render_workshop_example_reference_assessment(workshop_example_reference_assessment $assessment) {
00649         return $this->render_workshop_assessment($assessment);
00650     }
00651 
00653     // Internal rendering helper methods
00655 
00666     protected function helper_submission_attachments($submissionid, $format = 'html') {
00667         global $CFG;
00668         require_once($CFG->libdir.'/filelib.php');
00669 
00670         $fs     = get_file_storage();
00671         $ctx    = $this->page->context;
00672         $files  = $fs->get_area_files($ctx->id, 'mod_workshop', 'submission_attachment', $submissionid);
00673 
00674         $outputimgs     = '';   // images to be displayed inline
00675         $outputfiles    = '';   // list of attachment files
00676 
00677         foreach ($files as $file) {
00678             if ($file->is_directory()) {
00679                 continue;
00680             }
00681 
00682             $filepath   = $file->get_filepath();
00683             $filename   = $file->get_filename();
00684             $fileurl    = file_encode_url($CFG->wwwroot . '/pluginfile.php',
00685                                 '/' . $ctx->id . '/mod_workshop/submission_attachment/' . $submissionid . $filepath . $filename, true);
00686             $type       = $file->get_mimetype();
00687             $type       = mimeinfo_from_type('type', $type);
00688             $image      = html_writer::empty_tag('img', array('src'=>$this->output->pix_url(file_mimetype_icon($type)), 'alt'=>$type, 'class'=>'icon'));
00689 
00690             $linkhtml   = html_writer::link($fileurl, $image) . substr($filepath, 1) . html_writer::link($fileurl, $filename);
00691             $linktxt    = "$filename [$fileurl]";
00692 
00693             if ($format == 'html') {
00694                 if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
00695                     $preview     = html_writer::empty_tag('img', array('src' => $fileurl, 'alt' => '', 'class' => 'preview'));
00696                     $preview     = html_writer::tag('a', $preview, array('href' => $fileurl));
00697                     $outputimgs .= $this->output->container($preview);
00698 
00699                 } else {
00700                     $outputfiles .= html_writer::tag('li', $linkhtml, array('class' => $type));
00701                 }
00702 
00703             } else if ($format == 'text') {
00704                 $outputfiles .= $linktxt . PHP_EOL;
00705             }
00706         }
00707 
00708         if ($format == 'html') {
00709             if ($outputimgs) {
00710                 $outputimgs = $this->output->container($outputimgs, 'images');
00711             }
00712 
00713             if ($outputfiles) {
00714                 $outputfiles = html_writer::tag('ul', $outputfiles, array('class' => 'files'));
00715             }
00716 
00717             return $this->output->container($outputimgs . $outputfiles, 'attachments');
00718 
00719         } else {
00720             return $outputfiles;
00721         }
00722     }
00723 
00730     protected function helper_user_plan_tasks(array $tasks) {
00731         $out = '';
00732         foreach ($tasks as $taskcode => $task) {
00733             $classes = '';
00734             $icon = null;
00735             if ($task->completed === true) {
00736                 $classes .= ' completed';
00737             } elseif ($task->completed === false) {
00738                 $classes .= ' fail';
00739             } elseif ($task->completed === 'info') {
00740                 $classes .= ' info';
00741             }
00742             if (is_null($task->link)) {
00743                 $title = $task->title;
00744             } else {
00745                 $title = html_writer::link($task->link, $task->title);
00746             }
00747             $title = $this->output->container($title, 'title');
00748             $details = $this->output->container($task->details, 'details');
00749             $out .= html_writer::tag('li', $title . $details, array('class' => $classes));
00750         }
00751         if ($out) {
00752             $out = html_writer::tag('ul', $out, array('class' => 'tasks'));
00753         }
00754         return $out;
00755     }
00756 
00769     protected function helper_sortable_heading($text, $sortid=null, $sortby=null, $sorthow=null) {
00770         global $PAGE;
00771 
00772         $out = html_writer::tag('span', $text, array('class'=>'text'));
00773 
00774         if (!is_null($sortid)) {
00775             if ($sortby !== $sortid or $sorthow !== 'ASC') {
00776                 $url = new moodle_url($PAGE->url);
00777                 $url->params(array('sortby' => $sortid, 'sorthow' => 'ASC'));
00778                 $out .= $this->output->action_icon($url, new pix_icon('t/up', get_string('sortasc', 'workshop')), null, array('class' => 'sort asc'));
00779             }
00780             if ($sortby !== $sortid or $sorthow !== 'DESC') {
00781                 $url = new moodle_url($PAGE->url);
00782                 $url->params(array('sortby' => $sortid, 'sorthow' => 'DESC'));
00783                 $out .= $this->output->action_icon($url, new pix_icon('t/down', get_string('sortdesc', 'workshop')), null, array('class' => 'sort desc'));
00784             }
00785         }
00786         return $out;
00787 }
00788 
00794     protected function helper_grading_report_participant(stdclass $participant, array $userinfo) {
00795         $userid = $participant->userid;
00796         $out  = $this->output->user_picture($userinfo[$userid], array('courseid' => $this->page->course->id, 'size' => 35));
00797         $out .= html_writer::tag('span', fullname($userinfo[$userid]));
00798 
00799         return $out;
00800     }
00801 
00806     protected function helper_grading_report_submission(stdclass $participant) {
00807         global $CFG;
00808 
00809         if (is_null($participant->submissionid)) {
00810             $out = $this->output->container(get_string('nosubmissionfound', 'workshop'), 'info');
00811         } else {
00812             $url = new moodle_url('/mod/workshop/submission.php',
00813                                   array('cmid' => $this->page->context->instanceid, 'id' => $participant->submissionid));
00814             $out = html_writer::link($url, format_string($participant->submissiontitle), array('class'=>'title'));
00815         }
00816 
00817         return $out;
00818     }
00819 
00827     protected function helper_grading_report_assessment($assessment, $shownames, array $userinfo, $separator) {
00828         global $CFG;
00829 
00830         if (is_null($assessment)) {
00831             return get_string('nullgrade', 'workshop');
00832         }
00833         $a = new stdclass();
00834         $a->grade = is_null($assessment->grade) ? get_string('nullgrade', 'workshop') : $assessment->grade;
00835         $a->gradinggrade = is_null($assessment->gradinggrade) ? get_string('nullgrade', 'workshop') : $assessment->gradinggrade;
00836         $a->weight = $assessment->weight;
00837         // grrr the following logic should really be handled by a future language pack feature
00838         if (is_null($assessment->gradinggradeover)) {
00839             if ($a->weight == 1) {
00840                 $grade = get_string('formatpeergrade', 'workshop', $a);
00841             } else {
00842                 $grade = get_string('formatpeergradeweighted', 'workshop', $a);
00843             }
00844         } else {
00845             $a->gradinggradeover = $assessment->gradinggradeover;
00846             if ($a->weight == 1) {
00847                 $grade = get_string('formatpeergradeover', 'workshop', $a);
00848             } else {
00849                 $grade = get_string('formatpeergradeoverweighted', 'workshop', $a);
00850             }
00851         }
00852         $url = new moodle_url('/mod/workshop/assessment.php',
00853                               array('asid' => $assessment->assessmentid));
00854         $grade = html_writer::link($url, $grade, array('class'=>'grade'));
00855 
00856         if ($shownames) {
00857             $userid = $assessment->userid;
00858             $name   = $this->output->user_picture($userinfo[$userid], array('courseid' => $this->page->course->id, 'size' => 16));
00859             $name  .= html_writer::tag('span', fullname($userinfo[$userid]), array('class' => 'fullname'));
00860             $name   = $separator . html_writer::tag('span', $name, array('class' => 'user'));
00861         } else {
00862             $name   = '';
00863         }
00864 
00865         return $this->output->container($grade . $name, 'assessmentdetails');
00866     }
00867 
00871     protected function helper_grading_report_grade($grade, $over=null) {
00872         $a = new stdclass();
00873         $a->grade = is_null($grade) ? get_string('nullgrade', 'workshop') : $grade;
00874         if (is_null($over)) {
00875             $text = get_string('formataggregatedgrade', 'workshop', $a);
00876         } else {
00877             $a->over = is_null($over) ? get_string('nullgrade', 'workshop') : $over;
00878             $text = get_string('formataggregatedgradeover', 'workshop', $a);
00879         }
00880         return $text;
00881     }
00882 
00884     // Static helpers
00886 
00893     protected static function moodleform(moodleform $mform) {
00894 
00895         ob_start();
00896         $mform->display();
00897         $o = ob_get_contents();
00898         ob_end_clean();
00899 
00900         return $o;
00901     }
00902 
00910     protected static function array_nth(array $a, $n) {
00911         $keys = array_keys($a);
00912         if ($n < 0 or $n > count($keys) - 1) {
00913             return null;
00914         }
00915         $key = $keys[$n];
00916         return $a[$key];
00917     }
00918 
00924     protected static function fullname_format() {
00925         $fake = new stdclass(); // fake user
00926         $fake->lastname = 'LLLL';
00927         $fake->firstname = 'FFFF';
00928         $fullname = get_string('fullnamedisplay', '', $fake);
00929         if (strpos($fullname, 'LLLL') < strpos($fullname, 'FFFF')) {
00930             return 'lf';
00931         } else {
00932             return 'fl';
00933         }
00934     }
00935 }
 All Data Structures Namespaces Files Functions Variables Enumerations