Skip to content

Commit

Permalink
added renderer functions to improve design of the front page
Browse files Browse the repository at this point in the history
  • Loading branch information
irinahpe committed Nov 22, 2023
1 parent ad87194 commit 2bec4c3
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 4 deletions.
1 change: 1 addition & 0 deletions lang/en/ratingallocate.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
Each choice will be filled up to its maximum before assigning users to the next choice.';
$string['distribute_unallocated_equally_confirm'] = 'All currently unallocated users will be distributed to the choices.
The choices will be filled up equally, so all of them have about the same amount of places left.';
$string['unallocated_user_count'] = 'There are {$a->count} users unallocated';
$string['no_user_to_allocate'] = 'There is no user you could allocate';
$string['ratings_table'] = 'Ratings and Allocations';
$string['ratings_table_sum_allocations'] = 'Number of allocations / Maximum';
Expand Down
6 changes: 2 additions & 4 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1078,10 +1078,8 @@ private function process_default() {
// Print data and controls for teachers.
if (has_capability('mod/ratingallocate:start_distribution', $this->context)) {
$undistributeduserscount = count($this->get_undistributed_users());
$output .= $renderer->modify_allocation_group($this->ratingallocateid, $this->coursemodule->id, $status,
$undistributeduserscount, (int) $this->ratingallocate->algorithmstatus,
(boolean) $this->ratingallocate->runalgorithmbycron);
$output .= $renderer->publish_allocation_group($this->ratingallocateid, $this->coursemodule->id, $status);
$output .= $renderer->render_ratingallocate_allocation_status($this->coursemodule->id, $status, $undistributeduserscount);
$output .= $renderer->render_ratingallocate_publish_allocation($this->ratingallocateid, $this->coursemodule->id, $status);
$output .= $renderer->reports_group($this->ratingallocateid, $this->coursemodule->id, $status, $this->context);
}

Expand Down
164 changes: 164 additions & 0 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,151 @@ public function render_ratingallocate_strategyform($mform) {
return $o;
}

/**
* Displays the status of the allocation with buttons to start the algorithm, delete existing distributions,
* and distribute unallocated users.
*
* @param $coursemoduleid
* @param $status
* @param $undistributeduserscount
* @return string
* @throws coding_exception
* @throws moodle_exception
*/
public function render_ratingallocate_allocation_status($coursemoduleid, $status, $undistributeduserscount) {

$output = '';
$output .= $this->output->container_start('allocationstatustable');
$output .= $this->heading(get_string('modify_allocation_group', RATINGALLOCATE_MOD_NAME), 2);
$output .= $this->box_start();

$isdistributionrunning = $this->is_distribution_of_unallocated_users_running($coursemoduleid);

// The instance is called ready if it is in one of the two following status.
$ratingover = $status !== ratingallocate::DISTRIBUTION_STATUS_TOO_EARLY &&
$status !== ratingallocate::DISTRIBUTION_STATUS_RATING_IN_PROGRESS;

$starturl = new moodle_url($this->page->url, array('action' => ACTION_START_DISTRIBUTION));
$deleteurl = new moodle_url($this->page->url, array('id' => $coursemoduleid, 'action' => ACTION_DELETE_ALL_RATINGS));

// Get description dependent on status.
$descriptionbaseid = 'modify_allocation_group_desc_';
$description = get_string($descriptionbaseid . $status, RATINGALLOCATE_MOD_NAME);

// Create start algorithm button
$button = new single_button($starturl, get_string('start_distribution', RATINGALLOCATE_MOD_NAME), 'get');
// Enable only if the instance is ready and the algorithm may run manually.
$button->disabled = !($ratingover) || $isdistributionrunning;
$button->tooltip = get_string('start_distribution_explanation', RATINGALLOCATE_MOD_NAME);
$button->add_action(new confirm_action(get_string('confirm_start_distribution', RATINGALLOCATE_MOD_NAME)));

// Create delete all ratings button.
$deletebutton = new single_button($deleteurl, get_string('delete_all_ratings', RATINGALLOCATE_MOD_NAME, 'get'));
// Only allow deletion if new submission is possible and distribution currently not running.
$deletebutton->disabled = $ratingover || $isdistributionrunning;
$deletebutton->tooltip = get_string('delete_all_ratings_explanation', RATINGALLOCATE_MOD_NAME);
$deletebutton->add_action(new confirm_action(get_string('confirm_delete_all_ratings', RATINGALLOCATE_MOD_NAME)));


$table = new html_table();

// Add status, buttons for manual and algorithmic allocation and delete all ratings buuton to the table.
$this->add_table_row_triple($table,
$this->format_text($description),
$this->render($button) . '<br/>' . '<br/>' . $this->single_button(new moodle_url('/mod/ratingallocate/view.php', array('id' => $coursemoduleid,
'action' => ACTION_MANUAL_ALLOCATION)), get_string('manual_allocation_form', RATINGALLOCATE_MOD_NAME), 'get',
array('disabled' => !$ratingover || $isdistributionrunning)),
$this->render($deletebutton)
);

if (has_capability('mod/ratingallocate:distribute_unallocated', context_module::instance($coursemoduleid))) {

if ($ratingover && $undistributeduserscount != 0 && !$isdistributionrunning) {

// Add empty row.
$this->add_table_row_triple($table, '', '', '');

$distributeunallocatedurleq = new moodle_url($this->page->url, array('action' => ACTION_DISTRIBUTE_UNALLOCATED_EQUALLY));
$buttondisteq = new single_button($distributeunallocatedurleq,
get_string('distributeequally', RATINGALLOCATE_MOD_NAME), 'get');
$buttondisteq->add_action(new confirm_action(
get_string('distribute_unallocated_equally_confirm', RATINGALLOCATE_MOD_NAME)));

$distributeunallocatedurlfill = new moodle_url($this->page->url, array('action' => ACTION_DISTRIBUTE_UNALLOCATED_FILL));
$buttondistfill = new single_button($distributeunallocatedurlfill,
get_string('distributefill', RATINGALLOCATE_MOD_NAME), 'get');
$buttondistfill->add_action(new confirm_action(
get_string('distribute_unallocated_fill_confirm', RATINGALLOCATE_MOD_NAME)));

// Add Amount of users that are unallocated and buttons to allocate them manually.
$this->add_table_row_triple($table,
get_string('unallocated_user_count', RATINGALLOCATE_MOD_NAME, ['count' => $undistributeduserscount]) . $this->help_icon('distribution_description', RATINGALLOCATE_MOD_NAME),
$this->render($buttondisteq),
$this->render($buttondistfill)
);

} else if ($isdistributionrunning) {

// Add empty row.
$this->add_table_row_triple($table, '', '', '');

$this->add_table_row_triple($table,
get_string('unallocated_user_count', RATINGALLOCATE_MOD_NAME, ['count' => $undistributeduserscount]),
get_string('distribution_unallocated_already_running', RATINGALLOCATE_MOD_NAME),
''
);
}
}

$output .= html_writer::table($table);
$output .= $this->output->box_end();
$output .= $this->output->container_end();
return $output;
}

/**
* Displays the status concerning publishing the allocation together with the buttons to publish the allocation
* and to create groups.
*
* @param $ratingallocateid
* @param $coursemoduleid
* @param $status
* @return string
* @throws coding_exception
* @throws moodle_exception
*/
public function render_ratingallocate_publish_allocation($ratingallocateid, $coursemoduleid, $status) {

$output = '';
$output .= $this->output->container_start('allocationstatustable');
$output .= $this->heading(get_string('publish_allocation_group', RATINGALLOCATE_MOD_NAME), 2);
$output .= $this->box_start();

$isready = $status === ratingallocate::DISTRIBUTION_STATUS_READY_ALLOC_STARTED;

$table = new html_table();

// Get description dependent on status.
$descriptionbaseid = 'publish_allocation_group_desc_';
$description = get_string($descriptionbaseid . $status, RATINGALLOCATE_MOD_NAME);

$this->add_table_row_triple($table,
$this->format_text($description),
$this->single_button(new moodle_url('/mod/ratingallocate/view.php', array('id' => $coursemoduleid,
'ratingallocateid' => $ratingallocateid,
'action' => ACTION_PUBLISH_ALLOCATIONS)), get_string('publish_allocation', RATINGALLOCATE_MOD_NAME), 'get',
array('disabled' => !$isready)),
$this->single_button(new moodle_url('/mod/ratingallocate/view.php', array('id' => $coursemoduleid,
'ratingallocateid' => $ratingallocateid,
'action' => ACTION_ALLOCATION_TO_GROUPING)), get_string('create_moodle_groups', RATINGALLOCATE_MOD_NAME), 'get')
);

$output .= html_writer::table($table);
$output .= $this->output->box_end();
$output .= $this->output->container_end();
return $output;
}

/**
* render current choice status
* @param ratingallocate_choice_status $status
Expand Down Expand Up @@ -797,6 +942,25 @@ private function add_table_row_tuple(html_table $table, $first, $second) {
$table->data[] = $row;
}

/**
* Utility function to add a row of data to a table with 3 columns. Modified
* the table param and does not return a value
*
* @param html_table $table The table to append the row of data to
* @param string $first The first column text
* @param string $second The second column text
* @param string $third The third column text
* @return void
*/
private function add_table_row_triple(html_table $table, $first, $second, $third) {
$row = new html_table_row();
$cell1 = new html_table_cell($first);
$cell2 = new html_table_cell($second);
$cell3 = new html_table_cell($third);
$row->cells = array($cell1, $cell2, $cell3);
$table->data[] = $row;
}

/**
* Method to check if an adhoc task for distributing unallocated users has already been queued.
*
Expand Down

0 comments on commit 2bec4c3

Please sign in to comment.