Skip to content

Commit

Permalink
add groupname to the view for each groupmember at give_rating, check …
Browse files Browse the repository at this point in the history
…that user to group mapping is unique in the teamvotegrouping
  • Loading branch information
irinahpe committed May 6, 2024
1 parent 0531657 commit 9768092
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 44 deletions.
4 changes: 4 additions & 0 deletions lang/en/ratingallocate.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@
$string['your_allocated_choice'] = 'Your Allocation';
$string['you_are_not_allocated'] = 'You were not allocated to any choice!';
$string['your_rating'] = 'Your Rating';
$string['rating_for_team'] = 'Rating for Group {$a}';
$string['edit_rating'] = 'Edit Rating';
$string['delete_rating'] = 'Delete Rating';
$string['results_not_yet_published'] = 'Results have not yet been published.';
$string['no_choice_to_rate'] = 'There are no choices to rate!';
$string['too_few_choices_to_rate'] = 'There are too few choices to rate! Students have to rank at least {$a} choices!';
$string['at_least_one_rateable_choices_needed'] = 'You need at least one rateable choice.';
$string['no_rating_possible'] = 'Currently, there is no rating possible!';
$string['no_member_of_team'] = 'This Ratingallocate requires voting in groups. You are not a member of any group, so you cannot submit a rating. Please contact your teacher to be added to a group.';
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Administrator View">
$string['allocation_manual_explain_only_raters'] = 'Select a choice to be assigned to a user.
Expand Down Expand Up @@ -305,9 +307,11 @@
$string['teamvote_help'] = 'If enabled, students will be divided into groups based on the default set of groups or a custom grouping. A group rating will count for all group members.';
$string['teamvotegroupingid'] = 'Grouping for student groups';
$string['teamvotegroupingid_help'] = 'This is the grouping that the activity will use to find groups for student groups. If not set, the default set of groups will be used.';
$string['user_with_multiple_groups'] = 'Users have to be uniquely mapped to a group in a Group-Voting grouping. There might be users who are members of multiple groups in the selected grouping. Please modify the groups in the course settings or choose another grouping.';
$string['teamvote_altered_after_preferences'] = 'Group Voting settings cannot be changed after preferences were submitted';
$string['preventvotenotingroup'] = 'Require group to vote';
$string['preventvotenotingroup_help'] = 'If enabled, users who are not members of a group will be unable to give a rating.';
$string['teams'] = 'Team';

$string['err_required'] = 'You need to provide a value for this field.';
$string['err_minimum'] = 'The minimum value for this field is {$a}.';
Expand Down
72 changes: 30 additions & 42 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,39 +325,43 @@ private function process_action_give_rating() {
if (!$DB->record_exists('ratingallocate_choices', array('ratingallocateid' => $this->ratingallocateid))) {
$renderer->add_notification(get_string('no_choice_to_rate', RATINGALLOCATE_MOD_NAME));
} else if ($status === self::DISTRIBUTION_STATUS_RATING_IN_PROGRESS) {
// Rating is possible...

// Adde votegroup name zu form.
if ($this->db->get_field(this_db\ratingallocate::TABLE, 'preventvotenotingroup', ['id' => $this->ratingallocateid]) == 1
&& !$this->get_vote_group($USER->id)) {
$renderer->add_notification(get_string('no_member_of_team', RATINGALLOCATE_MOD_NAME));
} else {
// Rating is possible...

// Suche das richtige Formular nach Strategie.
$strategyform = 'ratingallocate\\' . $this->ratingallocate->strategy . '\\mod_ratingallocate_view_form';
// Suche das richtige Formular nach Strategie.
$strategyform = 'ratingallocate\\' . $this->ratingallocate->strategy . '\\mod_ratingallocate_view_form';

$mform = new $strategyform($PAGE->url->out(), $this);
$mform->add_action_buttons();
$mform = new $strategyform($PAGE->url->out(), $this);
$mform->add_action_buttons();

if ($mform->is_cancelled()) {
// Return to view.
redirect("$CFG->wwwroot/mod/ratingallocate/view.php?id=" . $this->coursemodule->id);
return "";
} else if ($mform->is_submitted() && $mform->is_validated() && $data = $mform->get_data()) {
// Save submitted data and call default page.
$this->save_ratings_to_db($USER->id, $data->data);
if ($mform->is_cancelled()) {
// Return to view.
redirect("$CFG->wwwroot/mod/ratingallocate/view.php?id=" . $this->coursemodule->id);
return "";
} else if ($mform->is_submitted() && $mform->is_validated() && $data = $mform->get_data()) {
// Save submitted data and call default page.
$this->save_ratings_to_db($USER->id, $data->data);

// Return to view.
redirect(
// Return to view.
redirect(
"$CFG->wwwroot/mod/ratingallocate/view.php?id=" . $this->coursemodule->id,
get_string('ratings_saved', RATINGALLOCATE_MOD_NAME),
null, \core\output\notification::NOTIFY_SUCCESS
);
}
);
}

$mform->definition_after_data();
$mform->definition_after_data();

$output .= $renderer->render_ratingallocate_strategyform($mform);
// Logging.
$event = \mod_ratingallocate\event\rating_viewed::create_simple(
$output .= $renderer->render_ratingallocate_strategyform($mform);
// Logging.
$event = \mod_ratingallocate\event\rating_viewed::create_simple(
context_module::instance($this->coursemodule->id), $this->ratingallocateid);
$event->trigger();
$event->trigger();
}
}
}
return $output;
Expand Down Expand Up @@ -1230,6 +1234,7 @@ public function handle_view() {
$choicestatus->showuserinfo = has_capability('mod/ratingallocate:give_rating', $this->context, null, false);
$choicestatus->algorithmstarttime = $this->ratingallocate->algorithmstarttime;
$choicestatus->algorithmstatus = $this->get_algorithm_status();
$choicestatus->teamid = $this->get_vote_group($USER->id)->id;
$choicestatusoutput = $renderer->render($choicestatus);
} else {
$choicestatusoutput = "";
Expand Down Expand Up @@ -1359,36 +1364,19 @@ public function add_groupid_to_ratings($userid, $groupid) {

public function delete_groups_for_usersnogroup($usergroups) {

$sql = 'SELECT id FROM {groups} WHERE id IN ( :groups ) AND idnumber = :ratingallocateid AND name = :name';
$sql = 'SELECT id FROM {groups} WHERE id IN ( :groups ) AND idnumber = :ratingallocateid AND name = :name AND courseid = :courseid';
$delgroups = $this->db->get_records_sql($sql, [
'groups' => implode(" , ", array_keys($usergroups)),
'ratingallocateid' => $this->ratingallocateid,
'name' => 'delete after algorithm run'
'name' => 'delete after algorithm run',
'courseid' => $this->ratingallocate->course
]);
foreach ($delgroups as $group) {
groups_delete_group($group);
}

}

/**
* Returns the group in the teamvotegrouping this user is a member of.
* (Should return only one groupid, please only call if teamvote is enabled).
*
* @param $userid
* @return false|mixed The groupid
* @throws dml_exception
*/
public function get_teamvotegroup_for_user($userid) {

$sql = 'SELECT gm.groupid FROM {groups_members} gm INNER JOIN {groupings_groups} gg ON gm.groupid=gg.groupid
INNER JOIN {ratingallocate} r ON gg.groupingid=r.teamvotegroupingid
WHERE gm.userid = :userid AND r.id = :ratingallocateid';
$groupid = $this->db->get_record_sql($sql, ['userid' => $userid, 'ratingallocateid' => $this->ratingallocateid]);
return $groupid->groupid;

}

/**
* distribution of choices for each user
* take care about max_execution_time and memory_limit
Expand Down
15 changes: 15 additions & 0 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public function definition_after_data() {
* Checks that accesstimestart is before accesstimestop
*/
public function validation($data, $files) {
global $COURSE;
$errors = parent::validation($data, $files);

if ($data['accesstimestop'] <= $data['accesstimestart']) {
Expand Down Expand Up @@ -332,6 +333,20 @@ public function validation($data, $files) {
}
}
}

// Check if group-user allocation in teamvotegrouping is 1:1.
$usersingrouping = groups_get_grouping_members($data['teamvotegroupingid'], 'u.id');
$userinmultipleteams = false;
foreach ($usersingrouping as $user) {
if (count(groups_get_user_groups($COURSE->id, $user)[$data['teamvotegroupingid']]) > 1) {
$userinmultipleteams = true;
break;
}
}
if ($userinmultipleteams) {
$errors['teamvotegroupingid'] = get_string('user_with_multiple_groups', self::MOD_NAME);
}

return $errors;
}

Expand Down
1 change: 1 addition & 0 deletions renderable.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ class ratingallocate_choice_status implements renderable {
public $showuserinfo;
public $algorithmstarttime;
public $algorithmstatus;
public $teamid;
}
15 changes: 13 additions & 2 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ public function render_ratingallocate_header(ratingallocate_header $header) {
*/
public function render_ratingallocate_strategyform($mform) {
$o = '';
$o .= $this->heading(get_string('your_rating', RATINGALLOCATE_MOD_NAME), 2);

if ($teamid = $mform->get_teamid()) {
$o .= $this->heading(get_string('rating_for_team', RATINGALLOCATE_MOD_NAME, groups_get_group_name($teamid)), 2);
} else {
var_dump($teamid);
$o .= $this->heading(get_string('your_rating', RATINGALLOCATE_MOD_NAME), 2);
}
$o .= $this->format_text($mform->get_strategy_description_header() . '<br/>' . $mform->describe_strategy());
$o .= $mform->to_html();

Expand Down Expand Up @@ -134,7 +140,12 @@ public function render_ratingallocate_choice_status(ratingallocate_choice_status
// Print own choices or full list of available choices.
if (!empty($status->ownchoices) && $status->showuserinfo && $accesstimestart < $time) {
$row = new html_table_row();
$cell1 = new html_table_cell(get_string('your_rating', RATINGALLOCATE_MOD_NAME));

if ($status->teamid) {
$cell1 = new html_table_cell(get_string('rating_for_team', RATINGALLOCATE_MOD_NAME, groups_get_group_name($status->teamid)));
} else {
$cell1 = new html_table_cell(get_string('your_rating', RATINGALLOCATE_MOD_NAME));
}

$choiceshtml = array();
foreach ($status->ownchoices as $choice) {
Expand Down
9 changes: 9 additions & 0 deletions strategy/strategy_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,16 @@ abstract class ratingallocate_strategyform extends \moodleform {

private $strategy;

private $teamid;

/**
*
* @param string $url The page url
* @param \ratingallocate $ratingallocate The calling ratingallocate instance
*/
public function __construct($url, \ratingallocate $ratingallocate) {
global $USER;

$this->ratingallocate = $ratingallocate;
// Load strategy options.
$allstrategyoptions = json_decode($this->ratingallocate->ratingallocate->setting, true);
Expand All @@ -212,6 +216,7 @@ public function __construct($url, \ratingallocate $ratingallocate) {
$this->strategyoptions = array();
}
$this->strategy = $this->construct_strategy($this->strategyoptions);
$this->teamid = $ratingallocate->get_vote_group($USER->id)->id;
parent::__construct($url);
}

Expand All @@ -228,6 +233,10 @@ protected function get_strategy() {
return $this->strategy;
}

public function get_teamid() {
return $this->teamid;
}

/**
* inherited from moodleform: a child class must call parent::definition() first to execute
* ratingallocate_strategyform::definition
Expand Down

0 comments on commit 9768092

Please sign in to comment.