Skip to content

Commit

Permalink
MDL-53638 mod_feedback: convert to moodleforms
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Apr 27, 2016
1 parent ffee513 commit 97d71cb
Show file tree
Hide file tree
Showing 30 changed files with 2,193 additions and 1,614 deletions.
38 changes: 11 additions & 27 deletions mod/feedback/analysis.php
Expand Up @@ -36,16 +36,15 @@
require_course_login($course, true, $cm);

$feedback = $PAGE->activityrecord;
$feedbackstructure = new mod_feedback_structure($feedback, $cm);

$context = context_module::instance($cm->id);

if (!feedback_can_view_analysis($feedback, $context)) {
if (!$feedbackstructure->can_view_analysis()) {
print_error('error');
}

/// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback");

$PAGE->set_heading($course->fullname);
$PAGE->set_title($feedback->name);
Expand All @@ -57,9 +56,8 @@


//get the groupid
$myurl = $CFG->wwwroot.'/mod/feedback/analysis.php?id='.$cm->id.'&do_show=analysis';
$mygroupid = groups_get_activity_group($cm, true);
groups_print_activity_menu($cm, $myurl);
groups_print_activity_menu($cm, $url);

if ( has_capability('mod/feedback:viewreports', $context) ) {
//button "export to excel"
Expand All @@ -69,17 +67,15 @@
echo $OUTPUT->container_end();
}

//get completed feedbacks
$completedscount = feedback_get_completeds_group_count($feedback, $mygroupid);
// Get completed feedbacks.
$completedcount = $feedbackstructure->count_completed_responses($mygroupid);

echo '<div class="analysis_header">';
// Show the submissions count.
echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />';

// get the items of the feedback
$items = $DB->get_records('feedback_item',
array('feedback'=>$feedback->id, 'hasvalue'=>1),
'position');
// Get the items of the feedback.
$items = $feedbackstructure->get_items(true);
// Show the items count.
if (is_array($items)) {
echo '<b>'.get_string('questions', 'feedback').': ' .count($items). ' </b><hr />';
Expand All @@ -90,30 +86,18 @@

$check_anonymously = true;
if ($mygroupid > 0 AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES) {
if ($completedscount < FEEDBACK_MIN_ANONYMOUS_COUNT_IN_GROUP) {
if ($completedcount < FEEDBACK_MIN_ANONYMOUS_COUNT_IN_GROUP) {
$check_anonymously = false;
}
}

echo '<div>';
if ($check_anonymously) {
$itemnr = 0;
//print the items in an analysed form
// Print the items in an analysed form.
foreach ($items as $item) {
if ($item->hasvalue == 0) {
continue;
}
echo '<table width="100%" class="generalbox">';

//get the class of item-typ
echo '<table class="analysis">';
$itemobj = feedback_get_item_class($item->typ);

$itemnr++;
if ($feedback->autonumbering) {
$printnr = $itemnr.'.';
} else {
$printnr = '';
}
$printnr = ($feedback->autonumbering && $item->itemnr) ? ($item->itemnr . '.') : '';
$itemobj->print_analysed($item, $printnr, $mygroupid);
echo '</table>';
}
Expand Down
51 changes: 16 additions & 35 deletions mod/feedback/analysis_course.php
Expand Up @@ -49,26 +49,19 @@
}
$PAGE->set_url($url);

if (! $cm = get_coursemodule_from_id('feedback', $id)) {
print_error('invalidcoursemodule');
}

if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf');
}

if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
print_error('invalidcoursemodule');
}

list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
$context = context_module::instance($cm->id);

require_login($course, true, $cm);
require_course_login($course, true, $cm);

$feedback = $PAGE->activityrecord;

if (!($feedback->publish_stats OR has_capability('mod/feedback:viewreports', $context))) {
print_error('error');
}

$feedbackstructure = new mod_feedback_structure($feedback, $PAGE->cm, $courseid);

/// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback");
Expand Down Expand Up @@ -96,14 +89,13 @@
//lstgroupid is the choosen id
$mygroupid = false;
//get completed feedbacks
$completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $courseid);
$completedcount = $feedbackstructure->count_completed_responses();

//show the count
echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />';

// get the items of the feedback
$params = array('feedback' => $feedback->id, 'hasvalue' => 1);
$items = $DB->get_records('feedback_item', $params, 'position');
// Get the items of the feedback.
$items = $feedbackstructure->get_items(true);
//show the count
if (is_array($items)) {
echo '<b>'.get_string('questions', 'feedback').': ' .count($items). ' </b><hr />';
Expand All @@ -123,8 +115,6 @@
echo '<div class="clearfix">';
echo '<table>';
echo '<tr><th>Course</th><th>Average</th></tr>';
$sep_dec = get_string('separator_decimal', 'feedback');
$sep_thous = get_string('separator_thousand', 'feedback');

foreach ($courses as $c) {
$coursecontext = context_course::instance($c->course_id);
Expand All @@ -133,7 +123,7 @@
echo '<tr>';
echo '<td>'.$shortname.'</td>';
echo '<td align="right">';
echo number_format(($c->sumvalue / $c->countvalue), 2, $sep_dec, $sep_thous);
echo format_float(($c->sumvalue / $c->countvalue), 2);
echo '</td>';
echo '</tr>';
}
Expand Down Expand Up @@ -182,23 +172,14 @@

echo '</form>';
echo '</div>';
echo '<hr />';
$itemnr = 0;
//print the items in an analysed form

// Print the items in an analysed form.
foreach ($items as $item) {
if ($item->hasvalue == 0) {
continue;
}
echo '<table>';
//get the class from item-typ
echo '<table class="analysis">';
echo "<tr><td colspan=\"2\" class=\"analysis_separator\"><hr></td></tr>";
$itemobj = feedback_get_item_class($item->typ);
$itemnr++;
if ($feedback->autonumbering) {
$printnr = $itemnr.'.';
} else {
$printnr = '';
}
$itemobj->print_analysed($item, $printnr, $mygroupid, $courseid);
$printnr = ($feedback->autonumbering && $item->itemnr) ? ($item->itemnr . '.') : '';
$itemobj->print_analysed($item, $printnr, $mygroupid, $feedbackstructure->get_courseid());
if (preg_match('/rated$/i', $item->typ)) {
$url = new moodle_url('/mod/feedback/analysis_course.php', array('id' => $id,
'courseitemfilter' => $item->id, 'courseitemfiltertyp' => $item->typ));
Expand Down
7 changes: 4 additions & 3 deletions mod/feedback/analysis_to_excel.php
Expand Up @@ -54,6 +54,7 @@
$context = context_module::instance($cm->id);

require_login($course, true, $cm);
$feedbackstructure = new mod_feedback_structure($feedback, $PAGE->cm, $coursefilter);

require_capability('mod/feedback:viewreports', $context);

Expand All @@ -78,8 +79,8 @@
ob_end_clean();

//get the questions (item-names)
$params = array('feedback' => $feedback->id, 'hasvalue' => 1);
if (!$items = $DB->get_records('feedback_item', $params, 'position')) {
$items = $feedbackstructure->get_items(true);
if (!$items) {
print_error('no_items_available_yet',
'feedback',
$CFG->wwwroot.'/mod/feedback/view.php?id='.$id);
Expand Down Expand Up @@ -139,7 +140,7 @@
//print the analysed sheet
////////////////////////////////////////////////////////////////////////
//get the completeds
$completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $coursefilter);
$completedscount = $feedbackstructure->count_completed_responses($mygroupid);
if ($completedscount > 0) {
//write the count of completeds
$row_offset1++;
Expand Down

0 comments on commit 97d71cb

Please sign in to comment.