Renders the full assessment

@param workshop_assessment $assessment
@return string HTML
180440
protected function render_workshop_assessment(workshop_assessment $assessment) {

        $o = ''; // output HTML code
        $anonymous = is_null($assessment->reviewer);
        $classes = 'assessment-full';
        if ($anonymous) {
            $classes .= ' anonymous';
        }

        $o .= $this->output->container_start($classes);
        $o .= $this->output->container_start('header');

        if (!empty($assessment->title)) {
            $title = s($assessment->title);
        } else {
            $title = get_string('assessment', 'workshop');
        }
        if (($assessment->url instanceof moodle_url) and ($this->page->url != $assessment->url)) {
            $o .= $this->output->container(html_writer::link($assessment->url, $title), 'title');
        } else {
            $o .= $this->output->container($title, 'title');
        }

        if (!$anonymous) {
            $reviewer   = $assessment->reviewer;
            $userpic    = $this->output->user_picture($reviewer, array('courseid' => $this->page->course->id, 'size' => 32));

            $userurl    = new moodle_url('/user/view.php',
                                       array('id' => $reviewer->id, 'course' => $this->page->course->id));
            $a          = new stdClass();
            $a->name    = fullname($reviewer);
            $a->url     = $userurl->out();
            $byfullname = get_string('assessmentby', 'workshop', $a);
            $oo         = $this->output->container($userpic, 'picture');
            $oo        .= $this->output->container($byfullname, 'fullname');

            $o .= $this->output->container($oo, 'reviewer');
        }

        if (is_null($assessment->realgrade)) {
            $o .= $this->output->container(
                get_string('notassessed', 'workshop'),
                'grade nograde'
            );
        } else {
            $a              = new stdClass();
            $a->max         = $assessment->maxgrade;
            $a->received    = $assessment->realgrade;
            $o .= $this->output->container(
                get_string('gradeinfo', 'workshop', $a),
                'grade'
            );

            if (!is_null($assessment->weight) and $assessment->weight != 1) {
                $o .= $this->output->container(
                    get_string('weightinfo', 'workshop', $assessment->weight),
                    'weight'
                );
            }
        }

        $o .= $this->output->container_start('actions');
        foreach ($assessment->actions as $action) {
            $o .= $this->output->single_button($action->url, $action->label, $action->method);
        }
        $o .= $this->output->container_end(); // actions

        $o .= $this->output->container_end(); // header

        if (!is_null($assessment->form)) {
            $o .= print_collapsible_region_start('assessment-form-wrapper', uniqid('workshop-assessment'),
                    get_string('assessmentform', 'workshop'), '', false, true);
            $o .= $this->output->container(self::moodleform($assessment->form), 'assessment-form');
            $o .= print_collapsible_region_end(true);

            if (!$assessment->form->is_editable()) {
                $o .= $this->overall_feedback($assessment);
            }
        }

        $o .= $this->output->container_end(); // main wrapper

        return $o;
    }
620611
public function render()
    {
        /** @var Grid $grid */
        $grid = $this->root;
        $this->isTotalsCalculationFinished = true;
        $tr = $grid->getRecordView();
        // set total_row as current grid row
        $lastRow = $grid->getCurrentRow();
        $grid->setCurrentRow($this->totalData);

        // modify columns, prepare it for rendering totals row
        $valueCalculators = [];
        $valueFormatters = [];
        foreach ($grid->getColumns() as $column) {
            $valueCalculators[$column->getId()] = $column->getValueCalculator();
            $valueFormatters[$column->getId()] = $prevFormatter = $column->getValueFormatter();
            $column->setValueCalculator(null);
            $column->setValueFormatter(function ($value) use ($prevFormatter, $column) {
                $operation = $this->getOperation($column->getId());
                if ($prevFormatter && !($operation === static::OPERATION_IGNORE || $operation instanceof Closure)) {
                    $value = call_user_func($prevFormatter, $value);
                }
                // Add value prefix if specified for operation
                if ($value !== null && is_string($operation) && array_key_exists($operation, $this->valuePrefixes)) {
                    $value = $this->valuePrefixes[$operation] . '&nbsp;' . $value;
                }
                return $value;
            });
        }

        $output = $tr->render();

        // restore column value calculators & formatters
        foreach ($grid->getColumns() as $column) {
            $column->setValueCalculator($valueCalculators[$column->getId()]);
            $column->setValueFormatter($valueFormatters[$column->getId()]);
        }
        // restore last data row
        $grid->setCurrentRow($lastRow);
        return $output;
    }
1018455
public function check_view_assessment($assessment, $submission) {
        global $USER;

        $isauthor = $submission->authorid == $USER->id;
        $isreviewer = $assessment->reviewerid == $USER->id;
        $canviewallassessments  = has_capability('mod/workshop:viewallassessments', $this->context);
        $canviewallsubmissions  = has_capability('mod/workshop:viewallsubmissions', $this->context);

        $canviewallsubmissions = $canviewallsubmissions && $this->check_group_membership($submission->authorid);

        if (!$isreviewer and !$isauthor and !($canviewallassessments and $canviewallsubmissions)) {
            print_error('nopermissions', 'error', $this->view_url(), 'view this assessment');
        }

        if ($isauthor and !$isreviewer and !$canviewallassessments and $this->phase != self::PHASE_CLOSED) {
            // Authors can see assessments of their work at the end of workshop only.
            print_error('nopermissions', 'error', $this->view_url(), 'view assessment of own work before workshop is closed');
        }
    }
1276097
public function render($part = 'content')
    {
        $return = '';
        switch ($part) {
            case 'content':
                $return = $this->renderContent();
                break;
            case 'filter':
                $return = $this->renderFilter();
                break;
            case 'summary':
                $return = $this->renderSummary();
                break;
            case 'header':
                $return = $this->renderHeader();
                break;
        }

        return $return;
    }
1127522
protected static function check_view_submission_assessments($submission, workshop $workshop) {
        global $USER;

        $ownsubmission = $submission->authorid == $USER->id;
        $canview = has_capability('mod/workshop:viewallassessments', $workshop->context) ||
            ($ownsubmission && $workshop->assessments_available());

        if ($canview) {
            // Here we should check if the user share group.
            if ($submission->authorid != $USER->id &&
                    !groups_user_groups_visible($workshop->course, $submission->authorid, $workshop->cm)) {
                throw new moodle_exception('notingroup');
            }
        } else {
            throw new moodle_exception('nopermissions', 'error', '', 'view assessment');
        }
    }
437545
protected function render_workshop_grading_report(workshop_grading_report $gradingreport) {

        $data       = $gradingreport->get_data();
        $options    = $gradingreport->get_options();
        $grades     = $data->grades;
        $userinfo   = $data->userinfo;

        if (empty($grades)) {
            return '';
        }

        $table = new html_table();
        $table->attributes['class'] = 'grading-report';

        $sortbyfirstname = $this->helper_sortable_heading(get_string('firstname'), 'firstname', $options->sortby, $options->sorthow);
        $sortbylastname = $this->helper_sortable_heading(get_string('lastname'), 'lastname', $options->sortby, $options->sorthow);
        if (self::fullname_format() == 'lf') {
            $sortbyname = $sortbylastname . ' / ' . $sortbyfirstname;
        } else {
            $sortbyname = $sortbyfirstname . ' / ' . $sortbylastname;
        }

        $sortbysubmisstiontitle = $this->helper_sortable_heading(get_string('submission', 'workshop'), 'submissiontitle',
                $options->sortby, $options->sorthow);
        $sortbysubmisstionlastmodified = $this->helper_sortable_heading(get_string('submissionlastmodified', 'workshop'),
                'submissionmodified', $options->sortby, $options->sorthow);
        $sortbysubmisstion = $sortbysubmisstiontitle . ' / ' . $sortbysubmisstionlastmodified;

        $table->head = array();
        $table->head[] = $sortbyname;
        $table->head[] = $sortbysubmisstion;

        // If we are in submission phase ignore the following headers (columns).
        if ($options->workshopphase != workshop::PHASE_SUBMISSION) {
            $table->head[] = $this->helper_sortable_heading(get_string('receivedgrades', 'workshop'));
            if ($options->showsubmissiongrade) {
                $table->head[] = $this->helper_sortable_heading(get_string('submissiongradeof', 'workshop', $data->maxgrade),
                        'submissiongrade', $options->sortby, $options->sorthow);
            }
            $table->head[] = $this->helper_sortable_heading(get_string('givengrades', 'workshop'));
            if ($options->showgradinggrade) {
                $table->head[] = $this->helper_sortable_heading(get_string('gradinggradeof', 'workshop', $data->maxgradinggrade),
                        'gradinggrade', $options->sortby, $options->sorthow);
            }
        }
        $table->rowclasses  = array();
        $table->colclasses  = array();
        $table->data        = array();

        foreach ($grades as $participant) {
            $numofreceived  = count($participant->reviewedby);
            $numofgiven     = count($participant->reviewerof);
            $published      = $participant->submissionpublished;

            // compute the number of <tr> table rows needed to display this participant
            if ($numofreceived > 0 and $numofgiven > 0) {
                $numoftrs       = workshop::lcm($numofreceived, $numofgiven);
                $spanreceived   = $numoftrs / $numofreceived;
                $spangiven      = $numoftrs / $numofgiven;
            } elseif ($numofreceived == 0 and $numofgiven > 0) {
                $numoftrs       = $numofgiven;
                $spanreceived   = $numoftrs;
                $spangiven      = $numoftrs / $numofgiven;
            } elseif ($numofreceived > 0 and $numofgiven == 0) {
                $numoftrs       = $numofreceived;
                $spanreceived   = $numoftrs / $numofreceived;
                $spangiven      = $numoftrs;
            } else {
                $numoftrs       = 1;
                $spanreceived   = 1;
                $spangiven      = 1;
            }

            for ($tr = 0; $tr < $numoftrs; $tr++) {
                $row = new html_table_row();
                if ($published) {
                    $row->attributes['class'] = 'published';
                }
                // column #1 - participant - spans over all rows
                if ($tr == 0) {
                    $cell = new html_table_cell();
                    $cell->text = $this->helper_grading_report_participant($participant, $userinfo);
                    $cell->rowspan = $numoftrs;
                    $cell->attributes['class'] = 'participant';
                    $row->cells[] = $cell;
                }
                // column #2 - submission - spans over all rows
                if ($tr == 0) {
                    $cell = new html_table_cell();
                    $cell->text = $this->helper_grading_report_submission($participant);
                    $cell->rowspan = $numoftrs;
                    $cell->attributes['class'] = 'submission';
                    $row->cells[] = $cell;
                }

                // If we are in submission phase ignore the following columns.
                if ($options->workshopphase == workshop::PHASE_SUBMISSION) {
                    $table->data[] = $row;
                    continue;
                }

                // column #3 - received grades
                if ($tr % $spanreceived == 0) {
                    $idx = intval($tr / $spanreceived);
                    $assessment = self::array_nth($participant->reviewedby, $idx);
                    $cell = new html_table_cell();
                    $cell->text = $this->helper_grading_report_assessment($assessment, $options->showreviewernames, $userinfo,
                            get_string('gradereceivedfrom', 'workshop'));
                    $cell->rowspan = $spanreceived;
                    $cell->attributes['class'] = 'receivedgrade';
                    if (is_null($assessment) or is_null($assessment->grade)) {
                        $cell->attributes['class'] .= ' null';
                    } else {
                        $cell->attributes['class'] .= ' notnull';
                    }
                    $row->cells[] = $cell;
                }
                // column #4 - total grade for submission
                if ($options->showsubmissiongrade and $tr == 0) {
                    $cell = new html_table_cell();
                    $cell->text = $this->helper_grading_report_grade($participant->submissiongrade, $participant->submissiongradeover);
                    $cell->rowspan = $numoftrs;
                    $cell->attributes['class'] = 'submissiongrade';
                    $row->cells[] = $cell;
                }
                // column #5 - given grades
                if ($tr % $spangiven == 0) {
                    $idx = intval($tr / $spangiven);
                    $assessment = self::array_nth($participant->reviewerof, $idx);
                    $cell = new html_table_cell();
                    $cell->text = $this->helper_grading_report_assessment($assessment, $options->showauthornames, $userinfo,
                            get_string('gradegivento', 'workshop'));
                    $cell->rowspan = $spangiven;
                    $cell->attributes['class'] = 'givengrade';
                    if (is_null($assessment) or is_null($assessment->grade)) {
                        $cell->attributes['class'] .= ' null';
                    } else {
                        $cell->attributes['class'] .= ' notnull';
                    }
                    $row->cells[] = $cell;
                }
                // column #6 - total grade for assessment
                if ($options->showgradinggrade and $tr == 0) {
                    $cell = new html_table_cell();
                    $cell->text = $this->helper_grading_report_grade($participant->gradinggrade);
                    $cell->rowspan = $numoftrs;
                    $cell->attributes['class'] = 'gradinggrade';
                    $row->cells[] = $cell;
                }

                $table->data[] = $row;
            }
        }

        return html_writer::table($table);
    }
25592
protected function filter_current_assessments(&$newallocations, $assessments) {
        foreach ($assessments as $assessment) {
            $allocation     = array($assessment->reviewerid => $assessment->authorid);
            $foundat        = array_keys($newallocations, $allocation);
            $newallocations = array_diff_key($newallocations, array_flip($foundat));
        }
    }
544241
public function persist(AssessmentTestSession $assessmentTestSession)
    {
        try {

            $stream = new MemoryStream();
            $stream->open();
            $access = $this->createBinaryStreamAccess($stream);

            // -- Deal with intrinsic values of the Test Session.
            $access->writeTinyInt($assessmentTestSession->getState());

            // Write the current position in the route.
            $route = $assessmentTestSession->getRoute();
            $access->writeTinyInt($route->getPosition());

            // persist time reference.
            $timeReference = $assessmentTestSession->getTimeReference();
            if (is_null($timeReference) === true) {
                $access->writeBoolean(false);
            } else {
                $access->writeBoolean(true);
                $access->writeDateTime($timeReference);
            }
            
            // persist visited testPart identifiers.
            $visitedTestPartIdentifiers = $assessmentTestSession->getVisitedTestPartIdentifiers();
            $access->writeTinyInt(count($visitedTestPartIdentifiers));
            foreach ($visitedTestPartIdentifiers as $visitedTestPartIdentifier) {
                $access->writeString($visitedTestPartIdentifier);
            }
            
            // persist path.
            $access->writePath($assessmentTestSession->getPath());
            
            // -- Persist configuration
            $access->writeShort($assessmentTestSession->getConfig());

            // -- Persist the Route of the AssessmentTestSession and the related item sessions.
            $access->writeTinyInt($route->count());
            $itemSessionStore = $assessmentTestSession->getAssessmentItemSessionStore();
            $pendingResponseStore = $assessmentTestSession->getPendingResponseStore();
            $oldRoutePosition = $route->getPosition();

            $seeker = $this->getSeeker();

            foreach ($route as $routeItem) {
                $item = $routeItem->getAssessmentItemRef();
                $occurence = $routeItem->getOccurence();

                // Deal with RouteItem
                $access->writeRouteItem($seeker, $routeItem);

                // Deal with ItemSession related to the previously written RouteItem.
                try {
                    $itemSession = $itemSessionStore->getAssessmentItemSession($item, $occurence);
                    $access->writeBoolean(true);
                    $access->writeAssessmentItemSession($seeker, $itemSession);
                    
                    // Deal with last occurence update.
                    $access->writeBoolean($assessmentTestSession->isLastOccurenceUpdate($item, $occurence));
                    
                    // Deal with PendingResponses
                    if (($pendingResponses = $pendingResponseStore->getPendingResponses($item, $occurence)) !== false) {
                        $access->writeBoolean(true);
                        $access->writePendingResponses($seeker, $pendingResponses);
                    } else {
                        $access->writeBoolean(false);
                    }
                }
                catch (OutOfBoundsException $e) {
                    $access->writeBoolean(false);
                    // No assessmentItemSession for this route item.
                    continue;
                }
            }
            
            $route->setPosition($oldRoutePosition);

            // Persist the test-level global scope.
            foreach ($assessmentTestSession->getKeys() as $outcomeIdentifier) {
                $outcomeVariable = $assessmentTestSession->getVariable($outcomeIdentifier);
                $access->writeVariableValue($outcomeVariable);
            }

            $durationStore = $assessmentTestSession->getDurationStore();
            $access->writeShort(count($durationStore));
            foreach ($durationStore->getKeys() as $k) {
                $access->writeString($k);
                $access->writeVariableValue($durationStore->getVariable($k));
            }

            $this->persistStream($assessmentTestSession, $stream);

            $stream->close();
        } catch (Exception $e) {
            $sessionId = $assessmentTestSession->getSessionId();
            $msg = "An error occured while persisting AssessmentTestSession with ID '${sessionId}': " . $e->getMessage();
            throw new StorageException($msg, StorageException::PERSISTENCE, $e);
        }
    }
468472
public function render(Configuration $configuration)
    {
        $output = '';

        foreach ($configuration->getSections() as $name => $section) {
            $output .= $this->renderSection($section);
        }

        return $output;
    }
1218047
public function render($aData)
    {
        $aData['num_options'] = static::NUM_OPTIONS;

        $oView = Factory::service('View');
        $sOut  = $oView->load('formbuilder/fields/open', $aData, true);
        $sOut  .= $oView->load('formbuilder/fields/body-scale', $aData, true);
        $sOut  .= $oView->load('formbuilder/fields/close', $aData, true);

        return $sOut;
    }
1209407
public static function get_submission_assessments($submissionid) {
        global $USER, $DB, $PAGE;

        $params = self::validate_parameters(self::get_submission_assessments_parameters(), array('submissionid' => $submissionid));
        $warnings = $assessments = array();

        // Get and validate the submission and workshop.
        $submission = $DB->get_record('workshop_submissions', array('id' => $params['submissionid']), '*', MUST_EXIST);
        list($workshop, $course, $cm, $context) = self::validate_workshop($submission->workshopid);

        // Check that we can get the assessments and get them.
        self::check_view_submission_assessments($submission, $workshop);
        $assessmentsrecords = $workshop->get_assessments_of_submission($submission->id);

        $related = array('context' => $context);
        foreach ($assessmentsrecords as $assessment) {
            $assessment = self::prepare_assessment_for_external($assessment, $workshop);
            if (empty($assessment)) {
                continue;
            }
            $exporter = new assessment_exporter($assessment, $related);
            $assessments[] = $exporter->export($PAGE->get_renderer('core'));
        }

        return array(
            'assessments' => $assessments,
            'warnings' => $warnings
        );
    }
1188168
def get_assessment(self, assessment):
        
        response = self.http.get('/Assessment/' + str(assessment))
        assessment = Schemas.Assessment(assessment=response)
        return assessment
81145
public function render()
    {
        // set response headers
        @Common::stripHeader('Pragma');
        @Common::stripHeader('Expires');
        @Common::sendHeader('Content-Type: text/html; charset=UTF-8');
        @Common::sendHeader('Cache-Control: must-revalidate');
        @Common::sendHeader('X-Frame-Options: deny');

        $error = htmlspecialchars($this->error, ENT_QUOTES, 'UTF-8');
        $messages = htmlspecialchars(serialize($this->feedbackMessages), ENT_QUOTES, 'UTF-8');
        $tokenAuth = $this->tokenAuth;
        $httpsFail = (int) $this->httpsFail;

        // use a heredoc instead of an external file
        echo <<<END_OF_TEMPLATE
<!DOCTYPE html>
<html>
 <head>
  <meta name="robots" content="noindex,nofollow">
  <meta charset="utf-8">
  <title></title>
 </head>
 <body>
  <form name="myform" method="post" action="?module=CoreUpdater&amp;action=oneClickResults">
   <input type="hidden" name="token_auth" value="$tokenAuth" />
   <input type="hidden" name="error" value="$error" />
   <input type="hidden" name="messages" value="$messages" />
   <input type="hidden" name="httpsFail" value="$httpsFail" />
   <noscript>
    <button type="submit">Continue</button>
   </noscript>
  </form>
  <script type="text/javascript">
   document.myform.submit();
  </script>
 </body>
</html>
END_OF_TEMPLATE;
    }
251283
public function panel(Panel\Panel\Panel $panel)
    {

        $html = '';

        //@todo Action render
        $actions = '';
        foreach($panel->getActions() as $action) {
            $actions .= $action->render() . PHP_EOL;
        }


        $html .= html('div', ['class' => 'pull-right'], $actions);
        $title = '<h4>' . $panel->getTitle() . '</h4>';
        $html .= html('div', ['class' => Style::PANEL_HEAD_CLASS_TITLE . ' clearfix'], $title);
        $html = html('div', ['class' => Style::PANEL_HEAD_CLASS], $html);


        //@todo footer render
        $html .= html('div', ['class' => Style::PANEL_BODY_CLASS], $panel->getBody());

        $panel->addClass(Style::PANEL_CLASS);

        if ($panel->hasContext()) {
            $panel->addClass(constant( Style::class . '::' . $panel->getContext()));
        }

        return html('div', $panel->getAttributes(), $html);
    }
469339
protected function renderSelect()
    {
        $options = $this->getOptions();

        $selectedExtensionStyle = '';

        $renderedOptionTags = [];
        foreach ($options as $option) {
            if (isset($option['selected']) && $option['selected'] === 'selected') {
                $selectedExtensionStyle = $option['style'];
            }
            if ($option['value'] === \Tx_Phpunit_Testable::ALL_EXTENSIONS) {
                $optionValue = $this->translate('all_extensions');
            } else {
                $optionValue = $option['value'];
            }
            $renderedOptionTags[] = $this->renderTag('option', $option, $optionValue);
        }

        return $this->renderTag(
            'select',
            [
                'name' => \Tx_Phpunit_Interface_Request::PARAMETER_NAMESPACE .
                    '[' . \Tx_Phpunit_Interface_Request::PARAMETER_KEY_TESTABLE . ']',
                'onchange' => 'document.location = \'' . $this->action . '&' .
                    \Tx_Phpunit_Interface_Request::PARAMETER_NAMESPACE .
                    '[' . \Tx_Phpunit_Interface_Request::PARAMETER_KEY_TESTABLE . ']=' .
                    '\'+this.options[this.selectedIndex].value;',
                'style' => $selectedExtensionStyle,
            ],
            implode(LF, $renderedOptionTags)
        );
    }
688229
public function render()
    {
        if (!$this->grid->showExportBtn()) {
            return '';
        }

        $this->setUpScripts();

        $trans = [
            'export'        => trans('admin.export'),
            'all'           => trans('admin.all'),
            'current_page'  => trans('admin.current_page'),
            'selected_rows' => trans('admin.selected_rows'),
        ];

        $page = request('page', 1);

        return <<<EOT

<div class="btn-group pull-right" style="margin-right: 10px">
    <a class="btn btn-sm btn-twitter" title="{$trans['export']}"><i class="fa fa-download"></i><span class="hidden-xs"> {$trans['export']}</span></a>
    <button type="button" class="btn btn-sm btn-twitter dropdown-toggle" data-toggle="dropdown">
        <span class="caret"></span>
        <span class="sr-only">Toggle Dropdown</span>
    </button>
    <ul class="dropdown-menu" role="menu">
        <li><a href="{$this->grid->getExportUrl('all')}" target="_blank">{$trans['all']}</a></li>
        <li><a href="{$this->grid->getExportUrl('page', $page)}" target="_blank">{$trans['current_page']}</a></li>
        <li><a href="{$this->grid->getExportUrl('selected', '__rows__')}" target="_blank" class='{$this->grid->getExportSelectedName()}'>{$trans['selected_rows']}</a></li>
    </ul>
</div>
EOT;
    }
1083943
public function ui() {
        global $PAGE, $DB;

        $output     = $PAGE->get_renderer('workshopallocation_manual');

        $page       = optional_param('page', 0, PARAM_INT);
        $perpage    = get_user_preferences('workshopallocation_manual_perpage', 10);
        $groupid    = groups_get_activity_group($this->workshop->cm, true);

        $hlauthorid     = -1;           // highlight this author
        $hlreviewerid   = -1;           // highlight this reviewer

        $message        = new workshop_message();

        $m  = optional_param('m', '', PARAM_ALPHANUMEXT);   // message code
        if ($m) {
            $m = explode('-', $m);
            switch ($m[0]) {
            case self::MSG_ADDED:
                $hlauthorid     = $m[1];
                $hlreviewerid   = $m[2];
                $message        = new workshop_message(get_string('allocationadded', 'workshopallocation_manual'),
                    workshop_message::TYPE_OK);
                break;
            case self::MSG_EXISTS:
                $hlauthorid     = $m[1];
                $hlreviewerid   = $m[2];
                $message        = new workshop_message(get_string('allocationexists', 'workshopallocation_manual'),
                    workshop_message::TYPE_INFO);
                break;
            case self::MSG_NOSUBMISSION:
                $hlauthorid     = $m[1];
                $message        = new workshop_message(get_string('nosubmissionfound', 'workshop'),
                    workshop_message::TYPE_ERROR);
                break;
            case self::MSG_CONFIRM_DEL:
                $hlauthorid     = $m[2];
                $hlreviewerid   = $m[3];
                if ($m[4] == 0) {
                    $message    = new workshop_message(get_string('areyousuretodeallocate', 'workshopallocation_manual'),
                        workshop_message::TYPE_INFO);
                } else {
                    $message    = new workshop_message(get_string('areyousuretodeallocategraded', 'workshopallocation_manual'),
                        workshop_message::TYPE_ERROR);
                }
                $url = new moodle_url($PAGE->url, array('mode' => 'del', 'what' => $m[1], 'confirm' => 1, 'sesskey' => sesskey()));
                $label = get_string('iamsure', 'workshop');
                $message->set_action($url, $label);
                break;
            case self::MSG_DELETED:
                $hlauthorid     = $m[1];
                $hlreviewerid   = $m[2];
                $message        = new workshop_message(get_string('assessmentdeleted', 'workshop'),
                    workshop_message::TYPE_OK);
                break;
            case self::MSG_DELETE_ERROR:
                $hlauthorid     = $m[1];
                $hlreviewerid   = $m[2];
                $message        = new workshop_message(get_string('assessmentnotdeleted', 'workshop'),
                    workshop_message::TYPE_ERROR);
                break;
            }
        }

        // fetch the list of ids of all workshop participants
        $numofparticipants = $this->workshop->count_participants(false, $groupid);
        $participants = $this->workshop->get_participants(false, $groupid, $perpage * $page, $perpage);

        if ($hlauthorid > 0 and $hlreviewerid > 0) {
            // display just those two users
            $participants = array_intersect_key($participants, array($hlauthorid => null, $hlreviewerid => null));
            $button = $output->single_button($PAGE->url, get_string('showallparticipants', 'workshopallocation_manual'), 'get');
        } else {
            $button = '';
        }

        // this will hold the information needed to display user names and pictures
        $userinfo = $participants;

        // load the participants' submissions
        $submissions = $this->workshop->get_submissions(array_keys($participants));
        $allnames = get_all_user_name_fields();
        foreach ($submissions as $submission) {
            if (!isset($userinfo[$submission->authorid])) {
                $userinfo[$submission->authorid]            = new stdclass();
                $userinfo[$submission->authorid]->id        = $submission->authorid;
                $userinfo[$submission->authorid]->picture   = $submission->authorpicture;
                $userinfo[$submission->authorid]->imagealt  = $submission->authorimagealt;
                $userinfo[$submission->authorid]->email     = $submission->authoremail;
                foreach ($allnames as $addname) {
                    $temp = 'author' . $addname;
                    $userinfo[$submission->authorid]->$addname = $submission->$temp;
                }
            }
        }

        // get current reviewers
        $reviewers = array();
        if ($submissions) {
            list($submissionids, $params) = $DB->get_in_or_equal(array_keys($submissions), SQL_PARAMS_NAMED);
            $picturefields = user_picture::fields('r', array(), 'reviewerid');
            $sql = "SELECT a.id AS assessmentid, a.submissionid, $picturefields,
                           s.id AS submissionid, s.authorid
                      FROM {workshop_assessments} a
                      JOIN {user} r ON (a.reviewerid = r.id)
                      JOIN {workshop_submissions} s ON (a.submissionid = s.id)
                     WHERE a.submissionid $submissionids";
            $reviewers = $DB->get_records_sql($sql, $params);
            foreach ($reviewers as $reviewer) {
                if (!isset($userinfo[$reviewer->reviewerid])) {
                    $userinfo[$reviewer->reviewerid]            = new stdclass();
                    $userinfo[$reviewer->reviewerid]->id        = $reviewer->reviewerid;
                    $userinfo[$reviewer->reviewerid]->picture   = $reviewer->picture;
                    $userinfo[$reviewer->reviewerid]->imagealt  = $reviewer->imagealt;
                    $userinfo[$reviewer->reviewerid]->email     = $reviewer->email;
                    foreach ($allnames as $addname) {
                        $userinfo[$reviewer->reviewerid]->$addname = $reviewer->$addname;
                    }
                }
            }
        }

        // get current reviewees
        $reviewees = array();
        if ($participants) {
            list($participantids, $params) = $DB->get_in_or_equal(array_keys($participants), SQL_PARAMS_NAMED);
            $namefields = get_all_user_name_fields(true, 'e');
            $params['workshopid'] = $this->workshop->id;
            $sql = "SELECT a.id AS assessmentid, a.submissionid,
                           u.id AS reviewerid,
                           s.id AS submissionid,
                           e.id AS revieweeid, e.lastname, e.firstname, $namefields, e.picture, e.imagealt, e.email
                      FROM {user} u
                      JOIN {workshop_assessments} a ON (a.reviewerid = u.id)
                      JOIN {workshop_submissions} s ON (a.submissionid = s.id)
                      JOIN {user} e ON (s.authorid = e.id)
                     WHERE u.id $participantids AND s.workshopid = :workshopid AND s.example = 0";
            $reviewees = $DB->get_records_sql($sql, $params);
            foreach ($reviewees as $reviewee) {
                if (!isset($userinfo[$reviewee->revieweeid])) {
                    $userinfo[$reviewee->revieweeid]            = new stdclass();
                    $userinfo[$reviewee->revieweeid]->id        = $reviewee->revieweeid;
                    $userinfo[$reviewee->revieweeid]->firstname = $reviewee->firstname;
                    $userinfo[$reviewee->revieweeid]->lastname  = $reviewee->lastname;
                    $userinfo[$reviewee->revieweeid]->picture   = $reviewee->picture;
                    $userinfo[$reviewee->revieweeid]->imagealt  = $reviewee->imagealt;
                    $userinfo[$reviewee->revieweeid]->email     = $reviewee->email;
                    foreach ($allnames as $addname) {
                        $userinfo[$reviewee->revieweeid]->$addname = $reviewee->$addname;
                    }
                }
            }
        }

        // the information about the allocations
        $allocations = array();

        foreach ($participants as $participant) {
            $allocations[$participant->id] = new stdClass();
            $allocations[$participant->id]->userid = $participant->id;
            $allocations[$participant->id]->submissionid = null;
            $allocations[$participant->id]->reviewedby = array();
            $allocations[$participant->id]->reviewerof = array();
        }
        unset($participants);

        foreach ($submissions as $submission) {
            $allocations[$submission->authorid]->submissionid = $submission->id;
            $allocations[$submission->authorid]->submissiontitle = $submission->title;
            $allocations[$submission->authorid]->submissiongrade = $submission->grade;
        }
        unset($submissions);
        foreach($reviewers as $reviewer) {
            $allocations[$reviewer->authorid]->reviewedby[$reviewer->reviewerid] = $reviewer->assessmentid;
        }
        unset($reviewers);
        foreach($reviewees as $reviewee) {
            $allocations[$reviewee->reviewerid]->reviewerof[$reviewee->revieweeid] = $reviewee->assessmentid;
        }
        unset($reviewees);

        // prepare data to be rendered
        $data                   = new workshopallocation_manual_allocations();
        $data->workshop         = $this->workshop;
        $data->allocations      = $allocations;
        $data->userinfo         = $userinfo;
        $data->authors          = $this->workshop->get_potential_authors();
        $data->reviewers        = $this->workshop->get_potential_reviewers();
        $data->hlauthorid       = $hlauthorid;
        $data->hlreviewerid     = $hlreviewerid;
        $data->selfassessment   = $this->workshop->useselfassessment;

        // prepare the group selector
        $groupselector = $output->container(groups_print_activity_menu($this->workshop->cm, $PAGE->url, true), 'groupwidget');

        // prepare paging bar
        $pagingbar              = new paging_bar($numofparticipants, $page, $perpage, $PAGE->url, 'page');
        $pagingbarout           = $output->render($pagingbar);
        $perpageselector        = $output->perpage_selector($perpage);

        return $groupselector . $pagingbarout . $output->render($message) . $output->render($data) . $button . $pagingbarout . $perpageselector;
    }