Example #1
0
 /**
  * Define the elements to be displayed at the form
  *
  * Called by the parent::definition()
  *
  * @return void
  */
 protected function definition_inner(&$mform)
 {
     $fields = $this->_customdata['fields'];
     $current = $this->_customdata['current'];
     $nodims = $this->_customdata['nodims'];
     // number of assessment dimensions
     $mform->addElement('hidden', 'nodims', $nodims);
     $mform->setType('nodims', PARAM_INT);
     for ($i = 0; $i < $nodims; $i++) {
         // dimension header
         $dimtitle = get_string('dimensionnumber', 'workshopform_accumulative', $i + 1);
         $mform->addElement('header', 'dimensionhdr__idx_' . $i, $dimtitle);
         // dimension id
         $mform->addElement('hidden', 'dimensionid__idx_' . $i, $fields->{'dimensionid__idx_' . $i});
         $mform->setType('dimensionid__idx_' . $i, PARAM_INT);
         // grade id
         $mform->addElement('hidden', 'gradeid__idx_' . $i);
         // value set by set_data() later
         $mform->setType('gradeid__idx_' . $i, PARAM_INT);
         // dimension description
         $desc = '<div id="id_dim_' . $fields->{'dimensionid__idx_' . $i} . '_desc" class="fitem description accumulative">' . "\n";
         $desc .= format_text($fields->{'description__idx_' . $i}, $fields->{'description__idx_' . $i . 'format'});
         $desc .= "\n</div>";
         $mform->addElement('html', $desc);
         // grade for this aspect
         $label = get_string('dimensiongrade', 'workshopform_accumulative');
         $options = make_grades_menu($fields->{'grade__idx_' . $i});
         $mform->addElement('select', 'grade__idx_' . $i, $label, $options);
         // comment
         $label = get_string('dimensioncomment', 'workshopform_accumulative');
         //$mform->addElement('editor', 'peercomment__idx_' . $i, $label, null, array('maxfiles' => 0));
         $mform->addElement('textarea', 'peercomment__idx_' . $i, $label, array('cols' => 60, 'rows' => 5));
     }
     $this->set_data($current);
 }
 /**
  * Defines the elements of the form used to mark a quiz submission.
  */
 public function definition()
 {
     global $OUTPUT;
     $mform =& $this->_form;
     $mform->addElement('hidden', 'attemptid');
     $mform->setType('attemptid', PARAM_INT);
     $mform->addElement('hidden', 'questionid');
     $mform->setType('questionid', PARAM_INT);
     $mform->addElement('hidden', 'sesskey', sesskey());
     $mform->setType('sesskey', PARAM_ALPHANUM);
     $mform->addElement('static', 'picture', $OUTPUT->user_picture($this->_customdata->user), fullname($this->_customdata->user, true) . '<br/>' . userdate($this->_customdata->submission->timemodified) . $this->_customdata->lateness);
     // Now come multiple (possibly) question comment fields.
     // Use $attemptobj->get_questions($arrayofquestionis) for this.
     foreach ($this->_customdata->questions as $questionid => $question) {
         $mform->addElement('header', 'question' . $questionid, get_string('question', 'modulename'));
         // Display question text.
         // Display user's answer.
         // Display comment form.
         $mform->addElement('editor', 'comment[' . $questionid . ']', get_string('comment', 'quiz') . ':', null, $this->get_editor_options());
         // Display grade selector.
         $grademenu = make_grades_menu($question->grade);
         $grademenu['-1'] = get_string('nograde');
         // TODO broken!
         $attributes = array();
         $mform->addElement('select', 'grade[' . $questionid . ']', get_string('grade') . ':', $grademenu, $attributes);
         // TODO set default to existing grade?
         $mform->setDefault('grade[' . $questionid . ']', -1);
     }
 }
 function definition()
 {
     $mform =& $this->_form;
     $qcreate = $this->_customdata['qcreate'];
     if ($qcreate->graderatio != 100) {
         //--------------------------------------------------------------------------------
         $mform->addElement('header', 'exportselection', get_string('exportselection', 'qcreate'));
         $menu = make_grades_menu($qcreate->grade);
         unset($menu[0]);
         $menu += array(0 => get_string('allquestions', 'qcreate'));
         $mform->addElement('select', 'betterthangrade', get_string('betterthangrade', 'qcreate'), $menu);
         $mform->setDefault('betterthangrade', 0);
     }
     $mform->addElement('header', 'exportnaming', get_string('exportnaming', 'qcreate'));
     $cbarray3 = array();
     $cbarray3[] =& MoodleQuickForm::createElement('checkbox', 'naming[other]', '', get_string('specifictext', 'qcreate'));
     $cbarray3[] =& MoodleQuickForm::createElement('text', 'naming[othertext]');
     $mform->addGroup($cbarray3, 'naming3', '', array(' '), false);
     $mform->disabledIf('naming3', 'naming[other]');
     $cbarray1 = array();
     $cbarray1[] =& MoodleQuickForm::createElement('checkbox', 'naming[firstname]', '', get_string('firstname'));
     $cbarray1[] =& MoodleQuickForm::createElement('checkbox', 'naming[lastname]', '', get_string('lastname'));
     $cbarray1[] =& MoodleQuickForm::createElement('checkbox', 'naming[username]', '', get_string('username', 'qcreate'));
     $mform->addGroup($cbarray1, 'naming1', '', array(' '), false);
     $cbarray2 = array();
     $cbarray2[] =& MoodleQuickForm::createElement('checkbox', 'naming[activityname]', '', get_string('activityname', 'qcreate'));
     $cbarray2[] =& MoodleQuickForm::createElement('checkbox', 'naming[timecreated]', '', get_string('timecreated', 'qcreate'));
     $mform->addGroup($cbarray2, 'naming2', '', array(' '), false);
     parent::definition();
 }
Example #4
0
File: lib.php Project: r007/PMoodle
function journal_user_complete_index($course, $user, $journal, $journalopen, $heading)
{
    /// Prints a journal, entry and feedback ... used on the journal index page.
    if (isteacher($course->id)) {
        $entrycount = journal_count_entries($journal, get_current_group($course->id));
        $entryinfo = "&nbsp;(<a href=\"report.php?id={$journal->coursemodule}\">" . get_string("viewallentries", "journal", $entrycount) . "</a>)";
    } else {
        $entryinfo = "";
    }
    $journal->name = "<a href=\"view.php?id={$journal->coursemodule}\">" . format_string($journal->name, true) . "</a>";
    if ($heading) {
        echo "<h3>{$heading} - {$journal->name}{$entryinfo}</h3>";
    } else {
        echo "<h3>{$journal->name}{$entryinfo}</h3>";
    }
    print_simple_box_start("left", "90%");
    echo format_text($journal->intro, $journal->introformat);
    print_simple_box_end();
    echo "<br clear=\"all\" />";
    echo "<br />";
    if (isstudent($course->id) or isteacher($course->id)) {
        print_simple_box_start("right", "90%");
        if ($journalopen) {
            echo "<p align=\"right\"><a href=\"edit.php?id={$journal->coursemodule}\">";
            echo get_string("edit") . "</a></p>";
        } else {
            echo "<p align=\"right\"><a href=\"view.php?id={$journal->coursemodule}\">";
            echo get_string("view") . "</a></p>";
        }
        if ($entry = get_record("journal_entries", "userid", $user->id, "journal", $journal->id)) {
            if ($entry->modified) {
                echo "<p align=\"center\"><font size=\"1\">" . get_string("lastedited") . ": " . userdate($entry->modified) . "</font></p>";
            }
            if ($entry->text) {
                echo format_text($entry->text, $entry->format);
            }
            if ($entry->teacher) {
                $grades = make_grades_menu($journal->assessed);
                journal_print_feedback($course, $entry, $grades);
            }
        } else {
            print_string("noentry", "journal");
        }
        print_simple_box_end();
        echo "<br clear=\"all\" />";
        echo "<br />";
    }
}
 /**
  * Define the form - called by parent constructor
  */
 function definition()
 {
     global $CFG;
     $mform = $this->_form;
     list($geogebra, $data, $params) = $this->_customdata;
     // visible elements
     $this->geogebra = $geogebra;
     $attemptelement = $mform->addElement('text', 'attempt', get_string('attempt', 'geogebra'), array('style' => 'border:none'));
     $mform->setType('attempt', PARAM_TEXT);
     $attemptelement->freeze();
     $durationelement = $mform->addElement('text', 'duration', get_string('duration', 'geogebra'), array('style' => 'border:none'));
     $mform->setType('duration', PARAM_TEXT);
     $durationelement->freeze();
     if ($geogebra->grade > 0) {
         $gradingelement = $mform->addElement('text', 'grade', get_string('grade', 'geogebra'));
         $mform->setType('grade', PARAM_TEXT);
     } else {
         $grademenu = make_grades_menu($geogebra->grade);
         if (count($grademenu) > 0) {
             $grademenu = array(RATING_UNSET_RATING => get_string('rate', 'rating') . '...') + $grademenu;
             $gradingelement = $mform->addElement('select', 'grade', get_string('grade') . ':', $grademenu);
             // The grade is already formatted with format_float so it needs to be converted back to an integer.
             if (!empty($data->grade)) {
                 $data->grade = (int) unformat_float($data->grade);
             }
             $mform->setType('grade', PARAM_INT);
         }
     }
     $mform->addElement('editor', 'comment_editor', get_string('comment', 'geogebra'), null, null);
     $mform->setType('comment_editor', PARAM_RAW);
     // Hidden parameters
     $mform->addElement('hidden', 'id', $data->id);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'student', $data->student);
     $mform->setType('student', PARAM_INT);
     $mform->addElement('hidden', 'attemptid', $data->attemptid);
     $mform->setType('attemptid', PARAM_INT);
     $mform->addElement('hidden', 'action', 'submitgrade');
     $mform->setType('action', PARAM_ALPHA);
     // Buttons
     $this->add_action_buttons(true, get_string('savechanges', 'assign'));
     $mform->closeHeaderBefore('buttonar');
     if ($data) {
         $this->set_data($data);
     }
 }
 protected function add_grades_section()
 {
     global $CFG;
     $mform = $this->_form;
     $mform->addElement('header', 'Grades', get_string('grades', 'grades'));
     $grademenu = make_grades_menu($this->_customdata['gradesetting']);
     $mform->addElement('select', 'xgrade', get_string('grade') . ':', $grademenu);
     $mform->setType('xgrade', PARAM_INT);
     $course = $this->_customdata['course'];
     $context = context_course::instance($course->id);
     if (has_capability('gradereport/grader:view', $context) && has_capability('moodle/grade:viewall', $context)) {
         $grade = '<a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '" >' . $this->_customdata['str_grade'] . '</a>';
     } else {
         $grade = $this->_customdata['str_grade'];
     }
     $mform->addElement('static', 'finalgrade', get_string('currentgrade', 'assignment') . ':', $grade);
     $mform->setType('finalgrade', PARAM_INT);
 }
Example #7
0
 /**
  * Define the elements to be displayed at the form
  *
  * Called by the parent::definition()
  *
  * @return void
  */
 protected function definition_inner(&$mform)
 {
     $fields = $this->_customdata['fields'];
     $current = $this->_customdata['current'];
     $nodims = $this->_customdata['nodims'];
     // number of assessment dimensions
     $mform->addElement('hidden', 'nodims', $nodims);
     $mform->setType('nodims', PARAM_INT);
     // minimal grade value to select - used by the 'compare' rule below
     // (just an implementation detail to make the rule work, this element is
     // not processed by the server)
     $mform->addElement('hidden', 'minusone', -1);
     $mform->setType('minusone', PARAM_INT);
     for ($i = 0; $i < $nodims; $i++) {
         // dimension header
         $dimtitle = get_string('dimensionnumber', 'workshopform_accumulative', $i + 1);
         $mform->addElement('header', 'dimensionhdr__idx_' . $i, $dimtitle);
         // dimension id
         $mform->addElement('hidden', 'dimensionid__idx_' . $i, $fields->{'dimensionid__idx_' . $i});
         $mform->setType('dimensionid__idx_' . $i, PARAM_INT);
         // grade id
         $mform->addElement('hidden', 'gradeid__idx_' . $i);
         // value set by set_data() later
         $mform->setType('gradeid__idx_' . $i, PARAM_INT);
         // dimension description
         $desc = '<div id="id_dim_' . $fields->{'dimensionid__idx_' . $i} . '_desc" class="fitem description accumulative">' . "\n";
         $desc .= format_text($fields->{'description__idx_' . $i}, $fields->{'description__idx_' . $i . 'format'});
         $desc .= "\n</div>";
         $mform->addElement('html', $desc);
         // grade for this aspect
         $label = get_string('dimensiongrade', 'workshopform_accumulative');
         $options = make_grades_menu($fields->{'grade__idx_' . $i});
         $options = array('-1' => get_string('choosedots')) + $options;
         $mform->addElement('select', 'grade__idx_' . $i, $label, $options);
         $mform->addRule(array('grade__idx_' . $i, 'minusone'), get_string('mustchoosegrade', 'workshopform_accumulative'), 'compare', 'gt');
         // comment
         $label = get_string('dimensioncomment', 'workshopform_accumulative');
         //$mform->addElement('editor', 'peercomment__idx_' . $i, $label, null, array('maxfiles' => 0));
         $mform->addElement('textarea', 'peercomment__idx_' . $i, $label, array('cols' => 60, 'rows' => 5));
     }
     $this->set_data($current);
 }
 /**
  * Wrapper for Moodle function that caches result, so can be called
  * without worry of a performance impact.
  * @param int $gradingtype Grading type value
  * @return array Array from value=>name
  */
 public static function make_grades_menu($gradingtype)
 {
     if (!array_key_exists($gradingtype, self::$scales)) {
         self::$scales[$gradingtype] = make_grades_menu($gradingtype);
     }
     return self::$scales[$gradingtype];
 }
Example #9
0
 /**
  * Calculates and returns the possible minimum and maximum score (in points) for this guide
  *
  * @return array
  */
 public function get_min_max_score()
 {
     if (!$this->is_form_available()) {
         return null;
     }
     $returnvalue = array('minscore' => 0, 'maxscore' => 0);
     $maxscore = 0;
     foreach ($this->get_definition()->guide_criteria as $id => $criterion) {
         $maxscore += $criterion['maxscore'];
     }
     $returnvalue['maxscore'] = $maxscore;
     $returnvalue['minscore'] = 0;
     if (!empty($this->moduleinstance->grade)) {
         $graderange = make_grades_menu($this->moduleinstance->grade);
         $returnvalue['modulegrade'] = count($graderange) - 1;
     }
     return $returnvalue;
 }
Example #10
0
function taoview_print_artefacts($artefacts, $viewtype, $tagfilter, $userfilter, $sort, $page, $perpage)
{
    global $CFG, $USER;
    //get scale
    $scale = get_record("scale", "name", 'TAO: Stars');
    $artefacts = taoview_get_paginated_results($artefacts, $page, $perpage);
    foreach ($artefacts as $artefact) {
        if ($perpage <= 0) {
            //not a great way to paginate.
            break;
        }
        echo '<div class="taoview">';
        if (!empty($artefact['thumbnail'])) {
            echo '<div class="taoview-thumb"><img src="' . $artefact['thumbnail'] . '"></div>';
        }
        echo '<div class="taoview-download"><a href="' . $artefact['download'] . '" target="_blank">' . $artefact['name'] . '</a></div>';
        if (!empty($artefact['uploader'])) {
            $user = get_record('user', 'username', $artefact['uploader']);
            if (!empty($user)) {
                echo '<div class="taoview-user">' . get_string('submittedby', 'local') . ': <a href="' . $CFG->wwwroot . '/local/mahara/taoview' . $viewtype . '.php?tag=' . $tagfilter . '&filteruser='******'uploader'] . '&sort=' . $sort . '">' . fullname($user) . '</a></div>';
            }
        }
        if (!empty($artefact['ctime'])) {
            echo '<div class="taoview-date">' . $artefact['ctime'] . '</div>';
        }
        if (!empty($artefact['description'])) {
            echo '<div class="taoview-desc">' . $artefact['description'] . '</div>';
        }
        if (!empty($artefact['tags']) && is_array($artefact['tags'])) {
            echo '<div class="taoview-tags">' . get_string('tags') . ': ';
            foreach ($artefact['tags'] as $tag) {
                echo '<a href="' . $CFG->wwwroot . '/local/mahara/taoview' . $viewtype . '.php?tag=' . $tag . '&sort=' . $sort . '">' . $tag . '</a>, ';
            }
            echo '</div>';
        }
        //now do ratings stuff
        echo '<div class="ratings">';
        $possiblevalues = make_grades_menu(-$scale->id);
        echo '<span class="taoviewratingtext">';
        tao_print_ratings($artefact['id'], $possiblevalues);
        echo '</span>';
        if (!empty($user) && $user->id != $USER->id && !isguest()) {
            tao_print_rating_menu($artefact['id'], $USER->id, $possiblevalues);
        }
        echo '</div>';
        //end of ratings stuff
        if (!empty($artefact['page'])) {
            echo '<div class="taoview-page"><a href="' . $artefact['page'] . '">' . get_string('moreinfo', 'local') . '</a></div>';
        }
        echo '</div>';
        $perpage--;
    }
    if (!empty($artefacts) && !isguest()) {
        echo "<div class=\"boxaligncenter\"><input id=\"taoviewratingsubmit\" type=\"submit\" value=\"" . get_string("sendinratings", "local") . "\" />";
        if (ajaxenabled()) {
            /// AJAX enabled, standard submission form
            $rate_ajax_config_settings = array("pixpath" => $CFG->pixpath, "wwwroot" => $CFG->wwwroot, "sesskey" => sesskey());
            echo "<script type=\"text/javascript\">//<![CDATA[\n" . "var rate_ajax_config = " . json_encode($rate_ajax_config_settings) . ";\n" . "init_rate_ajax();\n" . "//]]></script>\n";
        }
        //print_scale_menu_helpbutton(SITEID, $scale); //no help file written yet.
        echo "</div>";
    }
}
Example #11
0
    error("You do not have the capability to view post ratings");
}
if (!has_capability('mod/forum:viewanyrating', $context) and $USER->id != $post->userid) {
    error("You can only look at results for posts that you made");
}
switch ($sort) {
    case 'firstname':
        $sqlsort = "u.firstname ASC";
        break;
    case 'rating':
        $sqlsort = "r.rating ASC";
        break;
    default:
        $sqlsort = "r.time ASC";
}
$scalemenu = make_grades_menu($forum->scale);
$strratings = get_string('ratings', 'forum');
$strrating = get_string('rating', 'forum');
$strname = get_string('name');
$strtime = get_string('time');
print_header("{$strratings}: " . format_string($post->subject));
if (!($ratings = forum_get_ratings($post->id, $sqlsort))) {
    error("No ratings for this post: \"" . format_string($post->subject) . "\"");
} else {
    echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" class=\"generalbox\" style=\"width:100%\">";
    echo "<tr>";
    echo "<th class=\"header\" scope=\"col\">&nbsp;</th>";
    echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id={$post->id}&amp;sort=firstname\">{$strname}</a></th>";
    echo "<th class=\"header\" scope=\"col\" style=\"width:100%\"><a href=\"report.php?id={$post->id}&amp;sort=rating\">{$strrating}</a></th>";
    echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id={$post->id}&amp;sort=time\">{$strtime}</a></th>";
    echo "</tr>";
Example #12
0
 /**
  *  Display all the submissions ready for grading
  *
  * @global object
  * @global object
  * @global object
  * @global object
  * @param string $message
  * @return bool|void
  */
 function display_submissions($message = '')
 {
     global $CFG, $DB, $USER, $DB, $OUTPUT;
     require_once $CFG->libdir . '/gradelib.php';
     /* first we check to see if the form has just been submitted
      * to request user_preference updates
      */
     if (isset($_POST['updatepref'])) {
         $perpage = optional_param('perpage', 10, PARAM_INT);
         $perpage = $perpage <= 0 ? 10 : $perpage;
         set_user_preference('assignment_perpage', $perpage);
         set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));
     }
     /* next we get perpage and quickgrade (allow quick grade) params
      * from database
      */
     $perpage = get_user_preferences('assignment_perpage', 10);
     $quickgrade = get_user_preferences('assignment_quickgrade', 0);
     $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);
     if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
         $uses_outcomes = true;
     } else {
         $uses_outcomes = false;
     }
     $page = optional_param('page', 0, PARAM_INT);
     $strsaveallfeedback = get_string('saveallfeedback', 'assignment');
     /// Some shortcuts to make the code read better
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $tabindex = 1;
     //tabindex for quick grading tabbing; Not working for dropdowns yet
     add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->cm->id, $this->assignment->id, $this->cm->id);
     $navigation = build_navigation($this->strsubmissions, $this->cm);
     print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm));
     $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
     if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
         echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">' . get_string('seeallcoursegrades', 'grades') . '</a></div>';
     }
     if (!empty($message)) {
         echo $message;
         // display messages here if any
     }
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     /// Check to see if groups are being used in this assignment
     /// find out current groups mode
     $groupmode = groups_get_activity_groupmode($cm);
     $currentgroup = groups_get_activity_group($cm, true);
     groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id);
     /// Get all ppl that are allowed to submit assignments
     if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
         $users = array_keys($users);
     }
     // if groupmembersonly used, remove users who are not in any group
     if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
         if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
             $users = array_intersect($users, array_keys($groupingusers));
         }
     }
     $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
     if ($uses_outcomes) {
         $tablecolumns[] = 'outcome';
         // no sorting based on outcomes column
     }
     $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified') . ' (' . get_string('submission', 'assignment') . ')', get_string('lastmodified') . ' (' . get_string('grade') . ')', get_string('status'), get_string('finalgrade', 'grades'));
     if ($uses_outcomes) {
         $tableheaders[] = get_string('outcome', 'grades');
     }
     require_once $CFG->libdir . '/tablelib.php';
     $table = new flexible_table('mod-assignment-submissions');
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $table->define_baseurl($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;currentgroup=' . $currentgroup);
     $table->sortable(true, 'lastname');
     //sorted by lastname by default
     $table->collapsible(true);
     $table->initialbars(true);
     $table->column_suppress('picture');
     $table->column_suppress('fullname');
     $table->column_class('picture', 'picture');
     $table->column_class('fullname', 'fullname');
     $table->column_class('grade', 'grade');
     $table->column_class('submissioncomment', 'comment');
     $table->column_class('timemodified', 'timemodified');
     $table->column_class('timemarked', 'timemarked');
     $table->column_class('status', 'status');
     $table->column_class('finalgrade', 'finalgrade');
     if ($uses_outcomes) {
         $table->column_class('outcome', 'outcome');
     }
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'attempts');
     $table->set_attribute('class', 'submissions');
     $table->set_attribute('width', '100%');
     //$table->set_attribute('align', 'center');
     $table->no_sorting('finalgrade');
     $table->no_sorting('outcome');
     // Start working -- this is necessary as soon as the niceties are over
     $table->setup();
     if (empty($users)) {
         echo $OUTPUT->heading(get_string('nosubmitusers', 'assignment'));
         return true;
     }
     /// Construct the SQL
     if ($where = $table->get_sql_where()) {
         $where .= ' AND ';
     }
     if ($sort = $table->get_sql_sort()) {
         $sort = ' ORDER BY ' . $sort;
     }
     $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
                       s.id AS submissionid, s.grade, s.submissioncomment,
                       s.timemodified, s.timemarked,
                       COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';
     $sql = 'FROM {user} u ' . 'LEFT JOIN {assignment_submissions} s ON u.id = s.userid
                                                               AND s.assignment = ' . $this->assignment->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') ';
     $table->pagesize($perpage, count($users));
     ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
     $offset = $page * $perpage;
     $strupdate = get_string('update');
     $strgrade = get_string('grade');
     $grademenu = make_grades_menu($this->assignment->grade);
     if (($ausers = $DB->get_records_sql($select . $sql . $sort, null, $table->get_page_start(), $table->get_page_size())) !== false) {
         $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
         foreach ($ausers as $auser) {
             $final_grade = $grading_info->items[0]->grades[$auser->id];
             $grademax = $grading_info->items[0]->grademax;
             $final_grade->formatted_grade = round($final_grade->grade, 2) . ' / ' . round($grademax, 2);
             $locked_overridden = 'locked';
             if ($final_grade->overridden) {
                 $locked_overridden = 'overridden';
             }
             /// Calculate user status
             $auser->status = $auser->timemarked > 0 && $auser->timemarked >= $auser->timemodified;
             $picture = $OUTPUT->user_picture(moodle_user_picture::make($auser, $course->id));
             if (empty($auser->submissionid)) {
                 $auser->grade = -1;
                 //no submission yet
             }
             if (!empty($auser->submissionid)) {
                 ///Prints student answer and student modified date
                 ///attach file or print link to student answer, depending on the type of the assignment.
                 ///Refer to print_student_answer in inherited classes.
                 if ($auser->timemodified > 0) {
                     $studentmodified = '<div id="ts' . $auser->id . '">' . $this->print_student_answer($auser->id) . userdate($auser->timemodified) . '</div>';
                 } else {
                     $studentmodified = '<div id="ts' . $auser->id . '">&nbsp;</div>';
                 }
                 ///Print grade, dropdown or text
                 if ($auser->timemarked > 0) {
                     $teachermodified = '<div id="tt' . $auser->id . '">' . userdate($auser->timemarked) . '</div>';
                     if ($final_grade->locked or $final_grade->overridden) {
                         $grade = '<div id="g' . $auser->id . '" class="' . $locked_overridden . '">' . $final_grade->formatted_grade . '</div>';
                     } else {
                         if ($quickgrade) {
                             $select = html_select::make(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'));
                             $select->nothingvalue = '-1';
                             $select->tabindex = $tabindex++;
                             $menu = $OUTPUT->select($select);
                             $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>';
                         } else {
                             $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                         }
                     }
                 } else {
                     $teachermodified = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                     if ($final_grade->locked or $final_grade->overridden) {
                         $grade = '<div id="g' . $auser->id . '" class="' . $locked_overridden . '">' . $final_grade->formatted_grade . '</div>';
                     } else {
                         if ($quickgrade) {
                             $select = html_select::make(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'));
                             $select->nothingvalue = '-1';
                             $select->tabindex = $tabindex++;
                             $menu = $OUTPUT->select($select);
                             $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>';
                         } else {
                             $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                         }
                     }
                 }
                 ///Print Comment
                 if ($final_grade->locked or $final_grade->overridden) {
                     $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($final_grade->str_feedback), 15) . '</div>';
                 } else {
                     if ($quickgrade) {
                         $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>';
                     } else {
                         $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($auser->submissioncomment), 15) . '</div>';
                     }
                 }
             } else {
                 $studentmodified = '<div id="ts' . $auser->id . '">&nbsp;</div>';
                 $teachermodified = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                 $status = '<div id="st' . $auser->id . '">&nbsp;</div>';
                 if ($final_grade->locked or $final_grade->overridden) {
                     $grade = '<div id="g' . $auser->id . '">' . $final_grade->formatted_grade . '</div>';
                 } else {
                     if ($quickgrade) {
                         // allow editing
                         $select = html_select::make(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'));
                         $select->nothingvalue = '-1';
                         $select->tabindex = $tabindex++;
                         $menu = $OUTPUT->select($select);
                         $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>';
                     } else {
                         $grade = '<div id="g' . $auser->id . '">-</div>';
                     }
                 }
                 if ($final_grade->locked or $final_grade->overridden) {
                     $comment = '<div id="com' . $auser->id . '">' . $final_grade->str_feedback . '</div>';
                 } else {
                     if ($quickgrade) {
                         $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>';
                     } else {
                         $comment = '<div id="com' . $auser->id . '">&nbsp;</div>';
                     }
                 }
             }
             if (empty($auser->status)) {
                 /// Confirm we have exclusively 0 or 1
                 $auser->status = 0;
             } else {
                 $auser->status = 1;
             }
             $buttontext = $auser->status == 1 ? $strupdate : $strgrade;
             ///No more buttons, we use popups ;-).
             $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&userid=' . $auser->id . '&mode=single' . '&offset=' . $offset++;
             $link = html_link::make($popup_url, $buttontext);
             $link->add_action(new popup_action('click', $link->url, 'grade' . $auser->id, array('height' => 600, 'width' => 700)));
             $link->title = $buttontext;
             $button = $OUTPUT->link($link);
             $status = '<div id="up' . $auser->id . '" class="s' . $auser->status . '">' . $button . '</div>';
             $finalgrade = '<span id="finalgrade_' . $auser->id . '">' . $final_grade->str_grade . '</span>';
             $outcomes = '';
             if ($uses_outcomes) {
                 foreach ($grading_info->outcomes as $n => $outcome) {
                     $outcomes .= '<div class="outcome"><label>' . $outcome->name . '</label>';
                     $options = make_grades_menu(-$outcome->scaleid);
                     if ($outcome->grades[$auser->id]->locked or !$quickgrade) {
                         $options[0] = get_string('nooutcome', 'grades');
                         $outcomes .= ': <span id="outcome_' . $n . '_' . $auser->id . '">' . $options[$outcome->grades[$auser->id]->grade] . '</span>';
                     } else {
                         $outcomes .= ' ';
                         $select = html_select::make($options, 'outcome_' . $n . '[' . $auser->id . ']', $outcome->grades[$auser->id]->grade, get_string('nooutcome', 'grades'));
                         $select->nothingvalue = '0';
                         $select->tabindex = $tabindex++;
                         $select->id = 'outcome_' . $n . '_' . $auser->id;
                         $outcomes .= $OUTPUT->select($select);
                     }
                     $outcomes .= '</div>';
                 }
             }
             $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&amp;course=' . $course->id . '">' . fullname($auser) . '</a>';
             $row = array($picture, $userlink, $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade);
             if ($uses_outcomes) {
                 $row[] = $outcomes;
             }
             $table->add_data($row);
         }
     }
     /// Print quickgrade form around the table
     if ($quickgrade) {
         echo '<form action="submissions.php" id="fastg" method="post">';
         echo '<div>';
         echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />';
         echo '<input type="hidden" name="mode" value="fastgrade" />';
         echo '<input type="hidden" name="page" value="' . $page . '" />';
         echo '</div>';
     }
     $table->print_html();
     /// Print the whole table
     if ($quickgrade) {
         $lastmailinfo = get_user_preferences('assignment_mailinfo', 1) ? 'checked="checked"' : '';
         echo '<div class="fgcontrols">';
         echo '<div class="emailnotification">';
         echo '<label for="mailinfo">' . get_string('enableemailnotification', 'assignment') . '</label>';
         echo '<input type="hidden" name="mailinfo" value="0" />';
         echo '<input type="checkbox" id="mailinfo" name="mailinfo" value="1" ' . $lastmailinfo . ' />';
         echo $OUTPUT->help_icon(moodle_help_icon::make('emailnotification', get_string('enableemailnotification', 'assignment'), 'assignment')) . '</p></div>';
         echo '</div>';
         echo '<div class="fastgbutton"><input type="submit" name="fastg" value="' . get_string('saveallfeedback', 'assignment') . '" /></div>';
         echo '</div>';
         echo '</form>';
     }
     /// End of fast grading form
     /// Mini form for setting user preference
     echo '<div class="qgprefs">';
     echo '<form id="options" action="submissions.php?id=' . $this->cm->id . '" method="post"><div>';
     echo '<input type="hidden" name="updatepref" value="1" />';
     echo '<table id="optiontable">';
     echo '<tr><td>';
     echo '<label for="perpage">' . get_string('pagesize', 'assignment') . '</label>';
     echo '</td>';
     echo '<td>';
     echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />';
     echo $OUTPUT->help_icon(moodle_help_icon::make('pagesize', get_string('pagesize', 'assignment'), 'assignment'));
     echo '</td></tr>';
     echo '<tr><td>';
     echo '<label for="quickgrade">' . get_string('quickgrade', 'assignment') . '</label>';
     echo '</td>';
     echo '<td>';
     $checked = $quickgrade ? 'checked="checked"' : '';
     echo '<input type="checkbox" id="quickgrade" name="quickgrade" value="1" ' . $checked . ' />';
     echo $OUTPUT->help_icon(moodle_help_icon::make('quickgrade', get_string('quickgrade', 'assignment'), 'assignment')) . '</p></div>';
     echo '</td></tr>';
     echo '<tr><td colspan="2">';
     echo '<input type="submit" value="' . get_string('savepreferences') . '" />';
     echo '</td></tr></table>';
     echo '</div></form></div>';
     ///End of mini form
     echo $OUTPUT->footer();
 }
Example #13
0
    function add_grades_section() {
        global $CFG;
        $mform =& $this->_form;
        $attributes = array();
        if ($this->_customdata->gradingdisabled) {
            $attributes['disabled'] ='disabled';
        }

        $grademenu = make_grades_menu($this->_customdata->assignment->grade);
        $grademenu['-1'] = get_string('nograde');

        $mform->addElement('header', 'Grades', get_string('grades', 'grades'));
        $mform->addElement('select', 'xgrade', get_string('grade').':', $grademenu, $attributes);
        $mform->setDefault('xgrade', $this->_customdata->submission->grade ); //@fixme some bug when element called 'grade' makes it break
        $mform->setType('xgrade', PARAM_INT);

        if (!empty($this->_customdata->enableoutcomes)) {
            foreach($this->_customdata->grading_info->outcomes as $n=>$outcome) {
                $options = make_grades_menu(-$outcome->scaleid);
                if ($outcome->grades[$this->_customdata->submission->userid]->locked) {
                    $options[0] = get_string('nooutcome', 'grades');
                    echo $options[$outcome->grades[$this->_customdata->submission->userid]->grade];
                } else {
                    $options[''] = get_string('nooutcome', 'grades');
                    $attributes = array('id' => 'menuoutcome_'.$n );
                    $mform->addElement('select', 'outcome_'.$n.'['.$this->_customdata->userid.']', $outcome->name.':', $options, $attributes );
                    $mform->setType('outcome_'.$n.'['.$this->_customdata->userid.']', PARAM_INT);
                    $mform->setDefault('outcome_'.$n.'['.$this->_customdata->userid.']', $outcome->grades[$this->_customdata->submission->userid]->grade );
                }
            }
        }
        $course_context = get_context_instance(CONTEXT_MODULE , $this->_customdata->cm->id);
        if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
            $grade = '<a href="'.$CFG->wwwroot.'/grade/report/grader/index.php?id='. $this->_customdata->courseid .'" >'.
                        $this->_customdata->grading_info->items[0]->grades[$this->_customdata->userid]->str_grade . '</a>';
        }else{
            $grade = $this->_customdata->grading_info->items[0]->grades[$this->_customdata->userid]->str_grade;
        }
        $mform->addElement('static', 'finalgrade', get_string('currentgrade', 'assignment').':' ,$grade);
        $mform->setType('finalgrade', PARAM_INT);
    }
Example #14
0
    /**
     * add elements to grade form
     *
     * @param MoodleQuickForm $mform
     * @param stdClass $data
     * @param array $params
     * @return void
     */
    public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data, $params) {
        global $USER, $CFG;
        $settings = $this->get_instance();

        $rownum = $params['rownum'];
        $last = $params['last'];
        $useridlist = $params['useridlist'];
        $userid = $useridlist[$rownum];
        $grade = $this->get_user_grade($userid, false);

        // add advanced grading
        $gradingdisabled = $this->grading_disabled($userid);
        $gradinginstance = $this->get_grading_instance($userid, $gradingdisabled);

        if ($gradinginstance) {
            $gradingelement = $mform->addElement('grading', 'advancedgrading', get_string('grade').':', array('gradinginstance' => $gradinginstance));
            if ($gradingdisabled) {
                $gradingelement->freeze();
            } else {
                $mform->addElement('hidden', 'advancedgradinginstanceid', $gradinginstance->get_id());
            }
        } else {
            // use simple direct grading
            if ($this->get_instance()->grade > 0) {
                $gradingelement = $mform->addElement('text', 'grade', get_string('gradeoutof', 'assign',$this->get_instance()->grade));
                $mform->addHelpButton('grade', 'gradeoutofhelp', 'assign');
                $mform->setType('grade', PARAM_TEXT);
                if ($gradingdisabled) {
                    $gradingelement->freeze();
                }
            } else {
                $grademenu = make_grades_menu($this->get_instance()->grade);
                if (count($grademenu) > 0) {
                    $gradingelement = $mform->addElement('select', 'grade', get_string('grade').':', $grademenu);
                    $mform->setType('grade', PARAM_INT);
                    if ($gradingdisabled) {
                        $gradingelement->freeze();
                    }
                }
            }
        }

        $gradinginfo = grade_get_grades($this->get_course()->id,
                                        'mod',
                                        'assign',
                                        $this->get_instance()->id,
                                        $userid);
        if (!empty($CFG->enableoutcomes)) {
            foreach($gradinginfo->outcomes as $index=>$outcome) {
                $options = make_grades_menu(-$outcome->scaleid);
                if ($outcome->grades[$userid]->locked) {
                    $options[0] = get_string('nooutcome', 'grades');
                    $mform->addElement('static', 'outcome_'.$index.'['.$userid.']', $outcome->name.':',
                            $options[$outcome->grades[$userid]->grade]);
                } else {
                    $options[''] = get_string('nooutcome', 'grades');
                    $attributes = array('id' => 'menuoutcome_'.$index );
                    $mform->addElement('select', 'outcome_'.$index.'['.$userid.']', $outcome->name.':', $options, $attributes );
                    $mform->setType('outcome_'.$index.'['.$userid.']', PARAM_INT);
                    $mform->setDefault('outcome_'.$index.'['.$userid.']', $outcome->grades[$userid]->grade );
                }
            }
        }

        if (has_all_capabilities(array('gradereport/grader:view', 'moodle/grade:viewall'), $this->get_course_context())) {
            $gradestring = $this->output->action_link(new moodle_url('/grade/report/grader/index.php',
                                                              array('id'=>$this->get_course()->id)),
                                                $gradinginfo->items[0]->grades[$userid]->str_grade);
        } else {
            $gradestring = $gradinginfo->items[0]->grades[$userid]->str_grade;
        }
        $mform->addElement('static', 'finalgrade', get_string('currentgrade', 'assign').':', $gradestring);


        $mform->addElement('static', 'progress', '', get_string('gradingstudentprogress', 'assign', array('index'=>$rownum+1, 'count'=>count($useridlist))));

        // plugins
        $this->add_plugin_grade_elements($grade, $mform, $data);

        // hidden params
        $mform->addElement('hidden', 'id', $this->get_course_module()->id);
        $mform->setType('id', PARAM_INT);
        $mform->addElement('hidden', 'rownum', $rownum);
        $mform->setType('rownum', PARAM_INT);
        $mform->addElement('hidden', 'useridlist', implode(',', $useridlist));
        $mform->setType('useridlist', PARAM_TEXT);
        $mform->addElement('hidden', 'ajax', optional_param('ajax', 0, PARAM_INT));
        $mform->setType('ajax', PARAM_INT);

        if ($this->get_instance()->teamsubmission) {
            $mform->addElement('selectyesno', 'applytoall', get_string('applytoteam', 'assign'));
            $mform->setDefault('applytoall', 1);
        }

        $mform->addElement('hidden', 'action', 'submitgrade');
        $mform->setType('action', PARAM_ALPHA);


        $buttonarray=array();
        $buttonarray[] = $mform->createElement('submit', 'savegrade', get_string('savechanges', 'assign'));
        if (!$last) {
            $buttonarray[] = $mform->createElement('submit', 'saveandshownext', get_string('savenext','assign'));
        }
        $buttonarray[] = $mform->createElement('cancel', 'cancelbutton', get_string('cancel'));
        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
        $mform->closeHeaderBefore('buttonar');
        $buttonarray=array();

        if ($rownum > 0) {
            $buttonarray[] = $mform->createElement('submit', 'nosaveandprevious', get_string('previous','assign'));
        }

        if (!$last) {
            $buttonarray[] = $mform->createElement('submit', 'nosaveandnext', get_string('nosavebutnext', 'assign'));
        }
        $mform->addGroup($buttonarray, 'navar', '', array(' '), false);
    }
Example #15
0
     }
     $discussions[$post->discussion] = $discussion;
 } else {
     $discussion = $discussions[$post->discussion];
 }
 if (!isset($forums[$discussion->forum])) {
     if (!($forum = get_record('forum', 'id', $discussion->forum))) {
         error("Could not find forum {$discussion->forum}");
     }
     $forums[$discussion->forum] = $forum;
 } else {
     $forum = $forums[$discussion->forum];
 }
 $ratings = null;
 if ($forum->assessed) {
     if ($scale = make_grades_menu($forum->scale)) {
         $ratings = new object();
         $ratings->scale = $scale;
         $ratings->assesstimestart = $forum->assesstimestart;
         $ratings->assesstimefinish = $forum->assesstimefinish;
         $ratings->allow = false;
     }
 }
 if (!isset($cms[$forum->id])) {
     if (!($cm = get_coursemodule_from_instance('forum', $forum->id))) {
         error('Course Module ID was incorrect');
     }
     $cms[$forum->id] = $cm;
     unset($cm);
     // do not use cm directly, it would break caching
 }
Example #16
0
    function view_feedback($submission=NULL) {
        global $USER, $CFG, $DB, $OUTPUT, $PAGE;
        require_once($CFG->libdir.'/gradelib.php');
        require_once("$CFG->dirroot/grade/grading/lib.php");

        if (!$submission) { /// Get submission for this assignment
            $userid = $USER->id;
            $submission = $this->get_submission($userid);
        } else {
            $userid = $submission->userid;
        }

        // Check the user can submit
        $canviewfeedback = ($userid == $USER->id && has_capability('mod/assignment:submit', $this->context, $USER->id, false));
        // If not then check if the user still has the view cap and has a previous submission
        $canviewfeedback = $canviewfeedback || (!empty($submission) && $submission->userid == $USER->id && has_capability('mod/assignment:view', $this->context));
        // Or if user can grade (is a teacher or admin)
        $canviewfeedback = $canviewfeedback || has_capability('mod/assignment:grade', $this->context);

        if (!$canviewfeedback) {
            // can not view or submit assignments -> no feedback
            return;
        }

        $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $userid);
        $item = $grading_info->items[0];
        $grade = $item->grades[$userid];

        if ($grade->hidden or $grade->grade === false) { // hidden or error
            return;
        }

        if ($grade->grade === null and empty($grade->str_feedback)) {   // No grade to show yet
            if ($this->count_responsefiles($userid)) {   // but possibly response files are present
                echo $OUTPUT->heading(get_string('responsefiles', 'assignment'), 3);
                $responsefiles = $this->print_responsefiles($userid, true);
                echo $OUTPUT->box($responsefiles, 'generalbox boxaligncenter');
            }
            return;
        }

        $graded_date = $grade->dategraded;
        $graded_by   = $grade->usermodified;

    /// We need the teacher info
        if (!$teacher = $DB->get_record('user', array('id'=>$graded_by))) {
            print_error('cannotfindteacher');
        }

    /// Print the feedback
        echo $OUTPUT->heading(get_string('submissionfeedback', 'assignment'), 3);

        echo '<table cellspacing="0" class="feedback">';

        echo '<tr>';
        echo '<td class="left picture">';
        echo $OUTPUT->user_picture($teacher);
        echo '</td>';
        echo '<td class="topic">';
        echo '<div class="from">';
        echo '<div class="fullname">'.fullname($teacher).'</div>';
        echo '<div class="time">'.userdate($graded_date).'</div>';
        echo '</div>';
        echo '</td>';
        echo '</tr>';

        echo '<tr>';
        echo '<td class="left side">&nbsp;</td>';
        echo '<td class="content">';
        $gradestr = '<div class="grade">'. get_string("grade").': '.$grade->str_long_grade. '</div>';
        if (!empty($submission) && $controller = get_grading_manager($this->context, 'mod_assignment', 'submission')->get_active_controller()) {
            $controller->set_grade_range(make_grades_menu($this->assignment->grade));
            echo $controller->render_grade($PAGE, $submission->id, $item, $gradestr, has_capability('mod/assignment:grade', $this->context));
        } else {
            echo $gradestr;
        }
        echo '<div class="clearer"></div>';

        echo '<div class="comment">';
        echo $grade->str_feedback;
        echo '</div>';
        echo '</tr>';

        echo '<tr>';
        echo '<td class="left side">&nbsp;</td>';
        echo '<td class="content">';
        echo $this->print_responsefiles($userid, true);
        echo '</tr>';

        echo '</table>';
    }
 function display_submissions($message = '')
 {
     global $CFG, $db, $USER;
     require_once $CFG->libdir . '/gradelib.php';
     // Update preferences
     if (isset($_POST['updatepref'])) {
         $perpage = optional_param('perpage', 20, PARAM_INT);
         $perpage = $perpage <= 0 ? 20 : $perpage;
         set_user_preference('assignment_perpage', $perpage);
         $moderationtarget = optional_param('moderationtarget', 0, PARAM_INT);
         $moderationtarget = $moderationtarget <= 0 ? 0 : $moderationtarget;
         set_user_preference('assignment_moderationtarget', $moderationtarget);
     }
     // Get preferences
     $perpage = get_user_preferences('assignment_perpage', 10);
     $moderationtarget = get_user_preferences('assignment_moderationtarget', 0);
     // Some shortcuts to make the code read better
     $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     $page = optional_param('page', 0, PARAM_INT);
     // Log this view
     add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
     // Print header and navigation breadcrumbs
     $navigation = build_navigation($this->strsubmissions, $this->cm);
     print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm));
     // Print tabs at top of page
     $tabs = array();
     $row = array();
     $inactive = array();
     $activated = array();
     $row[] = new tabobject('criteria', "type/peerreview/" . self::CRITERIA_FILE . "?id=" . $this->cm->id . "&a=" . $this->assignment->id, get_string('criteria', 'assignment_peerreview'));
     $row[] = new tabobject('submissions', '', get_string('submissions', 'assignment_peerreview'));
     $tabs[] = $row;
     $currenttab = 'submissions';
     $inactive[] = 'submissions';
     $activated[] = 'submissions';
     print_tabs($tabs, $currenttab, $inactive, $activated);
     // Print optional message
     if (!empty($message)) {
         echo $message;
         // display messages here if any
     }
     // Check to see if groups are being used in this assignment
     // find out current groups mode
     // $groupmode = groups_get_activity_groupmode($cm);
     // $currentgroup = groups_get_activity_group($cm, true);
     // groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/assignment/submissions.php?id=' . $cm->id);
     // Get all ppl that are allowed to submit assignments
     // if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id', '', '', '', $currentgroup, '', false)) {
     if ($users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id')) {
         $users = array_keys($users);
     }
     // Filter out teachers
     if ($users && ($teachers = get_users_by_capability($context, 'mod/assignment:grade', 'u.id'))) {
         $users = array_diff($users, array_keys($teachers));
     }
     // Warn if class is too small
     if (count($users) < 5) {
         notify(get_string('numberofstudentswarning', 'assignment_peerreview'));
     }
     // if groupmembersonly used, remove users who are not in any group
     // if ($users and !empty($CFG->enablegroupings) and $cm->groupmembersonly) {
     // if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
     // $users = array_intersect($users, array_keys($groupingusers));
     // }
     // }
     // Create the table to be shown
     require_once $CFG->libdir . '/tablelib.php';
     $table = new flexible_table('mod-assignment-submissions');
     $tablecolumns = array('picture', 'fullname', 'submitted', 'reviews', 'moderations', 'status', 'seedoreviews', 'suggestedmark', 'finalgrade');
     $table->define_columns($tablecolumns);
     $tableheaders = array('', get_string('fullname'), get_string('submission', 'assignment_peerreview'), get_string('reviewsbystudent', 'assignment_peerreview') . helpbutton('reviewsbystudent', get_string('reviewsbystudent', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('moderationstitle', 'assignment_peerreview') . helpbutton('moderationtarget', get_string('moderationtarget', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('status') . helpbutton('status', get_string('status', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('seedoreviews', 'assignment_peerreview') . helpbutton('seedoreviews', get_string('seedoreviews', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('suggestedgrade', 'assignment_peerreview') . helpbutton('suggestedgrade', get_string('suggestedgrade', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true), get_string('finalgrade', 'assignment_peerreview') . helpbutton('finalgrade', get_string('finalgrade', 'assignment_peerreview'), 'assignment/type/peerreview/', true, false, '', true));
     $table->define_headers($tableheaders);
     // $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id.'&amp;currentgroup='.$currentgroup);
     $table->define_baseurl($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id);
     // $table->sortable(true, 'submitted');
     $table->sortable(false);
     $table->collapsible(true);
     // $table->initialbars(true);
     $table->initialbars(false);
     $table->column_suppress('picture');
     $table->column_suppress('fullname');
     $table->column_class('picture', 'picture');
     $table->column_class('fullname', 'fullname');
     $table->column_class('submitted', 'submitted');
     $table->column_class('reviews', 'reviews');
     $table->column_class('moderations', 'moderations');
     $table->column_class('status', 'status');
     $table->column_class('seedoreviews', 'seedoreviews');
     $table->column_class('suggestedmark', 'suggestedmark');
     $table->column_class('finalgrade', 'finalgrade');
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'attempts');
     $table->set_attribute('class', 'submissions');
     $table->set_attribute('width', '99%');
     $table->set_attribute('align', 'center');
     $table->column_style('submitted', 'text-align', $alignment);
     $table->column_style('finalgrade', 'text-align', 'center');
     /*
     		$table->no_sorting('picture');
     		$table->no_sorting('fullname');
     		$table->no_sorting('submitted');
     		$table->no_sorting('reviews');
     		$table->no_sorting('moderations');
     		$table->no_sorting('status');
     		$table->no_sorting('seedoreviews');
     		$table->no_sorting('suggestedmark');
     		$table->no_sorting('finalgrade');
     */
     $table->setup();
     if (empty($users)) {
         print_heading(get_string('nosubmitusers', 'assignment'));
         return true;
     }
     // Construct the SQL
     if ($where = $table->get_sql_where()) {
         $where .= ' AND ';
     }
     $select = 'SELECT u.id, u.firstname, u.lastname, u.picture, u.imagealt,
                       s.id AS submissionid, s.grade,
                       s.timecreated as submitted, s.timemarked ';
     $sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'assignment_submissions s ON u.id=s.userid AND s.assignment=' . $this->assignment->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') ';
     $sort = 'ORDER BY COALESCE(submitted,2147483647) ASC, submissionid ASC, u.lastname ASC';
     // if ($sort = $table->get_sql_sort()) {
     // $sort = ' ORDER BY '.$sort;
     // }
     $table->pagesize($perpage, count($users));
     ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
     $offset = $page * $perpage;
     $strupdate = get_string('update');
     $strgrade = get_string('grade');
     $grademenu = make_grades_menu($this->assignment->grade);
     // Get the criteria
     $criteriaList = get_records_list('assignment_criteria', 'assignment', $this->assignment->id, 'ordernumber');
     $numberOfCriteria = 0;
     if (is_array($criteriaList)) {
         $criteriaList = array_values($criteriaList);
         $numberOfCriteria = count($criteriaList);
     }
     if (($ausers = get_records_sql($select . $sql . $sort, $table->get_page_start(), $table->get_page_size())) !== false) {
         //            $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
         foreach ($ausers as $auser) {
             //              $final_grade = $grading_info->items[0]->grades[$auser->id];
             // Calculate user status
             $auser->status = $auser->timemarked > 0;
             $picture = print_user_picture($auser, $course->id, $auser->picture, false, true);
             $studentName = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $this->course->id . '">' . fullname($auser) . '</a>';
             // If submission has been made
             if (!empty($auser->submissionid)) {
                 $filearea = $this->file_area_name($auser->id);
                 $fileLink = '';
                 if (isset($this->assignment->var3) && $this->assignment->var3 == self::ONLINE_TEXT) {
                     $url = '/mod/assignment/type/peerreview/' . self::VIEW_ONLINE_TEXT . '?id=' . $this->cm->id . '&a=' . $this->assignment->id . '&userid=' . $auser->id . '&view=moderation';
                     $fileLink .= '<a href="' . $CFG->wwwroot . $url . '" target="_blank" onclick="return openpopup(\'' . $url . '\',\'\',\'menubar=0,location=0,scrollbars,resizable,width=500,height=400\');"><img src="' . $CFG->pixpath . '/f/html.gif" /></a>';
                 } else {
                     $basedir = $this->file_area($auser->id);
                     if ($files = get_directory_list($basedir)) {
                         require_once $CFG->libdir . '/filelib.php';
                         foreach ($files as $key => $file) {
                             $icon = mimeinfo('icon', $file);
                             $ffurl = get_file_url("{$filearea}/{$file}", array('forcedownload' => 1));
                             $fileLink .= '<a href="' . $ffurl . '" ><img src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" /></a>';
                         }
                     }
                 }
                 $submitted = '<div class="files" style="display:inline;">' . $fileLink . '</div><div style="display:inline;" id="tt' . $auser->id . '">' . userdate($auser->submitted, get_string('strftimeintable', 'assignment_peerreview')) . '</div>';
                 $submitted .= ' <a href="' . $CFG->wwwroot . '/mod/assignment/type/peerreview/' . self::RESUBMIT_FILE . '?id=' . $this->cm->id . '&a=' . $this->assignment->id . '&userid=' . $auser->id . '">(' . get_string('resubmitlabel', 'assignment_peerreview') . ')</a>';
                 // Reviews by student
                 $numberOfReviewsByThisStudent = 0;
                 if ($reviewsByThisStudent = get_records_select('assignment_review', 'assignment=\'' . $this->assignment->id . '\' AND reviewer=\'' . $auser->id . '\' AND complete=\'1\'')) {
                     $numberOfReviewsByThisStudent = count($reviewsByThisStudent);
                     $reviewsByThisStudent = array_values($reviewsByThisStudent);
                     $reviews = '<div style="text-align:center;" id="re' . $auser->id . '">';
                     for ($i = 0; $i < $numberOfReviewsByThisStudent; $i++) {
                         $reviews .= '<span id="rev' . $reviewsByThisStudent[$i]->id . '"  style="padding:5px 2px;">';
                         $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;userid=' . $reviewsByThisStudent[$i]->reviewee . '&amp;mode=single&amp;offset=1';
                         $reviews .= element_to_popup_window('button', $popup_url, 'grade' . $auser->id, $i + 1, 600, 780, $i + 1, 'none', true, 'user' . $auser->id . 'rev' . $i);
                         $reviews .= '</span>';
                         // $reviews .= $i<$numberOfReviewsByThisStudent-1?', ':'';
                     }
                     $reviews .= '</div>';
                     $reviews .= '<script>';
                     for ($i = 0; $i < $numberOfReviewsByThisStudent; $i++) {
                         $reviews .= 'document.getElementById(\'user' . $auser->id . 'rev' . $i . '\').setAttribute(\'onmouseover\',\'document.getElementById("se' . $reviewsByThisStudent[$i]->reviewee . '").style.background="#ff9999";\');';
                         $reviews .= 'document.getElementById(\'user' . $auser->id . 'rev' . $i . '\').setAttribute(\'onmouseout\',\'document.getElementById("se' . $reviewsByThisStudent[$i]->reviewee . '").style.background="transparent";\');';
                     }
                     $reviews .= '</script>';
                 } else {
                     $reviews = '<div id="re' . $auser->id . '">&nbsp;</div>';
                 }
                 // Reviews of student
                 $reviewsOfThisStudent = $this->get_reviews_of_student($auser->id);
                 $numberOfReviewsOfThisStudent = 0;
                 if (is_array($reviewsOfThisStudent)) {
                     $numberOfReviewsOfThisStudent = count($reviewsOfThisStudent);
                 }
                 $statusCode = $this->get_status($reviewsOfThisStudent, $numberOfCriteria);
                 $status = '<div id="st' . $auser->id . '">' . $this->print_status($statusCode, true) . '</div>';
                 $buttontext = get_string('review', 'assignment_peerreview');
                 $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;userid=' . $auser->id . '&amp;mode=single' . '&amp;offset=' . $offset++;
                 $button = element_to_popup_window('button', $popup_url, 'grade' . $auser->id, $buttontext, 600, 780, $buttontext, 'none', true, 'reviewbutton' . $auser->id);
                 $seedoreviews = '<div id="se' . $auser->id . '" style="text-align:center;padding:5px 0;"><span  id="seOutline' . $auser->id . '" class="s' . ($statusCode <= 3 ? '0' : '1') . '" style="padding:4px 1px;">' . $button . '</span></div>';
                 $seedoreviews .= '<script>';
                 $seedoreviews .= 'document.getElementById(\'reviewbutton' . $auser->id . '\').setAttribute(\'onmouseover\',\'';
                 for ($i = 0; $i < $numberOfReviewsOfThisStudent; $i++) {
                     $seedoreviews .= 'buttonHighlight=document.getElementById("rev' . $reviewsOfThisStudent[$i]->review . '"); if(buttonHighlight) buttonHighlight.style.background="#ff9999";';
                 }
                 $seedoreviews .= '\');';
                 $seedoreviews .= 'document.getElementById(\'reviewbutton' . $auser->id . '\').setAttribute(\'onmouseout\',\'';
                 for ($i = 0; $i < $numberOfReviewsOfThisStudent; $i++) {
                     $seedoreviews .= 'buttonHighlight=document.getElementById("rev' . $reviewsOfThisStudent[$i]->review . '"); if(buttonHighlight) buttonHighlight.style.background="transparent";';
                 }
                 $seedoreviews .= '\');';
                 $seedoreviews .= '</script>';
                 // Suggest mark
                 $suggestedmark = '<div style="text-align:center;" id="su' . $auser->id . '">';
                 $suggestedMarkToDisplay = $this->get_marks($reviewsOfThisStudent, $criteriaList, $numberOfReviewsByThisStudent, $this->assignment->var1);
                 $suggestedmark .= '<input type="text" size="4" id="gvalue' . $auser->id . '" value="' . $suggestedMarkToDisplay . '" />';
                 $suggestedmark .= '<input type="button" value="' . get_string('set', 'assignment_peerreview') . '" onclick="mark=parseInt(document.getElementById(\'gvalue' . $auser->id . '\').value); if(isNaN(mark)) {alert(\'' . get_string('gradenotanumber', 'assignment_peerreview') . '\'); return false;} else {popup_url=\'/mod/assignment/type/peerreview/' . self::SET_MARK_FILE . '?id=' . $this->cm->id . '&amp;a=' . $this->assignment->id . '&amp;userid=' . $auser->id . '&amp;mark=\'+mark; return openpopup(popup_url, \'grade5\', \'menubar=0,location=0,scrollbars,resizable,width=400,height=300\', 0);}" />';
                 $suggestedmark .= '</div>';
                 // Final grade
                 if ($auser->timemarked > 0) {
                     // if ($final_grade->locked or $final_grade->overridden) {
                     // $grade = '<div id="g'.$auser->id.'">'.$final_grade->str_grade.'</div>';
                     // }
                     // else {
                     $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                     // }
                 } else {
                     $grade = '<div id="g' . $auser->id . '">' . get_string('notset', 'assignment_peerreview') . '</div>';
                 }
             } else {
                 $submitted = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                 $reviews = '<div id="re' . $auser->id . '">&nbsp;</div>';
                 $status = '<div id="st' . $auser->id . '">&nbsp;</div>';
                 $seedoreviews = '<div id="se' . $auser->id . '">&nbsp;</div>';
                 $suggestedmark = '<div id="su' . $auser->id . '">&nbsp;</div>';
                 $grade = '<div id="g' . $auser->id . '">-</div>';
             }
             $moderationCountSQL = 'SELECT count(r.id) FROM ' . $CFG->prefix . 'assignment a, ' . $CFG->prefix . 'assignment_review r WHERE a.course=' . $course->id . ' AND a.id=r.assignment AND r.teacherreview=1 AND r.reviewee=\'' . $auser->id . '\'';
             $moderationCount = count_records_sql($moderationCountSQL);
             $moderations = '<div id="mo' . $auser->id . '" style="text-align:center;">' . ($moderationCount < $moderationtarget ? '<span class="errorStatus">' . $moderationCount . '</span>' : $moderationCount) . '</div>';
             // $finalgrade = '<span id="finalgrade_'.$auser->id.'">'.$final_grade->str_grade.'</span>';
             // Add the row to the table
             $row = array($picture, $studentName, $submitted, $reviews, $moderations, $status, $seedoreviews, $suggestedmark, $grade);
             $table->add_data($row);
         }
     }
     /// Print quickgrade form around the table
     require_once $CFG->dirroot . '/mod/assignment/type/peerreview/' . self::STYLES_FILE;
     $table->print_html();
     /// Print the whole table
     /// Mini form for setting user preference
     echo '<div style="margin:5px 10px;">';
     echo '<table id="optiontable" align="right">';
     echo '<tr><td colspan="2" align="right">';
     echo '<form id="options" action="type/peerreview/' . self::MASS_MARK_FILE . '?id=' . $this->cm->id . '&a=' . $this->assignment->id . '" method="post">';
     echo '<input type="submit" value="' . get_string('massmark', 'assignment_peerreview') . '" />';
     helpbutton('massmark', get_string('massmark', 'assignment_peerreview'), 'assignment/type/peerreview/');
     echo '</form>';
     echo '<br />';
     echo '</td></tr>';
     echo '<form id="options" action="submissions.php?id=' . $this->cm->id . '" method="post">';
     echo '<input type="hidden" id="updatepref" name="updatepref" value="1" />';
     echo '<tr align="right"><td>';
     echo '<label for="perpage">' . get_string('pagesize', 'assignment') . '</label>';
     echo ':</td>';
     echo '<td>';
     echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />';
     helpbutton('pagesize', get_string('pagesize', 'assignment'), 'assignment');
     echo '</td></tr>';
     echo '<tr align="right"><td>';
     echo '<label for="moderationtarget">' . get_string('moderationtarget', 'assignment_peerreview') . '</label>';
     echo ':</td>';
     echo '<td>';
     echo '<input type="text" id="moderationtarget" name="moderationtarget" size="1" value="' . $moderationtarget . '" />';
     helpbutton('moderationtarget', get_string('moderationtargetwhy', 'assignment_peerreview'), 'assignment/type/peerreview');
     echo '</td></tr>';
     echo '<tr>';
     echo '<td colspan="2" align="right">';
     echo '<input type="submit" value="' . get_string('savepreferences') . '" />';
     echo '</form>';
     echo '</td></tr></table>';
     echo '</div>';
     ///End of mini form
     print_footer($this->course);
 }
Example #18
0
    print_error('invalidcoursemodule');
}
require_login($course, false, $cm);
if (isguestuser()) {
    print_error('guestrate', 'data');
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/data:rate', $context);
if (!$data->assessed) {
    print_error('cannotrate', 'data');
}
if (!($frmdata = data_submitted()) or !confirm_sesskey()) {
    print_error('invalidaccess', 'data');
}
/// Calculate scale values
$scale_values = make_grades_menu($data->scale);
$count = 0;
foreach ((array) $frmdata as $recordid => $rating) {
    if (!is_numeric($recordid)) {
        continue;
    }
    if (!($record = $DB->get_record('data_records', array('id' => $recordid)))) {
        print_error('invalidid', 'data');
    }
    if ($data->id != $record->dataid) {
        print_error('invalidrecord', 'data');
    }
    if ($record->userid == $USER->id) {
        continue;
    }
    /// Check rate is valid for that database scale values
Example #19
0
/// Check forum can be rated
if (!$forum->assessed) {
    print_error('norate', 'forum');
}
/// Check user can rate
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/forum:rate', $context);
/// Check timed ratings
if ($forum->assesstimestart and $forum->assesstimefinish) {
    if ($post->created < $forum->assesstimestart or $post->created > $forum->assesstimefinish) {
        // we can not rate this, ignore it - this should not happen anyway unless teacher changes setting
        print_error('norate', 'forum');
    }
}
/// Calculate scale values
$scale_values = make_grades_menu($forum->scale);
/// Check rate is valid for for that forum scale values
if (!array_key_exists($rate, $scale_values) && $rate != FORUM_UNSET_POST_RATING) {
    print_error('invalidrate', 'forum');
}
/// Everything ready, process rate
/// Deleting rate
if ($rate == FORUM_UNSET_POST_RATING) {
    $DB->delete_records('forum_ratings', array('post' => $postid, 'userid' => $USER->id));
    /// Updating rate
} else {
    if ($oldrating = $DB->get_record('forum_ratings', array('userid' => $USER->id, 'post' => $post->id))) {
        if ($rate != $oldrating->rating) {
            $oldrating->rating = $rate;
            $oldrating->time = time();
            $DB->update_record('forum_ratings', $oldrating);
Example #20
0
$glossary->cmidnumber = $cm->idnumber;
if (!$glossary->assessed) {
    print_error('nopermissiontorate');
}
if ($glossary->assessed == 2) {
    require_capability('mod/glossary:rate', $context);
}
if (!empty($_SERVER['HTTP_REFERER'])) {
    $returnurl = $_SERVER['HTTP_REFERER'];
} else {
    $returnurl = $CFG->wwwroot . '/mod/glossary/view.php?id=' . $cm->id;
}
if ($data = data_submitted()) {
    // form submitted
    /// Calculate scale values
    $scale_values = make_grades_menu($glossary->scale);
    foreach ((array) $data as $entryid => $rating) {
        if (!is_numeric($entryid)) {
            continue;
        }
        if (!($entry = $DB->get_record('glossary_entries', array('id' => $entryid)))) {
            continue;
        }
        if ($entry->glossaryid != $glossary->id) {
            print_error('invalidentry');
        }
        if ($glossary->assesstimestart and $glossary->assesstimefinish) {
            if ($entry->timecreated < $glossary->assesstimestart or $entry->timecreated > $glossary->assesstimefinish) {
                // we can not rate this, ignore it - this should not happen anyway unless teacher changes setting
                continue;
            }
Example #21
0
    }
    add_to_log($course->id, "journal", "update feedback", "report.php?id={$cm->id}", "{$count} users", $cm->id);
    notify(get_string("feedbackupdated", "journal", "{$count}"), "green");
} else {
    add_to_log($course->id, "journal", "view responses", "report.php?id={$cm->id}", "{$journal->id}", $cm->id);
}
/// Print out the journal entries
if ($currentgroup) {
    $users = get_group_users($currentgroup);
} else {
    $users = get_course_students($course->id);
}
if (!$users) {
    print_heading(get_string("nousersyet"));
} else {
    $grades = make_grades_menu($journal->assessed);
    $teachers = get_course_teachers($course->id);
    $allowedtograde = ($groupmode != VISIBLEGROUPS or isteacheredit($course->id) or ismember($currentgroup));
    if ($allowedtograde) {
        echo '<form action="report.php" method="post">';
    }
    if ($usersdone = journal_get_users_done($journal)) {
        foreach ($usersdone as $user) {
            if ($currentgroup) {
                if (!ismember($currentgroup, $user->id)) {
                    /// Yes, it's inefficient, but this module will die
                    continue;
                }
            }
            journal_print_user_entry($course, $user, $entrybyuser[$user->id], $teachers, $grades);
            unset($users[$user->id]);
Example #22
0
function data_print_ratings($data, $record)
{
    global $USER;
    $cm = get_coursemodule_from_instance('data', $data->id);
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    if ($data->assessed and !empty($USER->id) and (has_capability('mod/data:rate', $context) or has_capability('mod/data:viewrating', $context) or data_isowner($record->id))) {
        if ($ratingsscale = make_grades_menu($data->scale)) {
            $ratingsmenuused = false;
            echo '<div class="ratings" style="text-align:center">';
            echo '<form id="form" method="post" action="rate.php">';
            echo '<input type="hidden" name="dataid" value="' . $data->id . '" />';
            if (has_capability('mod/data:rate', $context) and !data_isowner($record->id)) {
                data_print_ratings_mean($record->id, $ratingsscale, has_capability('mod/data:viewrating', $context));
                echo '&nbsp;';
                data_print_rating_menu($record->id, $USER->id, $ratingsscale);
                $ratingsmenuused = true;
            } else {
                data_print_ratings_mean($record->id, $ratingsscale, true);
            }
            if ($data->scale < 0) {
                if ($scale = get_record('scale', 'id', abs($data->scale))) {
                    print_scale_menu_helpbutton($data->course, $scale);
                }
            }
            if ($ratingsmenuused) {
                echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
                echo '<input type="submit" value="' . get_string('sendinratings', 'data') . '" />';
            }
            echo '</form>';
            echo '</div>';
        }
    }
}
Example #23
0
}

if (!has_capability('moodle/rating:view',$context)) {
    print_error('noviewrate', 'rating');
}
if (!has_capability('moodle/rating:viewall',$context) and $USER->id != $item->userid) {
    print_error('noviewanyrate', 'rating');
}

switch ($sort) {
    case 'firstname': $sqlsort = "u.firstname ASC"; break;
    case 'rating':    $sqlsort = "r.rating ASC"; break;
    default:          $sqlsort = "r.timemodified ASC";
}

$scalemenu = make_grades_menu($scaleid);

$strrating  = get_string('rating', 'rating');
$strname    = get_string('name');
$strtime    = get_string('time');

$PAGE->set_title(get_string('allratingsforitem','rating'));
echo $OUTPUT->header();

$ratingoptions = new stdClass;
$ratingoptions->context = $context;
$ratingoptions->component = $component;
$ratingoptions->ratingarea = $ratingarea;
$ratingoptions->itemid = $itemid;
$ratingoptions->sort = $sqlsort;
Example #24
0
function elluminate_update_group_records($elluminate)
{
    global $DB;
    $search = array("<", "&", "\"", "#", "%");
    $replace = '';
    $originalname = $elluminate->sessionname;
    $strippedname = str_replace($search, $replace, $elluminate->sessionname);
    $parentsessionid = $elluminate->id;
    $elluminate->id = '';
    $elluminate->meetingid = null;
    $elluminate->groupparentid = $parentsessionid;
    $elluminate->meetinginit = 0;
    if ($elluminate->groupmode != 0) {
        $sessions = $DB->get_records('elluminate', array('groupparentid' => $elluminate->instance));
        $desc = $elluminate->description;
        foreach ($sessions as $session) {
            $group = $DB->get_record('groups', array('id' => $session->groupid));
            $session->name = $elluminate->name;
            $elluminate->groupid = $group->id;
            $name_string = $elluminate->name;
            if ($elluminate->customname > 0) {
                if ($elluminate->customname == 1) {
                    $name_string = $group->name;
                } else {
                    if ($elluminate->customname == 2) {
                        $name_string = $name_string . ' - ' . $group->name;
                    }
                }
                if (strlen($name_string) > 64) {
                    $stringlength = strlen($name_string);
                    $toomany = $stringlength - 64 + 5;
                    $remainder = $toomany % 2;
                    $difference = $toomany / 2;
                    $session->sessionname = substr($name_string, 0, 33 - ($difference + $remainder)) . ' ... ' . substr($name_string, 32 + $difference, $stringlength);
                } else {
                    $session->sessionname = $name_string;
                }
            } else {
                $session->sessionname = $elluminate->sessionname;
            }
            if ($elluminate->customdescription == 1) {
                $session->description = '';
                $session->description = $group->name . ' - ' . $desc;
                $session->customdescription = 1;
            } else {
                $session->description = $desc;
                $session->customdescription = 0;
            }
            $search = array("<", "&", "\"", "#", "%");
            $replace = '';
            $elluminate->sessionname = str_replace($search, $replace, $elluminate->sessionname);
            $session->customname = $elluminate->customname;
            $session->timestart = $elluminate->timestart;
            $session->timeend = $elluminate->timeend;
            $session->recordingmode = $elluminate->recordingmode;
            $session->boundarytime = $elluminate->boundarytime;
            $session->boundarytimedisplay = $elluminate->boundarytimedisplay;
            $session->maxtalkers = $elluminate->maxtalkers;
            $session->seats = $elluminate->seats;
            $session->grade = $elluminate->grade;
            $session->timemodified = $elluminate->timemodified;
            $session->groupmode = $elluminate->groupmode;
            $session->groupingid = $elluminate->groupingid;
            $session->creator = $elluminate->creator;
            $session->chairlist = $elluminate->chairlist;
            $timenow = time();
            $ss_start_time = new stdClass();
            if ($session->timestart < $timenow) {
                $starttime = userdate($elluminate->timestart);
                $boundary = userdate($elluminate->boundarytime);
                $starttime = $elluminate->timestart;
                $boundary = $elluminate->boundarytime * 60;
                $new_boundarytime = floor(($timenow - ($starttime - $boundary)) / 60);
                $minutes = date('i', $timenow);
                $millis = date('s', $timenow);
                $addminutes = 15 - $minutes % 15;
                $new_boundarytime = $new_boundarytime + $addminutes;
                $ss_start_time = $timenow + $addminutes * 60 - $millis;
            } else {
                $ss_start_time = $session->timestart;
            }
            //Update the scheduling server with changes to meetings that have a meeting id already.
            if (!empty($session->meetingid)) {
                if (!($create_result = elluminate_update_meeting($session->meetingid, $ss_start_time, $session->timeend, $session->sessionname, '', '', $session->sessiontype, $session->seats, $session->boundarytime, $session->maxtalkers, $session->recordingmode, '', $session->id))) {
                    return false;
                }
            }
            $DB->update_record('elluminate', $session);
            elluminate_update_events($session);
            /// If the grade value for attendance has changed, modify any existing attendance records.
            if ($elluminate->grade != $session->grade) {
                $attendance = $DB->get_records('elluminate_attendance', array('elluminateid' => $session->id));
                foreach ($attendance as $attendee) {
                    if ($attendee->grade > 0) {
                        /// We're using a scale.
                        if ($elluminate->grade < 0) {
                            $grades = make_grades_menu($elluminate->grade);
                            $attendee->grade = key($grades);
                            /// We're using a numerical value.
                        } else {
                            $attendee->grade = $elluminate->grade;
                        }
                        $DB->update_record('elluminate_attendance', $attendee);
                        elluminate_update_grades($session, $attendee->userid);
                    }
                }
            }
        }
    }
}
Example #25
0
 /**
  *  Display all the submissions ready for grading
  */
 function display_submissions($message = '')
 {
     global $CFG, $db, $USER;
     require_once $CFG->libdir . '/gradelib.php';
     /* first we check to see if the form has just been submitted
      * to request user_preference updates
      */
     if (isset($_POST['updatepref'])) {
         $perpage = optional_param('perpage', 10, PARAM_INT);
         $perpage = $perpage <= 0 ? 10 : $perpage;
         set_user_preference('assignment_perpage', $perpage);
         set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL));
     }
     /* next we get perpage and quickgrade (allow quick grade) params
      * from database
      */
     $perpage = get_user_preferences('assignment_perpage', 10);
     $quickgrade = get_user_preferences('assignment_quickgrade', 0);
     $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id);
     if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
         $uses_outcomes = true;
     } else {
         $uses_outcomes = false;
     }
     $teacherattempts = true;
     /// Temporary measure
     $page = optional_param('page', 0, PARAM_INT);
     $strsaveallfeedback = get_string('saveallfeedback', 'assignment');
     /// Some shortcuts to make the code read better
     $course = $this->course;
     $assignment = $this->assignment;
     $cm = $this->cm;
     $tabindex = 1;
     //tabindex for quick grading tabbing; Not working for dropdowns yet
     add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
     $navlinks = array();
     $navlinks[] = array('name' => $this->strassignments, 'link' => "index.php?id={$course->id}", 'type' => 'activity');
     $navlinks[] = array('name' => format_string($this->assignment->name, true), 'link' => "view.php?a={$this->assignment->id}", 'type' => 'activityinstance');
     $navlinks[] = array('name' => $this->strsubmissions, 'link' => '', 'type' => 'title');
     $navigation = build_navigation($navlinks);
     print_header_simple(format_string($this->assignment->name, true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm));
     if (!empty($message)) {
         echo $message;
         // display messages here if any
     }
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     /// find out current groups mode
     $groupmode = groups_get_activity_groupmode($cm);
     $currentgroup = groups_get_activity_group($cm, true);
     groups_print_activity_menu($cm, 'submissions.php?id=' . $this->cm->id);
     /// Get all ppl that are allowed to submit assignments
     $users = get_users_by_capability($context, 'mod/assignment:submit', '', '', '', '', $currentgroup, '', false);
     $users = array_keys($users);
     if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
         $groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id');
         $users = array_intersect($users, array_keys($groupingusers));
     }
     $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade');
     if ($uses_outcomes) {
         $tablecolumns[] = 'outcome';
         // no sorting based on outcomes column
     }
     $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified') . ' (' . $course->student . ')', get_string('lastmodified') . ' (' . $course->teacher . ')', get_string('status'), get_string('finalgrade', 'grades'));
     if ($uses_outcomes) {
         $tableheaders[] = get_string('outcome', 'grades');
     }
     require_once $CFG->libdir . '/tablelib.php';
     $table = new flexible_table('mod-assignment-submissions');
     $table->define_columns($tablecolumns);
     $table->define_headers($tableheaders);
     $table->define_baseurl($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;currentgroup=' . $currentgroup);
     $table->sortable(true, 'lastname');
     //sorted by lastname by default
     $table->collapsible(true);
     $table->initialbars(true);
     $table->column_suppress('picture');
     $table->column_suppress('fullname');
     $table->column_class('picture', 'picture');
     $table->column_class('fullname', 'fullname');
     $table->column_class('grade', 'grade');
     $table->column_class('submissioncomment', 'comment');
     $table->column_class('timemodified', 'timemodified');
     $table->column_class('timemarked', 'timemarked');
     $table->column_class('status', 'status');
     $table->column_class('finalgrade', 'finalgrade');
     if ($uses_outcomes) {
         $table->column_class('outcome', 'outcome');
     }
     $table->set_attribute('cellspacing', '0');
     $table->set_attribute('id', 'attempts');
     $table->set_attribute('class', 'submissions');
     $table->set_attribute('width', '90%');
     //$table->set_attribute('align', 'center');
     $table->no_sorting('finalgrade');
     $table->no_sorting('outcome');
     // Start working -- this is necessary as soon as the niceties are over
     $table->setup();
     /// Check to see if groups are being used in this assignment
     if (!$teacherattempts) {
         $teachers = get_course_teachers($course->id);
         if (!empty($teachers)) {
             $keys = array_keys($teachers);
         }
         foreach ($keys as $key) {
             unset($users[$key]);
         }
     }
     if (empty($users)) {
         print_heading(get_string('noattempts', 'assignment'));
         return true;
     }
     /// Construct the SQL
     if ($where = $table->get_sql_where()) {
         $where .= ' AND ';
     }
     if ($sort = $table->get_sql_sort()) {
         $sort = ' ORDER BY ' . $sort;
     }
     $select = 'SELECT u.id, u.firstname, u.lastname, u.picture,
                       s.id AS submissionid, s.grade, s.submissioncomment,
                       s.timemodified, s.timemarked,
                       COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status ';
     $sql = 'FROM ' . $CFG->prefix . 'user u ' . 'LEFT JOIN ' . $CFG->prefix . 'assignment_submissions s ON u.id = s.userid
                                                               AND s.assignment = ' . $this->assignment->id . ' ' . 'WHERE ' . $where . 'u.id IN (' . implode(',', $users) . ') ';
     $table->pagesize($perpage, count($users));
     ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next
     $offset = $page * $perpage;
     $strupdate = get_string('update');
     $strgrade = get_string('grade');
     $grademenu = make_grades_menu($this->assignment->grade);
     if (($ausers = get_records_sql($select . $sql . $sort, $table->get_page_start(), $table->get_page_size())) !== false) {
         $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers));
         foreach ($ausers as $auser) {
             $final_grade = $grading_info->items[0]->grades[$auser->id];
             /// Calculate user status
             $auser->status = $auser->timemarked > 0 && $auser->timemarked >= $auser->timemodified;
             $picture = print_user_picture($auser->id, $course->id, $auser->picture, false, true);
             if (empty($auser->submissionid)) {
                 $auser->grade = -1;
                 //no submission yet
             }
             if (!empty($auser->submissionid)) {
                 ///Prints student answer and student modified date
                 ///attach file or print link to student answer, depending on the type of the assignment.
                 ///Refer to print_student_answer in inherited classes.
                 if ($auser->timemodified > 0) {
                     $studentmodified = '<div id="ts' . $auser->id . '">' . $this->print_student_answer($auser->id) . userdate($auser->timemodified) . '</div>';
                 } else {
                     $studentmodified = '<div id="ts' . $auser->id . '">&nbsp;</div>';
                 }
                 ///Print grade, dropdown or text
                 if ($auser->timemarked > 0) {
                     $teachermodified = '<div id="tt' . $auser->id . '">' . userdate($auser->timemarked) . '</div>';
                     if ($final_grade->locked or $final_grade->overridden) {
                         $grade = '<div id="g' . $auser->id . '">' . $final_grade->str_grade . '</div>';
                     } else {
                         if ($quickgrade) {
                             $menu = choose_from_menu(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++);
                             $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>';
                         } else {
                             $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                         }
                     }
                 } else {
                     $teachermodified = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                     if ($final_grade->locked or $final_grade->overridden) {
                         $grade = '<div id="g' . $auser->id . '">' . $final_grade->str_grade . '</div>';
                     } else {
                         if ($quickgrade) {
                             $menu = choose_from_menu(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++);
                             $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>';
                         } else {
                             $grade = '<div id="g' . $auser->id . '">' . $this->display_grade($auser->grade) . '</div>';
                         }
                     }
                 }
                 ///Print Comment
                 if ($final_grade->locked or $final_grade->overridden) {
                     $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($final_grade->str_feedback), 15) . '</div>';
                 } else {
                     if ($quickgrade) {
                         $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>';
                     } else {
                         $comment = '<div id="com' . $auser->id . '">' . shorten_text(strip_tags($auser->submissioncomment), 15) . '</div>';
                     }
                 }
             } else {
                 $studentmodified = '<div id="ts' . $auser->id . '">&nbsp;</div>';
                 $teachermodified = '<div id="tt' . $auser->id . '">&nbsp;</div>';
                 $status = '<div id="st' . $auser->id . '">&nbsp;</div>';
                 if ($final_grade->locked or $final_grade->overridden) {
                     $grade = '<div id="g' . $auser->id . '">' . $final_grade->str_grade . '</div>';
                 } else {
                     if ($quickgrade) {
                         // allow editing
                         $menu = choose_from_menu(make_grades_menu($this->assignment->grade), 'menu[' . $auser->id . ']', $auser->grade, get_string('nograde'), '', -1, true, false, $tabindex++);
                         $grade = '<div id="g' . $auser->id . '">' . $menu . '</div>';
                     } else {
                         $grade = '<div id="g' . $auser->id . '">-</div>';
                     }
                 }
                 if ($final_grade->locked or $final_grade->overridden) {
                     $comment = '<div id="com' . $auser->id . '">' . $final_grade->str_feedback . '</div>';
                 } else {
                     if ($quickgrade) {
                         $comment = '<div id="com' . $auser->id . '">' . '<textarea tabindex="' . $tabindex++ . '" name="submissioncomment[' . $auser->id . ']" id="submissioncomment' . $auser->id . '" rows="2" cols="20">' . $auser->submissioncomment . '</textarea></div>';
                     } else {
                         $comment = '<div id="com' . $auser->id . '">&nbsp;</div>';
                     }
                 }
             }
             if (empty($auser->status)) {
                 /// Confirm we have exclusively 0 or 1
                 $auser->status = 0;
             } else {
                 $auser->status = 1;
             }
             $buttontext = $auser->status == 1 ? $strupdate : $strgrade;
             ///No more buttons, we use popups ;-).
             $popup_url = '/mod/assignment/submissions.php?id=' . $this->cm->id . '&amp;userid=' . $auser->id . '&amp;mode=single' . '&amp;offset=' . $offset++;
             $button = link_to_popup_window($popup_url, 'grade' . $auser->id, $buttontext, 600, 780, $buttontext, 'none', true, 'button' . $auser->id);
             $status = '<div id="up' . $auser->id . '" class="s' . $auser->status . '">' . $button . '</div>';
             $finalgrade = '<span id="finalgrade_' . $auser->id . '">' . $final_grade->str_grade . '</span>';
             $outcomes = '';
             if ($uses_outcomes) {
                 foreach ($grading_info->outcomes as $n => $outcome) {
                     $outcomes .= '<div class="outcome"><label>' . $outcome->name . '</label>';
                     $options = make_grades_menu(-$outcome->scaleid);
                     if ($outcome->grades[$auser->id]->locked or !$quickgrade) {
                         $options[0] = get_string('nooutcome', 'grades');
                         $outcomes .= ': <span id="outcome_' . $n . '_' . $auser->id . '">' . $options[$outcome->grades[$auser->id]->grade] . '</span>';
                     } else {
                         $outcomes .= ' ';
                         $outcomes .= choose_from_menu($options, 'outcome_' . $n . '[' . $auser->id . ']', $outcome->grades[$auser->id]->grade, get_string('nooutcome', 'grades'), '', 0, true, false, 0, 'outcome_' . $n . '_' . $auser->id);
                     }
                     $outcomes .= '</div>';
                 }
             }
             $row = array($picture, fullname($auser), $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade);
             if ($uses_outcomes) {
                 $row[] = $outcomes;
             }
             $table->add_data($row);
         }
     }
     /// Print quickgrade form around the table
     if ($quickgrade) {
         echo '<form action="submissions.php" id="fastg" method="post">';
         echo '<div>';
         echo '<input type="hidden" name="id" value="' . $this->cm->id . '" />';
         echo '<input type="hidden" name="mode" value="fastgrade" />';
         echo '<input type="hidden" name="page" value="' . $page . '" />';
         echo '</div>';
         //echo '<div style="text-align:center"><input type="submit" name="fastg" value="'.get_string('saveallfeedback', 'assignment').'" /></div>';
     }
     $table->print_html();
     /// Print the whole table
     if ($quickgrade) {
         echo '<div style="text-align:center"><input type="submit" name="fastg" value="' . get_string('saveallfeedback', 'assignment') . '" /></div>';
         echo '</form>';
     }
     /// End of fast grading form
     /// Mini form for setting user preference
     echo '<br />';
     echo '<form id="options" action="submissions.php?id=' . $this->cm->id . '" method="post">';
     echo '<div>';
     echo '<input type="hidden" id="updatepref" name="updatepref" value="1" />';
     echo '<table id="optiontable" align="right">';
     echo '<tr align="right"><td>';
     echo '<label for="perpage">' . get_string('pagesize', 'assignment') . '</label>';
     echo ':</td>';
     echo '<td>';
     echo '<input type="text" id="perpage" name="perpage" size="1" value="' . $perpage . '" />';
     helpbutton('pagesize', get_string('pagesize', 'assignment'), 'assignment');
     echo '</td></tr>';
     echo '<tr align="right">';
     echo '<td>';
     print_string('quickgrade', 'assignment');
     echo ':</td>';
     echo '<td>';
     if ($quickgrade) {
         echo '<input type="checkbox" name="quickgrade" value="1" checked="checked" />';
     } else {
         echo '<input type="checkbox" name="quickgrade" value="1" />';
     }
     helpbutton('quickgrade', get_string('quickgrade', 'assignment'), 'assignment') . '</p></div>';
     echo '</td></tr>';
     echo '<tr>';
     echo '<td colspan="2" align="right">';
     echo '<input type="submit" value="' . get_string('savepreferences') . '" />';
     echo '</td></tr></table>';
     echo '</div>';
     echo '</form>';
     ///End of mini form
     print_footer($this->course);
 }
Example #26
0
File: lib.php Project: r007/PMoodle
/**
 *
 */
function forum_print_discussion($course, $cm, $forum, $discussion, $post, $mode, $canreply = NULL, $canrate = false)
{
    global $USER, $CFG;
    if (!empty($USER->id)) {
        $ownpost = $USER->id == $post->userid;
    } else {
        $ownpost = false;
    }
    if ($canreply === NULL) {
        $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
        $reply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
    } else {
        $reply = $canreply;
    }
    // $cm holds general cache for forum functions
    $cm->cache = new object();
    $cm->cache->groups = groups_get_all_groups($course->id, 0, $cm->groupingid);
    $cm->cache->usersgroups = array();
    $posters = array();
    // preload all posts - TODO: improve...
    if ($mode == FORUM_MODE_FLATNEWEST) {
        $sort = "p.created DESC";
    } else {
        $sort = "p.created ASC";
    }
    $forumtracked = forum_tp_is_tracked($forum);
    $posts = forum_get_all_discussion_posts($discussion->id, $sort, $forumtracked);
    $post = $posts[$post->id];
    foreach ($posts as $pid => $p) {
        $posters[$p->userid] = $p->userid;
    }
    // preload all groups of ppl that posted in this discussion
    if ($postersgroups = groups_get_all_groups($course->id, $posters, $cm->groupingid, 'gm.id, gm.groupid, gm.userid')) {
        foreach ($postersgroups as $pg) {
            if (!isset($cm->cache->usersgroups[$pg->userid])) {
                $cm->cache->usersgroups[$pg->userid] = array();
            }
            $cm->cache->usersgroups[$pg->userid][$pg->groupid] = $pg->groupid;
        }
        unset($postersgroups);
    }
    $ratings = NULL;
    $ratingsmenuused = false;
    $ratingsformused = false;
    if ($forum->assessed and isloggedin()) {
        if ($ratings->scale = make_grades_menu($forum->scale)) {
            $ratings->assesstimestart = $forum->assesstimestart;
            $ratings->assesstimefinish = $forum->assesstimefinish;
            $ratings->allow = $canrate;
            if ($ratings->allow) {
                echo '<form id="form" method="post" action="rate.php">';
                echo '<div class="ratingform">';
                echo '<input type="hidden" name="forumid" value="' . $forum->id . '" />';
                $ratingsformused = true;
            }
            // preload all ratings - one query only and minimal memory
            $cm->cache->ratings = array();
            $cm->cache->myratings = array();
            if ($postratings = forum_get_all_discussion_ratings($discussion)) {
                foreach ($postratings as $pr) {
                    if (!isset($cm->cache->ratings[$pr->postid])) {
                        $cm->cache->ratings[$pr->postid] = array();
                    }
                    $cm->cache->ratings[$pr->postid][$pr->id] = $pr->rating;
                    if ($pr->userid == $USER->id) {
                        $cm->cache->myratings[$pr->postid] = $pr->rating;
                    }
                }
                unset($postratings);
            }
        }
    }
    $post->forum = $forum->id;
    // Add the forum id to the post object, later used by forum_print_post
    $post->forumtype = $forum->type;
    $post->subject = format_string($post->subject);
    $postread = !empty($post->postread);
    if (forum_print_post($post, $discussion, $forum, $cm, $course, $ownpost, $reply, false, $ratings, '', '', $postread, true, $forumtracked)) {
        $ratingsmenuused = true;
    }
    switch ($mode) {
        case FORUM_MODE_FLATOLDEST:
        case FORUM_MODE_FLATNEWEST:
        default:
            if (forum_print_posts_flat($course, $cm, $forum, $discussion, $post, $mode, $ratings, $reply, $forumtracked, $posts)) {
                $ratingsmenuused = true;
            }
            break;
        case FORUM_MODE_THREADED:
            if (forum_print_posts_threaded($course, $cm, $forum, $discussion, $post, 0, $ratings, $reply, $forumtracked, $posts)) {
                $ratingsmenuused = true;
            }
            break;
        case FORUM_MODE_NESTED:
            if (forum_print_posts_nested($course, $cm, $forum, $discussion, $post, $ratings, $reply, $forumtracked, $posts)) {
                $ratingsmenuused = true;
            }
            break;
    }
    if ($ratingsformused) {
        if ($ratingsmenuused) {
            echo '<div class="ratingsubmit">';
            echo '<input type="submit" value="' . get_string('sendinratings', 'forum') . '" />';
            if ($forum->scale < 0) {
                if ($scale = get_record("scale", "id", abs($forum->scale))) {
                    print_scale_menu_helpbutton($course->id, $scale);
                }
            }
            echo '</div>';
        }
        echo '</div>';
        echo '</form>';
    }
}
Example #27
0
 /**
  * Add elements to grade form.
  *
  * @param MoodleQuickForm $mform
  * @param stdClass $data
  * @param array $params
  * @return void
  */
 public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data, $params)
 {
     global $USER, $CFG;
     $settings = $this->get_instance();
     $rownum = $params['rownum'];
     $last = $params['last'];
     $useridlistid = $params['useridlistid'];
     $userid = $params['userid'];
     $attemptnumber = $params['attemptnumber'];
     if (!$userid) {
         $cache = cache::make_from_params(cache_store::MODE_SESSION, 'mod_assign', 'useridlist');
         if (!($useridlist = $cache->get($this->get_course_module()->id . '_' . $useridlistid))) {
             $useridlist = $this->get_grading_userid_list();
             $cache->set($this->get_course_module()->id . '_' . $useridlistid, $useridlist);
         }
     } else {
         $useridlist = array($userid);
         $rownum = 0;
         $useridlistid = '';
     }
     $userid = $useridlist[$rownum];
     $grade = $this->get_user_grade($userid, false, $attemptnumber);
     $submission = null;
     if ($this->get_instance()->teamsubmission) {
         $submission = $this->get_group_submission($userid, 0, false, $attemptnumber);
     } else {
         $submission = $this->get_user_submission($userid, false, $attemptnumber);
     }
     // Add advanced grading.
     $gradingdisabled = $this->grading_disabled($userid);
     $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled);
     $mform->addElement('header', 'gradeheader', get_string('grade'));
     if ($gradinginstance) {
         $gradingelement = $mform->addElement('grading', 'advancedgrading', get_string('grade') . ':', array('gradinginstance' => $gradinginstance));
         if ($gradingdisabled) {
             $gradingelement->freeze();
         } else {
             $mform->addElement('hidden', 'advancedgradinginstanceid', $gradinginstance->get_id());
             $mform->setType('advancedgradinginstanceid', PARAM_INT);
         }
     } else {
         // Use simple direct grading.
         if ($this->get_instance()->grade > 0) {
             $name = get_string('gradeoutof', 'assign', $this->get_instance()->grade);
             if (!$gradingdisabled) {
                 $gradingelement = $mform->addElement('text', 'grade', $name);
                 $mform->addHelpButton('grade', 'gradeoutofhelp', 'assign');
                 $mform->setType('grade', PARAM_RAW);
             } else {
                 $mform->addElement('hidden', 'grade', $name);
                 $mform->hardFreeze('grade');
                 $mform->setType('grade', PARAM_RAW);
                 $strgradelocked = get_string('gradelocked', 'assign');
                 $mform->addElement('static', 'gradedisabled', $name, $strgradelocked);
                 $mform->addHelpButton('gradedisabled', 'gradeoutofhelp', 'assign');
             }
         } else {
             $grademenu = array(-1 => get_string("nograde")) + make_grades_menu($this->get_instance()->grade);
             if (count($grademenu) > 1) {
                 $gradingelement = $mform->addElement('select', 'grade', get_string('grade') . ':', $grademenu);
                 // The grade is already formatted with format_float so it needs to be converted back to an integer.
                 if (!empty($data->grade)) {
                     $data->grade = (int) unformat_float($data->grade);
                 }
                 $mform->setType('grade', PARAM_INT);
                 if ($gradingdisabled) {
                     $gradingelement->freeze();
                 }
             }
         }
     }
     $gradinginfo = grade_get_grades($this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, $userid);
     if (!empty($CFG->enableoutcomes)) {
         foreach ($gradinginfo->outcomes as $index => $outcome) {
             $options = make_grades_menu(-$outcome->scaleid);
             if ($outcome->grades[$userid]->locked) {
                 $options[0] = get_string('nooutcome', 'grades');
                 $mform->addElement('static', 'outcome_' . $index . '[' . $userid . ']', $outcome->name . ':', $options[$outcome->grades[$userid]->grade]);
             } else {
                 $options[''] = get_string('nooutcome', 'grades');
                 $attributes = array('id' => 'menuoutcome_' . $index);
                 $mform->addElement('select', 'outcome_' . $index . '[' . $userid . ']', $outcome->name . ':', $options, $attributes);
                 $mform->setType('outcome_' . $index . '[' . $userid . ']', PARAM_INT);
                 $mform->setDefault('outcome_' . $index . '[' . $userid . ']', $outcome->grades[$userid]->grade);
             }
         }
     }
     $capabilitylist = array('gradereport/grader:view', 'moodle/grade:viewall');
     if (has_all_capabilities($capabilitylist, $this->get_course_context())) {
         $urlparams = array('id' => $this->get_course()->id);
         $url = new moodle_url('/grade/report/grader/index.php', $urlparams);
         $usergrade = '-';
         if (isset($gradinginfo->items[0]->grades[$userid]->str_grade)) {
             $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade;
         }
         $gradestring = $this->get_renderer()->action_link($url, $usergrade);
     } else {
         $usergrade = '-';
         if (isset($gradinginfo->items[0]->grades[$userid]) && !$gradinginfo->items[0]->grades[$userid]->hidden) {
             $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade;
         }
         $gradestring = $usergrade;
     }
     if ($this->get_instance()->markingworkflow) {
         $states = $this->get_marking_workflow_states_for_current_user();
         $options = array('' => get_string('markingworkflowstatenotmarked', 'assign')) + $states;
         $mform->addElement('select', 'workflowstate', get_string('markingworkflowstate', 'assign'), $options);
         $mform->addHelpButton('workflowstate', 'markingworkflowstate', 'assign');
     }
     if ($this->get_instance()->markingallocation && has_capability('mod/assign:manageallocations', $this->context)) {
         $markers = get_users_by_capability($this->context, 'mod/assign:grade');
         $markerlist = array('' => get_string('choosemarker', 'assign'));
         foreach ($markers as $marker) {
             $markerlist[$marker->id] = fullname($marker);
         }
         $mform->addElement('select', 'allocatedmarker', get_string('allocatedmarker', 'assign'), $markerlist);
         $mform->addHelpButton('allocatedmarker', 'allocatedmarker', 'assign');
         $mform->disabledIf('allocatedmarker', 'workflowstate', 'eq', ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW);
         $mform->disabledIf('allocatedmarker', 'workflowstate', 'eq', ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW);
         $mform->disabledIf('allocatedmarker', 'workflowstate', 'eq', ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE);
         $mform->disabledIf('allocatedmarker', 'workflowstate', 'eq', ASSIGN_MARKING_WORKFLOW_STATE_RELEASED);
     }
     $mform->addElement('static', 'currentgrade', get_string('currentgrade', 'assign'), $gradestring);
     if (count($useridlist) > 1) {
         $strparams = array('current' => $rownum + 1, 'total' => count($useridlist));
         $name = get_string('outof', 'assign', $strparams);
         $mform->addElement('static', 'gradingstudent', get_string('gradingstudent', 'assign'), $name);
     }
     // Let feedback plugins add elements to the grading form.
     $this->add_plugin_grade_elements($grade, $mform, $data, $userid);
     // Hidden params.
     $mform->addElement('hidden', 'id', $this->get_course_module()->id);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'rownum', $rownum);
     $mform->setType('rownum', PARAM_INT);
     $mform->setConstant('rownum', $rownum);
     $mform->addElement('hidden', 'useridlistid', $useridlistid);
     $mform->setType('useridlistid', PARAM_INT);
     $mform->addElement('hidden', 'attemptnumber', $attemptnumber);
     $mform->setType('attemptnumber', PARAM_INT);
     $mform->addElement('hidden', 'ajax', optional_param('ajax', 0, PARAM_INT));
     $mform->setType('ajax', PARAM_INT);
     if ($this->get_instance()->teamsubmission) {
         $mform->addElement('header', 'groupsubmissionsettings', get_string('groupsubmissionsettings', 'assign'));
         $mform->addElement('selectyesno', 'applytoall', get_string('applytoteam', 'assign'));
         $mform->setDefault('applytoall', 1);
     }
     // Do not show if we are editing a previous attempt.
     if ($attemptnumber == -1 && $this->get_instance()->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
         $mform->addElement('header', 'attemptsettings', get_string('attemptsettings', 'assign'));
         $attemptreopenmethod = get_string('attemptreopenmethod_' . $this->get_instance()->attemptreopenmethod, 'assign');
         $mform->addElement('static', 'attemptreopenmethod', get_string('attemptreopenmethod', 'assign'), $attemptreopenmethod);
         $attemptnumber = 0;
         if ($submission) {
             $attemptnumber = $submission->attemptnumber;
         }
         $maxattempts = $this->get_instance()->maxattempts;
         if ($maxattempts == ASSIGN_UNLIMITED_ATTEMPTS) {
             $maxattempts = get_string('unlimitedattempts', 'assign');
         }
         $mform->addelement('static', 'maxattemptslabel', get_string('maxattempts', 'assign'), $maxattempts);
         $mform->addelement('static', 'attemptnumberlabel', get_string('attemptnumber', 'assign'), $attemptnumber + 1);
         $ismanual = $this->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL;
         $issubmission = !empty($submission);
         $isunlimited = $this->get_instance()->maxattempts == ASSIGN_UNLIMITED_ATTEMPTS;
         $islessthanmaxattempts = $issubmission && $submission->attemptnumber < $this->get_instance()->maxattempts - 1;
         if ($ismanual && (!$issubmission || $isunlimited || $islessthanmaxattempts)) {
             $mform->addElement('selectyesno', 'addattempt', get_string('addattempt', 'assign'));
             $mform->setDefault('addattempt', 0);
         }
     }
     $mform->addElement('hidden', 'action', 'submitgrade');
     $mform->setType('action', PARAM_ALPHA);
     $buttonarray = array();
     $name = get_string('savechanges', 'assign');
     $buttonarray[] = $mform->createElement('submit', 'savegrade', $name);
     if (!$last) {
         $name = get_string('savenext', 'assign');
         $buttonarray[] = $mform->createElement('submit', 'saveandshownext', $name);
     }
     $buttonarray[] = $mform->createElement('cancel', 'cancelbutton', get_string('cancel'));
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
     $buttonarray = array();
     if ($rownum > 0) {
         $name = get_string('previous', 'assign');
         $buttonarray[] = $mform->createElement('submit', 'nosaveandprevious', $name);
     }
     if (!$last) {
         $name = get_string('nosavebutnext', 'assign');
         $buttonarray[] = $mform->createElement('submit', 'nosaveandnext', $name);
     }
     if (!empty($buttonarray)) {
         $mform->addGroup($buttonarray, 'navar', '', array(' '), false);
     }
     // The grading form does not work well with shortforms.
     $mform->setDisableShortforms();
 }
Example #28
0
 function definition()
 {
     global $CFG, $OUTPUT;
     $id = required_param('id', PARAM_INT);
     $userid = optional_param('userid', null, PARAM_INT);
     $inpopup = optional_param('inpopup', 0, PARAM_INT);
     $this->addHidden('id', $id);
     $this->addHidden('userid', $userid);
     $submissionid = optional_param('submissionid', 0, PARAM_INT);
     if ($submissionid > 0) {
         $this->addHidden('submissionid', $submissionid);
     }
     $this->addHidden('inpopup', $inpopup);
     $vpl_instance = $this->vpl->get_instance();
     //TODO Improve grade form (recalculate grade)
     //Show assesment criteria
     //Show others evaluation
     //Type value => introduce value
     $grade = $this->vpl->get_grade();
     if ($grade != 0) {
         $this->addHTML(s(get_string('grade') . ' '));
         if ($grade > 0) {
             $this->addText('grade', '', 6);
         } else {
             $this->addSelect('grade', $this->get_scale_selection());
         }
         $this->addHTML(' &nbsp;');
     }
     $this->addSubmitButton('save', get_string('grade'));
     if ($inpopup) {
         $this->addSubmitButton('savenext', get_string('gradeandnext', VPL));
     }
     $this->addSubmitButton('removegrade', get_string('removegrade', VPL));
     //tranfer files to teacher's work area
     $url = vpl_mod_href('forms/edit.php', 'id', $id, 'userid', $userid, 'privatecopy', 1);
     $options = array('height' => 550, 'width' => 780, 'directories' => 0, 'location' => 0, 'menubar' => 0, 'personalbar' => 0, 'status' => 0, 'toolbar' => 0);
     $action = new popup_action('click', $url, 'privatecopy' . $vpl_instance->id, $options);
     $this->addHTML($OUTPUT->action_link($url, get_string('copy', VPL), $action));
     if ($vpl_instance->evaluate) {
         //Link to recalculate numeric grade from comments
         $url = vpl_mod_href('forms/evaluation.php', 'id', $id, 'userid', $userid, 'grading', 1, 'inpopup', $inpopup);
         $html = ' <a href="' . $url . '">' . s(get_string('evaluate', VPL)) . '</a>';
         $this->addHTML($html);
     }
     //Numeric grade
     if ($grade > 0) {
         //Link to recalculate numeric grade from comments
         $jscript = 'VPL.calculateGrade(' . $grade . ')';
         $html = ' <a href="javascript:void(0);" onclick="' . $jscript . '">' . s(get_string('calculate', VPL)) . '</a>';
         $this->addHTML($html);
     }
     //TODO user similarity
     /*        $url=vpl_mod_href('similarity/user_similarity.php','id',$id,'userid',$userid);
             $html=link_to_popup_window($url,'similarity'.$id.'-'.$userid,get_string('similarity',VPL),800,900,null,null,true);
             $this->addHTML(' '.$html);*/
     $this->addHTML('<br />');
     if ($grade != 0) {
         $this->addHTML(s(get_string('comments', VPL)) . '<br />');
         $this->addTextArea('comments', '', 8, 70);
         $this->addHTML('<br />');
     }
     if (!empty($CFG->enableoutcomes)) {
         $grading_info = grade_get_grades($this->vpl->get_course()->id, 'mod', 'vpl', $vpl_instance->id, $userid);
         if (!empty($grading_info->outcomes)) {
             $this->addHTML('<table border="0">');
             foreach ($grading_info->outcomes as $oid => $outcome) {
                 $this->addHTML('<tr><td align="right">');
                 $options = make_grades_menu(-$outcome->scaleid);
                 $options[0] = get_string('nooutcome', 'grades');
                 $this->addHTML(s($outcome->name));
                 $this->addHTML('</td><td>');
                 $this->addSelect('outcome_grade_' . $oid, $options, $outcome->grades[$userid]->grade);
                 $this->addHTML('</td></tr>');
             }
             $this->addHTML('</table>');
         }
     }
 }
 /**
  * Format a list of outcomes.
  *
  * @param stdClass $row
  * @return string
  */
 public function col_outcomes(stdClass $row)
 {
     $outcomes = '';
     foreach ($this->gradinginfo->outcomes as $index => $outcome) {
         $options = make_grades_menu(-$outcome->scaleid);
         $options[0] = get_string('nooutcome', 'grades');
         if ($this->quickgrading && !$outcome->grades[$row->userid]->locked) {
             $select = '<select name="outcome_' . $index . '_' . $row->userid . '" class="quickgrade">';
             foreach ($options as $optionindex => $optionvalue) {
                 $selected = '';
                 if ($outcome->grades[$row->userid]->grade == $optionindex) {
                     $selected = 'selected="selected"';
                 }
                 $select .= '<option value="' . $optionindex . '"' . $selected . '>' . $optionvalue . '</option>';
             }
             $select .= '</select>';
             $outcomes .= $this->output->container($outcome->name . ': ' . $select, 'outcome');
         } else {
             $name = $outcome->name . ': ' . $options[$outcome->grades[$row->userid]->grade];
             if ($this->is_downloading()) {
                 $outcomes .= $name;
             } else {
                 $outcomes .= $this->output->container($name, 'outcome');
             }
         }
     }
     return $outcomes;
 }
Example #30
0
if ($allentries) {
    //Decide if we must show the ALL link in the pagebar
    $specialtext = '';
    if ($glossary->showall) {
        $specialtext = get_string("allentries", "glossary");
    }
    //Build paging bar
    $paging = glossary_get_paging_bar($count, $page, $entriesbypage, "view.php?id={$id}&amp;mode={$mode}&amp;hook={$hook}&amp;sortkey={$sortkey}&amp;sortorder={$sortorder}&amp;fullsearch={$fullsearch}&amp;", 9999, 10, '&nbsp;&nbsp;', $specialtext, -1);
    echo '<div class="paging">';
    echo $paging;
    echo '</div>';
    $ratings = NULL;
    $ratingsmenuused = false;
    if ($glossary->assessed and isloggedin() and !isguestuser()) {
        $ratings = new object();
        if ($ratings->scale = make_grades_menu($glossary->scale)) {
            $ratings->assesstimestart = $glossary->assesstimestart;
            $ratings->assesstimefinish = $glossary->assesstimefinish;
        }
        if ($glossary->assessed == 2 and !has_capability('mod/glossary:rate', $context)) {
            $ratings->allow = false;
        } else {
            $ratings->allow = true;
        }
        $formsent = 1;
        echo "<form method=\"post\" action=\"rate.php\">";
        echo "<div>";
        echo "<input type=\"hidden\" name=\"glossaryid\" value=\"{$glossary->id}\" />";
    }
    foreach ($allentries as $entry) {
        // Setting the pivot for the current entry