diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index 8d36065667c..fd687c31e04 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -189,6 +189,11 @@ class workshop { */ protected $evaluationinstance = null; + /** + * @var array It gets initialised in init_initial_bar, and may have keys 'i_first' and 'i_last' depending on what is selected. + */ + protected $initialbarprefs = []; + /** * Initializes the workshop API instance using the data from DB * @@ -680,15 +685,24 @@ class workshop { global $DB; list($sql, $params) = $this->get_participants_sql($musthavesubmission, $groupid); + list($filteringsql, $filteringparams) = $this->get_users_with_initial_filtering_sql_where(); + $wheresql = ""; + if ($filteringsql) { + $wheresql .= $filteringsql; + $params = array_merge($params, $filteringparams); + } if (empty($sql)) { return array(); } list($sort, $sortparams) = users_order_by_sql('tmp'); - $sql = "SELECT * - FROM ($sql) tmp - ORDER BY $sort"; + $sql = "SELECT * FROM ($sql) tmp"; + + if ($wheresql) { + $sql .= " WHERE $wheresql"; + } + $sql .= " ORDER BY $sort"; return $DB->get_records_sql($sql, array_merge($params, $sortparams), $limitfrom, $limitnum); } @@ -3218,6 +3232,66 @@ class workshop { $DB->update_record('workshop_submissions', $record); } + /** + * Get the initial first name. + * + * @return string|null initial of first name we are currently filtering by. + */ + public function get_initial_first(): ?string { + if (empty($this->initialbarprefs['i_first'])) { + return null; + } + + return $this->initialbarprefs['i_first']; + } + + /** + * Get the initial last name. + * + * @return string|null initial of last name we are currently filtering by. + */ + public function get_initial_last(): ?string { + if (empty($this->initialbarprefs['i_last'])) { + return null; + } + + return $this->initialbarprefs['i_last']; + } + + /** + * Init method for initial bars. + * @return void + */ + public function init_initial_bar(): void { + global $SESSION; + if ($this->phase === self::PHASE_SETUP) { + return; + } + + $ifirst = optional_param('ifirst', null, PARAM_NOTAGS); + $ilast = optional_param('ilast', null, PARAM_NOTAGS); + + if (empty($SESSION->mod_workshop->initialbarprefs['id-'.$this->context->id])) { + $SESSION->mod_workshop = new stdClass(); + $SESSION->mod_workshop->initialbarprefs['id-'.$this->context->id] = []; + } + if (!empty($SESSION->mod_workshop->initialbarprefs['id-'.$this->context->id]['i_first'])) { + $this->initialbarprefs['i_first'] = $SESSION->mod_workshop->initialbarprefs['id-'.$this->context->id]['i_first']; + } + if (!empty($SESSION->mod_workshop->initialbarprefs['id-'.$this->context->id]['i_last'])) { + $this->initialbarprefs['i_last'] = $SESSION->mod_workshop->initialbarprefs['id-'.$this->context->id]['i_last']; + } + if (!is_null($ifirst)) { + $this->initialbarprefs['i_first'] = $ifirst; + $SESSION->mod_workshop->initialbarprefs['id-'.$this->context->id]['i_first'] = $ifirst; + } + + if (!is_null($ilast)) { + $this->initialbarprefs['i_last'] = $ilast; + $SESSION->mod_workshop->initialbarprefs['id-'.$this->context->id]['i_last'] = $ilast; + } + } + //////////////////////////////////////////////////////////////////////////////// // Internal methods (implementation details) // //////////////////////////////////////////////////////////////////////////////// @@ -3430,6 +3504,28 @@ class workshop { return array($sql, $params); } + /** + * Returns SQL to fetch all enrolled users with the first name or last name. + * + * @return array + */ + protected function get_users_with_initial_filtering_sql_where(): array { + global $DB; + $conditions = []; + $params = []; + $ifirst = $this->get_initial_first(); + $ilast = $this->get_initial_last(); + if ($ifirst) { + $conditions[] = $DB->sql_like('LOWER(tmp.firstname)', ':i_first' , false, false); + $params['i_first'] = $DB->sql_like_escape($ifirst) . '%'; + } + if ($ilast) { + $conditions[] = $DB->sql_like('LOWER(tmp.lastname)', ':i_last' , false, false); + $params['i_last'] = $DB->sql_like_escape($ilast) . '%'; + } + return [implode(" AND ", $conditions), $params]; + } + /** * Returns SQL statement that can be used to fetch all actively enrolled participants in the workshop * diff --git a/mod/workshop/renderer.php b/mod/workshop/renderer.php index 4fb20c070f2..aa43c1a4ca2 100644 --- a/mod/workshop/renderer.php +++ b/mod/workshop/renderer.php @@ -431,7 +431,7 @@ class mod_workshop_renderer extends plugin_renderer_base { $userinfo = $data->userinfo; if (empty($grades)) { - return ''; + return $this->output->notification(get_string('nothingtodisplay'), 'success', false); } $table = new html_table(); @@ -821,6 +821,22 @@ class mod_workshop_renderer extends plugin_renderer_base { return $this->output->container($this->output->render($select), 'perpagewidget'); } + /** + * Render the initials bars for workshop. + * + * @param workshop $workshop the current workshop of initial bars. + * @param moodle_url $url base URL object. + * @return string HTML. + */ + public function initials_bars(workshop $workshop, moodle_url $url): string { + $ifirst = $workshop->get_initial_first(); + $ilast = $workshop->get_initial_last(); + + $html = $this->output->initials_bar($ifirst, 'firstinitial', get_string('firstname'), 'ifirst', $url); + $html .= $this->output->initials_bar($ilast, 'lastinitial', get_string('lastname'), 'ilast', $url); + return $html; + } + /** * Renders the user's final grades * diff --git a/mod/workshop/tests/behat/workshop_activity_filter.feature b/mod/workshop/tests/behat/workshop_activity_filter.feature new file mode 100644 index 00000000000..eac488a3609 --- /dev/null +++ b/mod/workshop/tests/behat/workshop_activity_filter.feature @@ -0,0 +1,86 @@ +@mod @mod_workshop +Feature: View work shop activity submissions report. + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Vinnie | Money | student1@example.com | + | student2 | Anna | Velvet | student2@example.com | + | student3 | Anna | Moe | student3@example.com | + | teacher1 | Darrell | Teacher1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "course enrolments" exist: + | user | course | role | + | student1 | C1 | student | + | student2 | C1 | student | + | student3 | C1 | student | + | teacher1 | C1 | editingteacher | + And the following "activities" exist: + | activity | name | intro | course | + | workshop | Music history | Test workshop description | C1 | + + Scenario Outline: Filter submissions report by surname/first name + Given I am on the "Music history" "workshop activity" page logged in as teacher1 + When I change phase in workshop "Music history" to "" + Then ".firstinitial" "css_element" should exist + And ".lastinitial" "css_element" should exist + And "grading-report" "table" should exist + And I should see "Anna Moe" in the "grading-report" "table" + And I should see "Vinnie Money" in the "grading-report" "table" + And I should see "Anna Velvet" in the "grading-report" "table" + + Examples: + | phase | + | Submission phase | + | Assessment phase | + | Grading evaluation phase | + | Closed | + + Scenario: Filter submissions report by surname/first name is hidden in the Setup phase. + When I am on the "Music history" "workshop activity" page logged in as teacher1 + Then ".firstinitial" "css_element" should not exist + And ".lastinitial" "css_element" should not exist + And "grading-report" "table" should not exist + + Scenario: Filter submissions report by first name as a teacher. + Given I am on the "Music history" "workshop activity" page logged in as teacher1 + And I change phase in workshop "Music history" to "Submission phase" + When I click on "A" "link" in the ".firstinitial" "css_element" + Then I should see "Anna Moe" in the "grading-report" "table" + And I should see "Anna Velvet" in the "grading-report" "table" + And I should not see "Vinnie Money" in the "grading-report" "table" + + Scenario: Filter submissions report by surname name as a teacher. + Given I am on the "Music history" "workshop activity" page logged in as teacher1 + And I change phase in workshop "Music history" to "Submission phase" + When I click on "V" "link" in the ".lastinitial" "css_element" + Then I should see "Anna Velvet" in the "grading-report" "table" + And I should not see "Anna Moe" in the "grading-report" "table" + And I should not see "Vinnie Money" in the "grading-report" "table" + + Scenario: Filter submissions report by first name and surname as a teacher. + Given I am on the "Music history" "workshop activity" page logged in as teacher1 + And I change phase in workshop "Music history" to "Submission phase" + When I click on "V" "link" in the ".firstinitial" "css_element" + And I click on "M" "link" in the ".lastinitial" "css_element" + Then I should see "Vinnie Money" in the "grading-report" "table" + And I should not see "Anna Moe" in the "grading-report" "table" + And I should not see "Anna Velvet" in the "grading-report" "table" + + Scenario: Filter submissions report and see nothing. + Given I am on the "Music history" "workshop activity" page logged in as teacher1 + And I change phase in workshop "Music history" to "Submission phase" + When I click on "Z" "link" in the ".firstinitial" "css_element" + Then I should see "Nothing to display" + + Scenario: Filter submissions report using All by first name + Given I am on the "Music history" "workshop activity" page logged in as teacher1 + And I change phase in workshop "Music history" to "Submission phase" + When I click on "V" "link" in the ".firstinitial" "css_element" + And I click on "M" "link" in the ".lastinitial" "css_element" + And I click on "All" "link" in the ".firstinitial" "css_element" + Then I should see "Vinnie Money" in the "grading-report" "table" + And I should see "Anna Moe" in the "grading-report" "table" + And I should not see "Anna Velvet" in the "grading-report" "table" diff --git a/mod/workshop/tests/locallib_test.php b/mod/workshop/tests/locallib_test.php index 42cda0a853f..802163fcf58 100644 --- a/mod/workshop/tests/locallib_test.php +++ b/mod/workshop/tests/locallib_test.php @@ -778,4 +778,97 @@ class locallib_test extends \advanced_testcase { $this->assertTrue($workshop3->check_group_membership($student2->id)); $this->assertFalse($workshop3->check_group_membership($student3->id)); } + + /** + * Test init_initial_bar function. + * + * @covers \workshop::init_initial_bar + */ + public function test_init_initial_bar(): void { + global $SESSION; + $this->resetAfterTest(); + + $_GET['ifirst'] = 'A'; + $_GET['ilast'] = 'B'; + $contextid = $this->workshop->context->id; + + $this->workshop->init_initial_bar(); + $initialbarprefs = $this->get_initial_bar_prefs_property(); + + $this->assertEquals('A', $initialbarprefs['i_first']); + $this->assertEquals('B', $initialbarprefs['i_last']); + $this->assertEquals('A', $SESSION->mod_workshop->initialbarprefs['id-' . $contextid]['i_first']); + $this->assertEquals('B', $SESSION->mod_workshop->initialbarprefs['id-' . $contextid]['i_last']); + + $_GET['ifirst'] = null; + $_GET['ilast'] = null; + $SESSION->mod_workshop->initialbarprefs['id-' . $contextid]['i_first'] = 'D'; + $SESSION->mod_workshop->initialbarprefs['id-' . $contextid]['i_last'] = 'E'; + + $this->workshop->init_initial_bar(); + $initialbarprefs = $this->get_initial_bar_prefs_property(); + + $this->assertEquals('D', $initialbarprefs['i_first']); + $this->assertEquals('E', $initialbarprefs['i_last']); + } + + /** + * Test empty init_initial_bar + * + * @covers \workshop::init_initial_bar + */ + public function test_init_initial_bar_empty(): void { + $this->resetAfterTest(); + + $this->workshop->init_initial_bar(); + $initialbarprefs = $this->get_initial_bar_prefs_property(); + + $this->assertEmpty($initialbarprefs); + } + + /** + * Test get_initial_first function + * + * @covers \workshop::get_initial_first + */ + public function test_get_initial_first(): void { + $this->resetAfterTest(); + $this->workshop->init_initial_bar(); + $this->assertEquals(null, $this->workshop->get_initial_first()); + + $_GET['ifirst'] = 'D'; + $this->workshop->init_initial_bar(); + $this->assertEquals('D', $this->workshop->get_initial_first()); + } + + /** + * Test get_initial_last function + * + * @covers \workshop::get_initial_last + */ + public function test_get_initial_last(): void { + $this->resetAfterTest(); + $this->workshop->init_initial_bar(); + $this->assertEquals(null, $this->workshop->get_initial_last()); + + $_GET['ilast'] = 'D'; + $this->workshop->init_initial_bar(); + $this->assertEquals('D', $this->workshop->get_initial_last()); + } + + /** + * Get the protected propertyinitialbarprefs from workshop class. + * + * @coversNothing + * @return array initialbarspref property. eg ['i_first' => 'A', 'i_last' => 'B'] + */ + private function get_initial_bar_prefs_property(): array { + + $reflector = new \ReflectionObject($this->workshop); + $initialbarprefsprop = $reflector->getProperty('initialbarprefs'); + $initialbarprefsprop->setAccessible(true); + $initialbarprefs = $initialbarprefsprop->getValue($this->workshop); + + return $initialbarprefs; + } } diff --git a/mod/workshop/view.php b/mod/workshop/view.php index 149ce97ed6e..67b8bec38de 100644 --- a/mod/workshop/view.php +++ b/mod/workshop/view.php @@ -72,7 +72,7 @@ if ($workshop->phase == workshop::PHASE_SUBMISSION and $workshop->phaseswitchass if (!is_null($editmode) && $PAGE->user_allowed_editing()) { $USER->editing = $editmode; } - +$workshop->init_initial_bar(); $userplan = new workshop_user_plan($workshop, $USER->id); foreach ($userplan->phases as $phase) { @@ -162,537 +162,547 @@ echo $output->heading(format_string($currentphasetitle), 3, null, 'mod_workshop- echo $output->render($userplan); switch ($workshop->phase) { -case workshop::PHASE_SETUP: - if (trim($workshop->intro)) { - print_collapsible_region_start('', 'workshop-viewlet-intro', get_string('introduction', 'workshop'), + case workshop::PHASE_SETUP: + if (trim($workshop->intro)) { + print_collapsible_region_start('', 'workshop-viewlet-intro', get_string('introduction', 'workshop'), 'workshop-viewlet-intro-collapsed'); - echo $output->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox'); - print_collapsible_region_end(); - } - if ($workshop->useexamples and has_capability('mod/workshop:manageexamples', $PAGE->context)) { - print_collapsible_region_start('', 'workshop-viewlet-allexamples', get_string('examplesubmissions', 'workshop'), + echo $output->box(format_module_intro('workshop', $workshop, $workshop->cm->id), 'generalbox'); + print_collapsible_region_end(); + } + if ($workshop->useexamples && has_capability('mod/workshop:manageexamples', $PAGE->context)) { + print_collapsible_region_start('', 'workshop-viewlet-allexamples', get_string('examplesubmissions', 'workshop'), 'workshop-viewlet-allexamples-collapsed'); - echo $output->box_start('generalbox examples'); - if ($workshop->grading_strategy_instance()->form_ready()) { - if (! $examples = $workshop->get_examples_for_manager()) { - echo $output->container(get_string('noexamples', 'workshop'), 'noexamples'); + echo $output->box_start('generalbox examples'); + if ($workshop->grading_strategy_instance()->form_ready()) { + if (!$examples = $workshop->get_examples_for_manager()) { + echo $output->container(get_string('noexamples', 'workshop'), 'noexamples'); + } + foreach ($examples as $example) { + $summary = $workshop->prepare_example_summary($example); + $summary->editable = true; + echo $output->render($summary); + } + $aurl = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on')); + echo $output->single_button($aurl, get_string('exampleadd', 'workshop'), 'get'); + } else { + echo $output->container(get_string('noexamplesformready', 'workshop')); } - foreach ($examples as $example) { - $summary = $workshop->prepare_example_summary($example); - $summary->editable = true; - echo $output->render($summary); - } - $aurl = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on')); - echo $output->single_button($aurl, get_string('exampleadd', 'workshop'), 'get'); - } else { - echo $output->container(get_string('noexamplesformready', 'workshop')); - } - echo $output->box_end(); - print_collapsible_region_end(); - } - break; -case workshop::PHASE_SUBMISSION: - if (trim($workshop->instructauthors)) { - $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id, - 'mod_workshop', 'instructauthors', null, workshop::instruction_editors_options($PAGE->context)); - print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'), - 'workshop-viewlet-instructauthors-collapsed'); - echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv'=>true)), array('generalbox', 'instructions')); - print_collapsible_region_end(); - } - - if ($workshop->assessing_examples_allowed() - and has_capability('mod/workshop:submit', $workshop->context) - and ! has_capability('mod/workshop:manageexamples', $workshop->context)) { - $examples = $userplan->get_examples(); - $total = count($examples); - print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), - 'workshop-viewlet-examples-collapsed', $examplesdone); - echo $output->box_start('generalbox exampleassessments'); - if ($total == 0) { - echo $output->heading(get_string('noexamples', 'workshop'), 3); - } else { - foreach ($examples as $example) { - $summary = $workshop->prepare_example_summary($example); - echo $output->render($summary); - } - } - echo $output->box_end(); - print_collapsible_region_end(); - } - - if (has_capability('mod/workshop:submit', $PAGE->context) and (!$examplesmust or $examplesdone)) { - print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), - 'workshop-viewlet-ownsubmission-collapsed'); - echo $output->box_start('generalbox ownsubmission'); - if ($submission = $workshop->get_submission_by_author($USER->id)) { - echo $output->render($workshop->prepare_submission_summary($submission, true)); - } else { - echo $output->container(get_string('noyoursubmission', 'workshop')); - } - - echo $output->box_end(); - print_collapsible_region_end(); - } - - if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) { - $groupmode = groups_get_activity_groupmode($workshop->cm); - $groupid = groups_get_activity_group($workshop->cm, true); - - if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $workshop->context)) { - $allowedgroups = groups_get_activity_allowed_groups($workshop->cm); - if (empty($allowedgroups)) { - echo $output->container(get_string('groupnoallowed', 'mod_workshop'), 'groupwidget error'); - break; - } - if (! in_array($groupid, array_keys($allowedgroups))) { - echo $output->container(get_string('groupnotamember', 'core_group'), 'groupwidget error'); - break; - } - } - - print_collapsible_region_start('', 'workshop-viewlet-allsubmissions', get_string('submissionsreport', 'workshop'), - 'workshop-viewlet-allsubmissions-collapsed'); - - $perpage = get_user_preferences('workshop_perpage', 10); - $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow); - if ($data) { - $countparticipants = $workshop->count_participants(); - $countsubmissions = $workshop->count_submissions(array_keys($data->grades), $groupid); - $a = new stdClass(); - $a->submitted = $countsubmissions; - $a->notsubmitted = $data->totalcount - $countsubmissions; - - echo html_writer::tag('div', get_string('submittednotsubmitted', 'workshop', $a)); - - echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget'); - - // Prepare the paging bar. - $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow)); - $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page'); - - // Populate the display options for the submissions report. - $reportopts = new stdclass(); - $reportopts->showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context); - $reportopts->showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context); - $reportopts->sortby = $sortby; - $reportopts->sorthow = $sorthow; - $reportopts->showsubmissiongrade = false; - $reportopts->showgradinggrade = false; - $reportopts->workshopphase = $workshop->phase; - - echo $output->render($pagingbar); - echo $output->render(new workshop_grading_report($data, $reportopts)); - echo $output->render($pagingbar); - echo $output->perpage_selector($perpage); - } else { - echo html_writer::tag('div', get_string('nothingfound', 'workshop'), array('class' => 'nothingfound')); - } - print_collapsible_region_end(); - } - break; - -case workshop::PHASE_ASSESSMENT: - - $ownsubmissionexists = null; - if (has_capability('mod/workshop:submit', $PAGE->context)) { - if ($ownsubmission = $workshop->get_submission_by_author($USER->id)) { - print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), - 'workshop-viewlet-ownsubmission-collapsed', true); - echo $output->box_start('generalbox ownsubmission'); - echo $output->render($workshop->prepare_submission_summary($ownsubmission, true)); - $ownsubmissionexists = true; - } else { - print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), - 'workshop-viewlet-ownsubmission-collapsed'); - echo $output->box_start('generalbox ownsubmission'); - echo $output->container(get_string('noyoursubmission', 'workshop')); - $ownsubmissionexists = false; - } - - echo $output->box_end(); - print_collapsible_region_end(); - } - - if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) { - $perpage = get_user_preferences('workshop_perpage', 10); - $groupid = groups_get_activity_group($workshop->cm, true); - $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow); - if ($data) { - $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context); - $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context); - - // prepare paging bar - $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow)); - $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page'); - - // grading report display options - $reportopts = new stdclass(); - $reportopts->showauthornames = $showauthornames; - $reportopts->showreviewernames = $showreviewernames; - $reportopts->sortby = $sortby; - $reportopts->sorthow = $sorthow; - $reportopts->showsubmissiongrade = false; - $reportopts->showgradinggrade = false; - $reportopts->workshopphase = $workshop->phase; - - print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'), - 'workshop-viewlet-gradereport-collapsed'); - echo $output->box_start('generalbox gradesreport'); - echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget'); - echo $output->render($pagingbar); - echo $output->render(new workshop_grading_report($data, $reportopts)); - echo $output->render($pagingbar); - echo $output->perpage_selector($perpage); echo $output->box_end(); print_collapsible_region_end(); } - } - if (trim($workshop->instructreviewers)) { - $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id, - 'mod_workshop', 'instructreviewers', null, workshop::instruction_editors_options($PAGE->context)); - print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'), - 'workshop-viewlet-instructreviewers-collapsed'); - echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions')); - print_collapsible_region_end(); - } - - // does the user have to assess examples before assessing other's work? - $examplesmust = ($workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_ASSESSMENT); - - // is the assessment of example submissions considered finished? - $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context); - - // can the examples be assessed? - $examplesavailable = true; - - if (!$examplesdone and $examplesmust and ($ownsubmissionexists === false)) { - print_collapsible_region_start('', 'workshop-viewlet-examplesfail', get_string('exampleassessments', 'workshop'), - 'workshop-viewlet-examplesfail-collapsed'); - echo $output->box(get_string('exampleneedsubmission', 'workshop')); - print_collapsible_region_end(); - $examplesavailable = false; - } - - if ($workshop->assessing_examples_allowed() - and has_capability('mod/workshop:submit', $workshop->context) - and ! has_capability('mod/workshop:manageexamples', $workshop->context) - and $examplesavailable) { - $examples = $userplan->get_examples(); - $total = count($examples); - $left = 0; - // make sure the current user has all examples allocated - foreach ($examples as $exampleid => $example) { - if (is_null($example->assessmentid)) { - $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0); - } - if (is_null($example->grade)) { - $left++; - } + break; + case workshop::PHASE_SUBMISSION: + if (trim($workshop->instructauthors)) { + $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id, + 'mod_workshop', 'instructauthors', null, workshop::instruction_editors_options($PAGE->context)); + print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'), + 'workshop-viewlet-instructauthors-collapsed'); + echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv' => true)), + array('generalbox', 'instructions')); + print_collapsible_region_end(); } - if ($left > 0 and $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) { - $examplesdone = false; - } else { - $examplesdone = true; - } - print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), + + if ($workshop->assessing_examples_allowed() + && has_capability('mod/workshop:submit', $workshop->context) + && !has_capability('mod/workshop:manageexamples', $workshop->context)) { + $examples = $userplan->get_examples(); + $total = count($examples); + print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), 'workshop-viewlet-examples-collapsed', $examplesdone); - echo $output->box_start('generalbox exampleassessments'); - if ($total == 0) { - echo $output->heading(get_string('noexamples', 'workshop'), 3); - } else { - foreach ($examples as $example) { - $summary = $workshop->prepare_example_summary($example); - echo $output->render($summary); + echo $output->box_start('generalbox exampleassessments'); + if ($total == 0) { + echo $output->heading(get_string('noexamples', 'workshop'), 3); + } else { + foreach ($examples as $example) { + $summary = $workshop->prepare_example_summary($example); + echo $output->render($summary); + } + } + echo $output->box_end(); + print_collapsible_region_end(); + } + + if (has_capability('mod/workshop:submit', $PAGE->context) && (!$examplesmust || $examplesdone)) { + print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), + 'workshop-viewlet-ownsubmission-collapsed'); + echo $output->box_start('generalbox ownsubmission'); + if ($submission = $workshop->get_submission_by_author($USER->id)) { + echo $output->render($workshop->prepare_submission_summary($submission, true)); + } else { + echo $output->container(get_string('noyoursubmission', 'workshop')); + } + + echo $output->box_end(); + print_collapsible_region_end(); + } + + if (has_capability('mod/workshop:viewallsubmissions', $PAGE->context)) { + $groupmode = groups_get_activity_groupmode($workshop->cm); + $groupid = groups_get_activity_group($workshop->cm, true); + + if ($groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $workshop->context)) { + $allowedgroups = groups_get_activity_allowed_groups($workshop->cm); + if (empty($allowedgroups)) { + echo $output->container(get_string('groupnoallowed', 'mod_workshop'), 'groupwidget error'); + break; + } + if (!in_array($groupid, array_keys($allowedgroups))) { + echo $output->container(get_string('groupnotamember', 'core_group'), 'groupwidget error'); + break; + } + } + + print_collapsible_region_start('', 'workshop-viewlet-allsubmissions', get_string('submissionsreport', 'workshop'), + 'workshop-viewlet-allsubmissions-collapsed'); + + $perpage = get_user_preferences('workshop_perpage', 10); + $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow); + if ($data) { + $countparticipants = $workshop->count_participants(); + $countsubmissions = $workshop->count_submissions(array_keys($data->grades), $groupid); + $a = new stdClass(); + $a->submitted = $countsubmissions; + $a->notsubmitted = $data->totalcount - $countsubmissions; + + echo html_writer::tag('div', get_string('submittednotsubmitted', 'workshop', $a)); + + echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget'); + + // Prepare the paging bar. + $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow)); + $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page'); + + // Populate the display options for the submissions report. + $reportopts = new stdclass(); + $reportopts->showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context); + $reportopts->showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context); + $reportopts->sortby = $sortby; + $reportopts->sorthow = $sorthow; + $reportopts->showsubmissiongrade = false; + $reportopts->showgradinggrade = false; + $reportopts->workshopphase = $workshop->phase; + echo $output->initials_bars($workshop, $baseurl); + echo $output->render($pagingbar); + echo $output->render(new workshop_grading_report($data, $reportopts)); + echo $output->render($pagingbar); + echo $output->perpage_selector($perpage); + } else { + echo html_writer::tag('div', get_string('nothingfound', 'workshop'), array('class' => 'nothingfound')); + } + print_collapsible_region_end(); + } + break; + + case workshop::PHASE_ASSESSMENT: + + $ownsubmissionexists = null; + if (has_capability('mod/workshop:submit', $PAGE->context)) { + if ($ownsubmission = $workshop->get_submission_by_author($USER->id)) { + print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), + 'workshop-viewlet-ownsubmission-collapsed', true); + echo $output->box_start('generalbox ownsubmission'); + echo $output->render($workshop->prepare_submission_summary($ownsubmission, true)); + $ownsubmissionexists = true; + } else { + print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), + 'workshop-viewlet-ownsubmission-collapsed'); + echo $output->box_start('generalbox ownsubmission'); + echo $output->container(get_string('noyoursubmission', 'workshop')); + $ownsubmissionexists = false; + } + + echo $output->box_end(); + print_collapsible_region_end(); + } + + if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) { + $perpage = get_user_preferences('workshop_perpage', 10); + $groupid = groups_get_activity_group($workshop->cm, true); + $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow); + if ($data) { + $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context); + $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context); + + // Prepare paging bar. + $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow)); + $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page'); + + // Grading report display options. + $reportopts = new stdclass(); + $reportopts->showauthornames = $showauthornames; + $reportopts->showreviewernames = $showreviewernames; + $reportopts->sortby = $sortby; + $reportopts->sorthow = $sorthow; + $reportopts->showsubmissiongrade = false; + $reportopts->showgradinggrade = false; + $reportopts->workshopphase = $workshop->phase; + + print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'), + 'workshop-viewlet-gradereport-collapsed'); + echo $output->box_start('generalbox gradesreport'); + echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget'); + echo $output->initials_bars($workshop, $baseurl); + echo $output->render($pagingbar); + echo $output->render(new workshop_grading_report($data, $reportopts)); + echo $output->render($pagingbar); + echo $output->perpage_selector($perpage); + echo $output->box_end(); + print_collapsible_region_end(); } } - echo $output->box_end(); - print_collapsible_region_end(); - } - if (!$examplesmust or $examplesdone) { - print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'), - 'workshop-viewlet-assignedassessments-collapsed'); - if (! $assessments = $workshop->get_assessments_by_reviewer($USER->id)) { - echo $output->box_start('generalbox assessment-none'); - echo $output->notification(get_string('assignedassessmentsnone', 'workshop')); + if (trim($workshop->instructreviewers)) { + $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id, + 'mod_workshop', 'instructreviewers', null, workshop::instruction_editors_options($PAGE->context)); + print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'), + 'workshop-viewlet-instructreviewers-collapsed'); + echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv' => true)), + array('generalbox', 'instructions')); + print_collapsible_region_end(); + } + + // Does the user have to assess examples before assessing other's work? + $examplesmust = ($workshop->useexamples && $workshop->examplesmode == workshop::EXAMPLES_BEFORE_ASSESSMENT); + + // Is the assessment of example submissions considered finished? + $examplesdone = has_capability('mod/workshop:manageexamples', $workshop->context); + + // Can the examples be assessed? + $examplesavailable = true; + + if (!$examplesdone && $examplesmust && ($ownsubmissionexists === false)) { + print_collapsible_region_start('', 'workshop-viewlet-examplesfail', get_string('exampleassessments', 'workshop'), + 'workshop-viewlet-examplesfail-collapsed'); + echo $output->box(get_string('exampleneedsubmission', 'workshop')); + print_collapsible_region_end(); + $examplesavailable = false; + } + + if ($workshop->assessing_examples_allowed() + && has_capability('mod/workshop:submit', $workshop->context) + && !has_capability('mod/workshop:manageexamples', $workshop->context) + && $examplesavailable) { + $examples = $userplan->get_examples(); + $total = count($examples); + $left = 0; + // Make sure the current user has all examples allocated. + foreach ($examples as $exampleid => $example) { + if (is_null($example->assessmentid)) { + $examples[$exampleid]->assessmentid = $workshop->add_allocation($example, $USER->id, 0); + } + if (is_null($example->grade)) { + $left++; + } + } + if ($left > 0 && $workshop->examplesmode != workshop::EXAMPLES_VOLUNTARY) { + $examplesdone = false; + } else { + $examplesdone = true; + } + print_collapsible_region_start('', 'workshop-viewlet-examples', get_string('exampleassessments', 'workshop'), + 'workshop-viewlet-examples-collapsed', $examplesdone); + echo $output->box_start('generalbox exampleassessments'); + if ($total == 0) { + echo $output->heading(get_string('noexamples', 'workshop'), 3); + } else { + foreach ($examples as $example) { + $summary = $workshop->prepare_example_summary($example); + echo $output->render($summary); + } + } echo $output->box_end(); - } else { + print_collapsible_region_end(); + } + if (!$examplesmust || $examplesdone) { + print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', + get_string('assignedassessments', 'workshop'), + 'workshop-viewlet-assignedassessments-collapsed'); + if (!$assessments = $workshop->get_assessments_by_reviewer($USER->id)) { + echo $output->box_start('generalbox assessment-none'); + echo $output->notification(get_string('assignedassessmentsnone', 'workshop')); + echo $output->box_end(); + } else { + $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context); + foreach ($assessments as $assessment) { + $submission = new stdClass(); + $submission->id = $assessment->submissionid; + $submission->title = $assessment->submissiontitle; + $submission->timecreated = $assessment->submissioncreated; + $submission->timemodified = $assessment->submissionmodified; + $userpicturefields = explode(',', implode(',', \core_user\fields::get_picture_fields())); + foreach ($userpicturefields as $userpicturefield) { + $prefixedusernamefield = 'author' . $userpicturefield; + $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield; + } + + // Transform the submission object into renderable component. + $submission = $workshop->prepare_submission_summary($submission, $shownames); + + if (is_null($assessment->grade)) { + $submission->status = 'notgraded'; + $class = ' notgraded'; + $buttontext = get_string('assess', 'workshop'); + } else { + $submission->status = 'graded'; + $class = ' graded'; + $buttontext = get_string('reassess', 'workshop'); + } + + echo $output->box_start('generalbox assessment-summary' . $class); + echo $output->render($submission); + $aurl = $workshop->assess_url($assessment->id); + echo $output->single_button($aurl, $buttontext, 'get'); + echo $output->box_end(); + } + } + print_collapsible_region_end(); + } + break; + case workshop::PHASE_EVALUATION: + if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) { + $perpage = get_user_preferences('workshop_perpage', 10); + $groupid = groups_get_activity_group($workshop->cm, true); + $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow); + if ($data) { + $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context); + $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context); + + if (has_capability('mod/workshop:overridegrades', $PAGE->context)) { + // Print a drop-down selector to change the current evaluation method. + $selector = new single_select($PAGE->url, 'eval', workshop::available_evaluators_list(), + $workshop->evaluation, false, 'evaluationmethodchooser'); + $selector->set_label(get_string('evaluationmethod', 'mod_workshop')); + $selector->set_help_icon('evaluationmethod', 'mod_workshop'); + $selector->method = 'post'; + echo $output->render($selector); + // Load the grading evaluator. + $evaluator = $workshop->grading_evaluation_instance(); + $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(), + compact('sortby', 'sorthow', 'page'))); + $form->display(); + } + + // Prepare paging bar. + $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow)); + $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page'); + + // Grading report display options. + $reportopts = new stdclass(); + $reportopts->showauthornames = $showauthornames; + $reportopts->showreviewernames = $showreviewernames; + $reportopts->sortby = $sortby; + $reportopts->sorthow = $sorthow; + $reportopts->showsubmissiongrade = true; + $reportopts->showgradinggrade = true; + $reportopts->workshopphase = $workshop->phase; + + print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'), + 'workshop-viewlet-gradereport-collapsed'); + echo $output->box_start('generalbox gradesreport'); + echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget'); + echo $output->initials_bars($workshop, $baseurl); + echo $output->render($pagingbar); + echo $output->render(new workshop_grading_report($data, $reportopts)); + echo $output->render($pagingbar); + echo $output->perpage_selector($perpage); + echo $output->box_end(); + print_collapsible_region_end(); + } + } + if (has_capability('mod/workshop:overridegrades', $workshop->context)) { + print_collapsible_region_start('', 'workshop-viewlet-cleargrades', get_string('toolbox', 'workshop'), + 'workshop-viewlet-cleargrades-collapsed', true); + echo $output->box_start('generalbox toolbox'); + + // Clear aggregated grades. + $url = new moodle_url($workshop->toolbox_url('clearaggregatedgrades')); + $btn = new single_button($url, get_string('clearaggregatedgrades', 'workshop'), 'post'); + $btn->add_confirm_action(get_string('clearaggregatedgradesconfirm', 'workshop')); + echo $output->container_start('toolboxaction'); + echo $output->render($btn); + echo $output->help_icon('clearaggregatedgrades', 'workshop'); + echo $output->container_end(); + // Clear assessments. + $url = new moodle_url($workshop->toolbox_url('clearassessments')); + $btn = new single_button($url, get_string('clearassessments', 'workshop'), 'post'); + $btn->add_confirm_action(get_string('clearassessmentsconfirm', 'workshop')); + echo $output->container_start('toolboxaction'); + echo $output->render($btn); + echo $output->help_icon('clearassessments', 'workshop'); + + echo $OUTPUT->pix_icon('i/risk_dataloss', get_string('riskdatalossshort', 'admin')); + echo $output->container_end(); + + echo $output->box_end(); + print_collapsible_region_end(); + } + if (has_capability('mod/workshop:submit', $PAGE->context)) { + print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), + 'workshop-viewlet-ownsubmission-collapsed'); + echo $output->box_start('generalbox ownsubmission'); + if ($submission = $workshop->get_submission_by_author($USER->id)) { + echo $output->render($workshop->prepare_submission_summary($submission, true)); + } else { + echo $output->container(get_string('noyoursubmission', 'workshop')); + } + echo $output->box_end(); + print_collapsible_region_end(); + } + if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) { + print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', + get_string('assignedassessments', 'workshop'), + 'workshop-viewlet-assignedassessments-collapsed'); $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context); foreach ($assessments as $assessment) { - $submission = new stdClass(); - $submission->id = $assessment->submissionid; - $submission->title = $assessment->submissiontitle; - $submission->timecreated = $assessment->submissioncreated; - $submission->timemodified = $assessment->submissionmodified; + $submission = new stdclass(); + $submission->id = $assessment->submissionid; + $submission->title = $assessment->submissiontitle; + $submission->timecreated = $assessment->submissioncreated; + $submission->timemodified = $assessment->submissionmodified; $userpicturefields = explode(',', implode(',', \core_user\fields::get_picture_fields())); foreach ($userpicturefields as $userpicturefield) { $prefixedusernamefield = 'author' . $userpicturefield; $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield; } - // transform the submission object into renderable component - $submission = $workshop->prepare_submission_summary($submission, $shownames); - if (is_null($assessment->grade)) { - $submission->status = 'notgraded'; $class = ' notgraded'; + $submission->status = 'notgraded'; $buttontext = get_string('assess', 'workshop'); } else { - $submission->status = 'graded'; $class = ' graded'; + $submission->status = 'graded'; $buttontext = get_string('reassess', 'workshop'); } - echo $output->box_start('generalbox assessment-summary' . $class); - echo $output->render($submission); - $aurl = $workshop->assess_url($assessment->id); - echo $output->single_button($aurl, $buttontext, 'get'); - echo $output->box_end(); - } - } - print_collapsible_region_end(); - } - break; -case workshop::PHASE_EVALUATION: - if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) { - $perpage = get_user_preferences('workshop_perpage', 10); - $groupid = groups_get_activity_group($workshop->cm, true); - $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow); - if ($data) { - $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context); - $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context); - - if (has_capability('mod/workshop:overridegrades', $PAGE->context)) { - // Print a drop-down selector to change the current evaluation method. - $selector = new single_select($PAGE->url, 'eval', workshop::available_evaluators_list(), - $workshop->evaluation, false, 'evaluationmethodchooser'); - $selector->set_label(get_string('evaluationmethod', 'mod_workshop')); - $selector->set_help_icon('evaluationmethod', 'mod_workshop'); - $selector->method = 'post'; - echo $output->render($selector); - // load the grading evaluator - $evaluator = $workshop->grading_evaluation_instance(); - $form = $evaluator->get_settings_form(new moodle_url($workshop->aggregate_url(), - compact('sortby', 'sorthow', 'page'))); - $form->display(); - } - - // prepare paging bar - $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow)); - $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page'); - - // grading report display options - $reportopts = new stdclass(); - $reportopts->showauthornames = $showauthornames; - $reportopts->showreviewernames = $showreviewernames; - $reportopts->sortby = $sortby; - $reportopts->sorthow = $sorthow; - $reportopts->showsubmissiongrade = true; - $reportopts->showgradinggrade = true; - $reportopts->workshopphase = $workshop->phase; - - print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'), - 'workshop-viewlet-gradereport-collapsed'); - echo $output->box_start('generalbox gradesreport'); - echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget'); - echo $output->render($pagingbar); - echo $output->render(new workshop_grading_report($data, $reportopts)); - echo $output->render($pagingbar); - echo $output->perpage_selector($perpage); - echo $output->box_end(); - print_collapsible_region_end(); - } - } - if (has_capability('mod/workshop:overridegrades', $workshop->context)) { - print_collapsible_region_start('', 'workshop-viewlet-cleargrades', get_string('toolbox', 'workshop'), - 'workshop-viewlet-cleargrades-collapsed', true); - echo $output->box_start('generalbox toolbox'); - - // Clear aggregated grades - $url = new moodle_url($workshop->toolbox_url('clearaggregatedgrades')); - $btn = new single_button($url, get_string('clearaggregatedgrades', 'workshop'), 'post'); - $btn->add_confirm_action(get_string('clearaggregatedgradesconfirm', 'workshop')); - echo $output->container_start('toolboxaction'); - echo $output->render($btn); - echo $output->help_icon('clearaggregatedgrades', 'workshop'); - echo $output->container_end(); - // Clear assessments - $url = new moodle_url($workshop->toolbox_url('clearassessments')); - $btn = new single_button($url, get_string('clearassessments', 'workshop'), 'post'); - $btn->add_confirm_action(get_string('clearassessmentsconfirm', 'workshop')); - echo $output->container_start('toolboxaction'); - echo $output->render($btn); - echo $output->help_icon('clearassessments', 'workshop'); - - echo $OUTPUT->pix_icon('i/risk_dataloss', get_string('riskdatalossshort', 'admin')); - echo $output->container_end(); - - echo $output->box_end(); - print_collapsible_region_end(); - } - if (has_capability('mod/workshop:submit', $PAGE->context)) { - print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', get_string('yoursubmission', 'workshop'), - 'workshop-viewlet-ownsubmission-collapsed'); - echo $output->box_start('generalbox ownsubmission'); - if ($submission = $workshop->get_submission_by_author($USER->id)) { - echo $output->render($workshop->prepare_submission_summary($submission, true)); - } else { - echo $output->container(get_string('noyoursubmission', 'workshop')); - } - echo $output->box_end(); - print_collapsible_region_end(); - } - if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) { - print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'), - 'workshop-viewlet-assignedassessments-collapsed'); - $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context); - foreach ($assessments as $assessment) { - $submission = new stdclass(); - $submission->id = $assessment->submissionid; - $submission->title = $assessment->submissiontitle; - $submission->timecreated = $assessment->submissioncreated; - $submission->timemodified = $assessment->submissionmodified; - $userpicturefields = explode(',', implode(',', \core_user\fields::get_picture_fields())); - foreach ($userpicturefields as $userpicturefield) { - $prefixedusernamefield = 'author' . $userpicturefield; - $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield; - } - - if (is_null($assessment->grade)) { - $class = ' notgraded'; - $submission->status = 'notgraded'; - $buttontext = get_string('assess', 'workshop'); - } else { - $class = ' graded'; - $submission->status = 'graded'; - $buttontext = get_string('reassess', 'workshop'); - } - echo $output->box_start('generalbox assessment-summary' . $class); - echo $output->render($workshop->prepare_submission_summary($submission, $shownames)); - echo $output->box_end(); - } - print_collapsible_region_end(); - } - break; -case workshop::PHASE_CLOSED: - if (trim($workshop->conclusion)) { - $conclusion = file_rewrite_pluginfile_urls($workshop->conclusion, 'pluginfile.php', $workshop->context->id, - 'mod_workshop', 'conclusion', null, workshop::instruction_editors_options($workshop->context)); - print_collapsible_region_start('', 'workshop-viewlet-conclusion', get_string('conclusion', 'workshop'), - 'workshop-viewlet-conclusion-collapsed'); - echo $output->box(format_text($conclusion, $workshop->conclusionformat, array('overflowdiv'=>true)), array('generalbox', 'conclusion')); - print_collapsible_region_end(); - } - $finalgrades = $workshop->get_gradebook_grades($USER->id); - if (!empty($finalgrades)) { - print_collapsible_region_start('', 'workshop-viewlet-yourgrades', get_string('yourgrades', 'workshop'), - 'workshop-viewlet-yourgrades-collapsed'); - echo $output->box_start('generalbox grades-yourgrades'); - echo $output->render($finalgrades); - echo $output->box_end(); - print_collapsible_region_end(); - } - if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) { - $perpage = get_user_preferences('workshop_perpage', 10); - $groupid = groups_get_activity_group($workshop->cm, true); - $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow); - if ($data) { - $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context); - $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context); - - // prepare paging bar - $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow)); - $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page'); - - // grading report display options - $reportopts = new stdclass(); - $reportopts->showauthornames = $showauthornames; - $reportopts->showreviewernames = $showreviewernames; - $reportopts->sortby = $sortby; - $reportopts->sorthow = $sorthow; - $reportopts->showsubmissiongrade = true; - $reportopts->showgradinggrade = true; - $reportopts->workshopphase = $workshop->phase; - - print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'), - 'workshop-viewlet-gradereport-collapsed'); - echo $output->box_start('generalbox gradesreport'); - echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget'); - echo $output->render($pagingbar); - echo $output->render(new workshop_grading_report($data, $reportopts)); - echo $output->render($pagingbar); - echo $output->perpage_selector($perpage); - echo $output->box_end(); - print_collapsible_region_end(); - } - } - if (has_capability('mod/workshop:submit', $PAGE->context)) { - print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', - get_string('yoursubmissionwithassessments', 'workshop'), 'workshop-viewlet-ownsubmission-collapsed'); - echo $output->box_start('generalbox ownsubmission'); - if ($submission = $workshop->get_submission_by_author($USER->id)) { - echo $output->render($workshop->prepare_submission_summary($submission, true)); - } else { - echo $output->container(get_string('noyoursubmission', 'workshop')); - } - echo $output->box_end(); - - if (!empty($submission->gradeoverby) and strlen(trim($submission->feedbackauthor)) > 0) { - echo $output->render(new workshop_feedback_author($submission)); - } - - print_collapsible_region_end(); - } - if (has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context)) { - $shownames = has_capability('mod/workshop:viewauthorpublished', $workshop->context); - if ($submissions = $workshop->get_published_submissions()) { - print_collapsible_region_start('', 'workshop-viewlet-publicsubmissions', get_string('publishedsubmissions', 'workshop'), - 'workshop-viewlet-publicsubmissions-collapsed'); - foreach ($submissions as $submission) { - echo $output->box_start('generalbox submission-summary'); echo $output->render($workshop->prepare_submission_summary($submission, $shownames)); echo $output->box_end(); } print_collapsible_region_end(); } - } - if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) { - print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', get_string('assignedassessments', 'workshop'), - 'workshop-viewlet-assignedassessments-collapsed'); - $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context); - foreach ($assessments as $assessment) { - $submission = new stdclass(); - $submission->id = $assessment->submissionid; - $submission->title = $assessment->submissiontitle; - $submission->timecreated = $assessment->submissioncreated; - $submission->timemodified = $assessment->submissionmodified; - $userpicturefields = explode(',', implode(',', \core_user\fields::get_picture_fields())); - foreach ($userpicturefields as $userpicturefield) { - $prefixedusernamefield = 'author' . $userpicturefield; - $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield; - } - - if (is_null($assessment->grade)) { - $class = ' notgraded'; - $submission->status = 'notgraded'; - $buttontext = get_string('assess', 'workshop'); - } else { - $class = ' graded'; - $submission->status = 'graded'; - $buttontext = get_string('reassess', 'workshop'); - } - echo $output->box_start('generalbox assessment-summary' . $class); - echo $output->render($workshop->prepare_submission_summary($submission, $shownames)); + break; + case workshop::PHASE_CLOSED: + if (trim($workshop->conclusion)) { + $conclusion = file_rewrite_pluginfile_urls($workshop->conclusion, 'pluginfile.php', $workshop->context->id, + 'mod_workshop', 'conclusion', null, workshop::instruction_editors_options($workshop->context)); + print_collapsible_region_start('', 'workshop-viewlet-conclusion', get_string('conclusion', 'workshop'), + 'workshop-viewlet-conclusion-collapsed'); + echo $output->box(format_text($conclusion, $workshop->conclusionformat, array('overflowdiv' => true)), + array('generalbox', 'conclusion')); + print_collapsible_region_end(); + } + $finalgrades = $workshop->get_gradebook_grades($USER->id); + if (!empty($finalgrades)) { + print_collapsible_region_start('', 'workshop-viewlet-yourgrades', get_string('yourgrades', 'workshop'), + 'workshop-viewlet-yourgrades-collapsed'); + echo $output->box_start('generalbox grades-yourgrades'); + echo $output->render($finalgrades); echo $output->box_end(); + print_collapsible_region_end(); + } + if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) { + $perpage = get_user_preferences('workshop_perpage', 10); + $groupid = groups_get_activity_group($workshop->cm, true); + $data = $workshop->prepare_grading_report_data($USER->id, $groupid, $page, $perpage, $sortby, $sorthow); + if ($data) { + $showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context); + $showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context); - if (strlen(trim($assessment->feedbackreviewer)) > 0) { - echo $output->render(new workshop_feedback_reviewer($assessment)); + // Prepare paging bar. + $baseurl = new moodle_url($PAGE->url, array('sortby' => $sortby, 'sorthow' => $sorthow)); + $pagingbar = new paging_bar($data->totalcount, $page, $perpage, $baseurl, 'page'); + + // Grading report display options. + $reportopts = new stdclass(); + $reportopts->showauthornames = $showauthornames; + $reportopts->showreviewernames = $showreviewernames; + $reportopts->sortby = $sortby; + $reportopts->sorthow = $sorthow; + $reportopts->showsubmissiongrade = true; + $reportopts->showgradinggrade = true; + $reportopts->workshopphase = $workshop->phase; + + print_collapsible_region_start('', 'workshop-viewlet-gradereport', get_string('gradesreport', 'workshop'), + 'workshop-viewlet-gradereport-collapsed'); + echo $output->box_start('generalbox gradesreport'); + echo $output->container(groups_print_activity_menu($workshop->cm, $PAGE->url, true), 'groupwidget'); + echo $output->initials_bars($workshop, $baseurl); + echo $output->render($pagingbar); + echo $output->render(new workshop_grading_report($data, $reportopts)); + echo $output->render($pagingbar); + echo $output->perpage_selector($perpage); + echo $output->box_end(); + print_collapsible_region_end(); } } - print_collapsible_region_end(); - } - break; -default: + if (has_capability('mod/workshop:submit', $PAGE->context)) { + print_collapsible_region_start('', 'workshop-viewlet-ownsubmission', + get_string('yoursubmissionwithassessments', 'workshop'), 'workshop-viewlet-ownsubmission-collapsed'); + echo $output->box_start('generalbox ownsubmission'); + if ($submission = $workshop->get_submission_by_author($USER->id)) { + echo $output->render($workshop->prepare_submission_summary($submission, true)); + } else { + echo $output->container(get_string('noyoursubmission', 'workshop')); + } + echo $output->box_end(); + + if (!empty($submission->gradeoverby) && strlen(trim($submission->feedbackauthor)) > 0) { + echo $output->render(new workshop_feedback_author($submission)); + } + + print_collapsible_region_end(); + } + if (has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context)) { + $shownames = has_capability('mod/workshop:viewauthorpublished', $workshop->context); + if ($submissions = $workshop->get_published_submissions()) { + print_collapsible_region_start('', 'workshop-viewlet-publicsubmissions', + get_string('publishedsubmissions', 'workshop'), + 'workshop-viewlet-publicsubmissions-collapsed'); + foreach ($submissions as $submission) { + echo $output->box_start('generalbox submission-summary'); + echo $output->render($workshop->prepare_submission_summary($submission, $shownames)); + echo $output->box_end(); + } + print_collapsible_region_end(); + } + } + if ($assessments = $workshop->get_assessments_by_reviewer($USER->id)) { + print_collapsible_region_start('', 'workshop-viewlet-assignedassessments', + get_string('assignedassessments', 'workshop'), + 'workshop-viewlet-assignedassessments-collapsed'); + $shownames = has_capability('mod/workshop:viewauthornames', $PAGE->context); + foreach ($assessments as $assessment) { + $submission = new stdclass(); + $submission->id = $assessment->submissionid; + $submission->title = $assessment->submissiontitle; + $submission->timecreated = $assessment->submissioncreated; + $submission->timemodified = $assessment->submissionmodified; + $userpicturefields = explode(',', implode(',', \core_user\fields::get_picture_fields())); + foreach ($userpicturefields as $userpicturefield) { + $prefixedusernamefield = 'author' . $userpicturefield; + $submission->$prefixedusernamefield = $assessment->$prefixedusernamefield; + } + + if (is_null($assessment->grade)) { + $class = ' notgraded'; + $submission->status = 'notgraded'; + $buttontext = get_string('assess', 'workshop'); + } else { + $class = ' graded'; + $submission->status = 'graded'; + $buttontext = get_string('reassess', 'workshop'); + } + echo $output->box_start('generalbox assessment-summary' . $class); + echo $output->render($workshop->prepare_submission_summary($submission, $shownames)); + echo $output->box_end(); + + if (strlen(trim($assessment->feedbackreviewer)) > 0) { + echo $output->render(new workshop_feedback_reviewer($assessment)); + } + } + print_collapsible_region_end(); + } + break; + default: } $PAGE->requires->js_call_amd('mod_workshop/workshopview', 'init'); echo $output->footer();