/** * Define the elements to be displayed at the form * * Called by the parent::definition() * * @return void */ protected function definition_inner(&$mform) { $norepeats = $this->_customdata['norepeats']; // number of dimensions to display $descriptionopts = $this->_customdata['descriptionopts']; // wysiwyg fields options $current = $this->_customdata['current']; // current data to be set $mform->addElement('hidden', 'norepeats', $norepeats); $mform->setType('norepeats', PARAM_INT); // value not to be overridden by submitted value $mform->setConstants(array('norepeats' => $norepeats)); for ($i = 0; $i < $norepeats; $i++) { $mform->addElement('header', 'dimension' . $i, get_string('dimensionnumber', 'teamworkform_accumulative', $i + 1)); $mform->addElement('hidden', 'dimensionid__idx_' . $i); $mform->setType('dimensionid__idx_' . $i, PARAM_INT); $mform->addElement('editor', 'description__idx_' . $i . '_editor', get_string('dimensiondescription', 'teamworkform_accumulative'), '', $descriptionopts); // todo replace modgrade with an advanced element (usability issue discussed with Olli) $mform->addElement('modgrade', 'grade__idx_' . $i, get_string('dimensionmaxgrade', 'teamworkform_accumulative'), null, true); $mform->setDefault('grade__idx_' . $i, 10); $mform->addElement('select', 'weight__idx_' . $i, get_string('dimensionweight', 'teamworkform_accumulative'), teamwork::available_dimension_weights_list()); $mform->setDefault('weight__idx_' . $i, 1); } $mform->registerNoSubmitButton('noadddims'); $mform->addElement('submit', 'noadddims', get_string('addmoredimensions', 'teamworkform_accumulative', teamwork_accumulative_strategy::ADDDIMS)); $mform->closeHeaderBefore('noadddims'); $this->set_data($current); }
function definition() { $mform = $this->_form; $current = $this->_customdata['current']; $teamwork = $this->_customdata['teamwork']; $editoropts = $this->_customdata['editoropts']; $options = $this->_customdata['options']; $mform->addElement('header', 'assessmentsettings', get_string('assessmentsettings', 'teamwork')); if (!empty($options['editableweight'])) { $mform->addElement('select', 'weight', get_string('assessmentweight', 'teamwork'), teamwork::available_assessment_weights_list()); $mform->setDefault('weight', 1); } $mform->addElement('static', 'gradinggrade', get_string('gradinggradecalculated', 'teamwork')); if (!empty($options['overridablegradinggrade'])) { $grades = array('' => get_string('notoverridden', 'teamwork')); for ($i = (int) $teamwork->gradinggrade; $i >= 0; $i--) { $grades[$i] = $i; } $mform->addElement('select', 'gradinggradeover', get_string('gradinggradeover', 'teamwork'), $grades); $mform->addElement('editor', 'feedbackreviewer_editor', get_string('feedbackreviewer', 'teamwork'), null, $editoropts); $mform->setType('feedbackreviewer_editor', PARAM_RAW); } $mform->addElement('hidden', 'asid'); $mform->setType('asid', PARAM_INT); $mform->addElement('submit', 'save', get_string('saveandclose', 'teamwork')); $this->set_data($current); }
/** * Define the elements to be displayed at the form * * Called by the parent::definition() * * @return void */ protected function definition_inner(&$mform) { $plugindefaults = get_config('teamworkform_numerrors'); $nodimensions = $this->_customdata['nodimensions']; // number of currently filled dimensions $norepeats = $this->_customdata['norepeats']; // number of dimensions to display $descriptionopts = $this->_customdata['descriptionopts']; // wysiwyg fields options $current = $this->_customdata['current']; // current data to be set $mform->addElement('hidden', 'norepeats', $norepeats); $mform->setType('norepeats', PARAM_INT); // value not to be overridden by submitted value $mform->setConstants(array('norepeats' => $norepeats)); for ($i = 0; $i < $norepeats; $i++) { $mform->addElement('header', 'dimension' . $i, get_string('dimensionnumber', 'teamworkform_numerrors', $i + 1)); $mform->addElement('hidden', 'dimensionid__idx_' . $i); // the id in teamwork_forms $mform->setType('dimensionid__idx_' . $i, PARAM_INT); $mform->addElement('editor', 'description__idx_' . $i . '_editor', get_string('dimensiondescription', 'teamworkform_numerrors'), '', $descriptionopts); $mform->addElement('text', 'grade0__idx_' . $i, get_string('grade0', 'teamworkform_numerrors'), array('size' => '15')); $mform->setDefault('grade0__idx_' . $i, $plugindefaults->grade0); $mform->setType('grade0__idx_' . $i, PARAM_TEXT); $mform->addElement('text', 'grade1__idx_' . $i, get_string('grade1', 'teamworkform_numerrors'), array('size' => '15')); $mform->setDefault('grade1__idx_' . $i, $plugindefaults->grade1); $mform->setType('grade1__idx_' . $i, PARAM_TEXT); $mform->addElement('select', 'weight__idx_' . $i, get_string('dimensionweight', 'teamworkform_numerrors'), teamwork::available_dimension_weights_list()); $mform->setDefault('weight__idx_' . $i, 1); } $mform->addElement('header', 'mappingheader', get_string('grademapping', 'teamworkform_numerrors')); $mform->addElement('static', 'mappinginfo', get_string('maperror', 'teamworkform_numerrors'), get_string('mapgrade', 'teamworkform_numerrors')); // get the total weight of all items == maximum weighted number of errors $totalweight = 0; for ($i = 0; $i < $norepeats; $i++) { if (!empty($current->{'weight__idx_' . $i})) { $totalweight += $current->{'weight__idx_' . $i}; } } $totalweight = max($totalweight, $nodimensions); $percents = array(); $percents[''] = ''; for ($i = 100; $i >= 0; $i--) { $percents[$i] = get_string('percents', 'teamworkform_numerrors', $i); } $mform->addElement('static', 'mappingzero', 0, get_string('percents', 'teamworkform_numerrors', 100)); for ($i = 1; $i <= $totalweight; $i++) { $selects = array(); $selects[] = $mform->createElement('select', 'map__idx_' . $i, $i, $percents); $selects[] = $mform->createElement('static', 'mapdefault__idx_' . $i, '', get_string('percents', 'teamworkform_numerrors', floor(100 - $i * 100 / $totalweight))); $mform->addGroup($selects, 'grademapping' . $i, $i, array(' '), false); $mform->setDefault('map__idx_' . $i, ''); } $mform->registerNoSubmitButton('noadddims'); $mform->addElement('submit', 'noadddims', get_string('addmoredimensions', 'teamworkform_numerrors', teamwork_numerrors_strategy::ADDDIMS)); $mform->closeHeaderBefore('noadddims'); $this->set_data($current); }
/** * Add the fields that are common for all grading strategies. * * If the strategy does not support all these fields, then you can override * this method and remove the ones you don't want with * $mform->removeElement(). * Strategy subclassess should define their own fields in definition_inner() * * @return void */ public function definition() { global $CFG; $mform = $this->_form; $this->mode = $this->_customdata['mode']; // influences the save buttons $this->strategy = $this->_customdata['strategy']; // instance of the strategy api class $this->teamwork = $this->_customdata['teamwork']; // instance of the teamwork api class $this->options = $this->_customdata['options']; // array with addiotional options // Disable shortforms $mform->setDisableShortforms(); // add the strategy-specific fields $this->definition_inner($mform); // add the data common for all subplugins $mform->addElement('hidden', 'strategy', $this->teamwork->strategy); $mform->setType('strategy', PARAM_PLUGIN); if ($this->teamwork->overallfeedbackmode and $this->is_editable()) { $mform->addElement('header', 'overallfeedbacksection', get_string('overallfeedback', 'mod_teamwork')); $mform->addElement('editor', 'feedbackauthor_editor', get_string('feedbackauthor', 'mod_teamwork'), null, $this->teamwork->overall_feedback_content_options()); if ($this->teamwork->overallfeedbackmode == 2) { $mform->addRule('feedbackauthor_editor', null, 'required', null, 'client'); } if ($this->teamwork->overallfeedbackfiles) { $mform->addElement('filemanager', 'feedbackauthorattachment_filemanager', get_string('feedbackauthorattachment', 'mod_teamwork'), null, $this->teamwork->overall_feedback_attachment_options()); } } if (!empty($this->options['editableweight']) and $this->is_editable()) { $mform->addElement('header', 'assessmentsettings', get_string('assessmentweight', 'teamwork')); $mform->addElement('select', 'weight', get_string('assessmentweight', 'teamwork'), teamwork::available_assessment_weights_list()); $mform->setDefault('weight', 1); } $buttonarray = array(); if ($this->mode == 'preview') { $buttonarray[] = $mform->createElement('cancel', 'backtoeditform', get_string('backtoeditform', 'teamwork')); } if ($this->mode == 'assessment') { if (!empty($this->options['pending'])) { $buttonarray[] = $mform->createElement('submit', 'saveandshownext', get_string('saveandshownext', 'teamwork')); } $buttonarray[] = $mform->createElement('submit', 'saveandclose', get_string('saveandclose', 'teamwork')); $buttonarray[] = $mform->createElement('submit', 'saveandcontinue', get_string('saveandcontinue', 'teamwork')); $buttonarray[] = $mform->createElement('cancel'); } $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); $mform->closeHeaderBefore('buttonar'); }
/** * Triggered when the '\mod_teamwork\event\course_module_viewed' event is triggered. * * This does the same job as {@link teamworkallocation_scheduled_cron()} but for the * single teamwork. The idea is that we do not need to wait for cron to execute. * Displaying the teamwork main view.php can trigger the scheduled allocation, too. * * @param \mod_teamwork\event\course_module_viewed $event * @return bool */ public static function teamwork_viewed($event) { global $DB, $CFG; require_once $CFG->dirroot . '/mod/teamwork/locallib.php'; $teamwork = $event->get_record_snapshot('teamwork', $event->objectid); $course = $event->get_record_snapshot('course', $event->courseid); $cm = $event->get_record_snapshot('course_modules', $event->contextinstanceid); $teamwork = new \teamwork($teamwork, $cm, $course); $now = time(); // Non-expensive check to see if the scheduled allocation can even happen. if ($teamwork->phase == \teamwork::PHASE_SUBMISSION and $teamwork->submissionend > 0 and $teamwork->submissionend < $now) { // Make sure the scheduled allocation has been configured for this teamwork, that it has not // been executed yet and that the passed teamwork record is still valid. $sql = "SELECT a.id\n FROM {teamworkallocation_scheduled} a\n JOIN {teamwork} w ON a.teamworkid = w.id\n WHERE w.id = :teamworkid\n AND a.enabled = 1\n AND w.phase = :phase\n AND w.submissionend > 0\n AND w.submissionend < :now\n AND (a.timeallocated IS NULL OR a.timeallocated < w.submissionend)"; $params = array('teamworkid' => $teamwork->id, 'phase' => \teamwork::PHASE_SUBMISSION, 'now' => $now); if ($DB->record_exists_sql($sql, $params)) { // Allocate submissions for assessments. $allocator = $teamwork->allocator_instance('scheduled'); $result = $allocator->execute(); // Todo inform the teachers about the results. } } return true; }
// course module id $instanceid = required_param('instance', PARAM_INT); $id = optional_param('id', 0, PARAM_INT); // submission id $edit = optional_param('edit', false, PARAM_BOOL); // open for editing? $assess = optional_param('assess', false, PARAM_BOOL); // instant assessment required $cm = get_coursemodule_from_instance('teamwork', $teamwork, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); require_login($course, false, $cm); if (isguestuser()) { print_error('guestsarenotallowed'); } $teamworkrecord = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST); $teamwork = new teamwork($teamworkrecord, $cm, $course); if ($id) { // submission is specified $submission = $teamwork->get_submission_by_id($id); $params = array('objectid' => $submission->id, 'context' => $teamwork->context, 'courseid' => $teamwork->course->id, 'relateduserid' => $submission->authorid, 'other' => array('teamworkid' => $teamwork->id)); $event = \mod_workshop\event\submission_viewed::create($params); $event->trigger(); } $ownsubmission = $submission->authorid == $USER->id; $canviewall = has_capability('mod/teamwork:viewallsubmissions', $teamwork->context); $cansubmit = has_capability('mod/teamwork:submit', $teamwork->context); $canallocate = has_capability('mod/teamwork:allocate', $teamwork->context); $canpublish = has_capability('mod/teamwork:publishsubmissions', $teamwork->context); $canoverride = ($teamwork->phase == teamwork::PHASE_EVALUATION and has_capability('mod/teamwork:overridegrades', $teamwork->context)); $userassessment = $teamwork->get_assessment_of_submission_by_user($submission->id, $USER->id); $isreviewer = !empty($userassessment);
$edit = optional_param('edit', false, PARAM_BOOL); // open for editing? $delete = optional_param('delete', false, PARAM_BOOL); // example removal requested $confirm = optional_param('confirm', false, PARAM_BOOL); // example removal request confirmed $assess = optional_param('assess', false, PARAM_BOOL); // assessment required $cm = get_coursemodule_from_id('teamwork', $cmid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); require_login($course, false, $cm); if (isguestuser()) { print_error('guestsarenotallowed'); } $teamwork = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST); $teamwork = new teamwork($teamwork, $cm, $course); $PAGE->set_url($teamwork->exsubmission_url($id), array('edit' => $edit)); $PAGE->set_title($teamwork->name); $PAGE->set_heading($course->fullname); if ($edit) { $PAGE->navbar->add(get_string('exampleediting', 'teamwork')); } else { $PAGE->navbar->add(get_string('example', 'teamwork')); } $output = $PAGE->get_renderer('mod_teamwork'); if ($id) { // example is specified $example = $teamwork->get_example_by_id($id); } else { // no example specified - create new one require_capability('mod/teamwork:manageexamples', $teamwork->context);
* @package mod_teamwork * @copyright 2009 David Mudrak <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once dirname(__FILE__) . '/locallib.php'; $cmid = required_param('cmid', PARAM_INT); // course module $phase = required_param('phase', PARAM_INT); // the code of the new phase $confirm = optional_param('confirm', false, PARAM_BOOL); // confirmation $cm = get_coursemodule_from_id('teamwork', $cmid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $teamwork = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST); $teamwork = new teamwork($teamwork, $cm, $course); $PAGE->set_url($teamwork->switchphase_url($phase), array('cmid' => $cmid, 'phase' => $phase)); require_login($course, false, $cm); require_capability('mod/teamwork:switchphase', $PAGE->context); if ($confirm) { if (!confirm_sesskey()) { throw new moodle_exception('confirmsesskeybad'); } if (!$teamwork->switch_phase($phase)) { print_error('errorswitchingphase', 'teamwork', $teamwork->view_url()); } redirect($teamwork->view_url()); } $PAGE->set_title($teamwork->name); $PAGE->set_heading($course->fullname); $PAGE->navbar->add(get_string('switchingphase', 'teamwork'));
/** * Renders the teamwork grading report * * @param teamwork_grading_report $gradingreport * @return string html code */ protected function render_teamwork_grading_report(teamwork_grading_report $gradingreport) { $data = $gradingreport->get_data(); $options = $gradingreport->get_options(); $grades = $data->grades; $userinfo = $data->userinfo; if (empty($grades)) { return ''; } $table = new html_table(); $table->attributes['class'] = 'grading-report'; $sortbyfirstname = $this->helper_sortable_heading(get_string('firstname'), 'firstname', $options->sortby, $options->sorthow); $sortbylastname = $this->helper_sortable_heading(get_string('lastname'), 'lastname', $options->sortby, $options->sorthow); if (self::fullname_format() == 'lf') { $sortbyname = $sortbylastname . ' / ' . $sortbyfirstname; } else { $sortbyname = $sortbyfirstname . ' / ' . $sortbylastname; } $table->head = array(); $table->head[] = $sortbyname; $table->head[] = $this->helper_sortable_heading(get_string('submission', 'teamwork'), 'submissiontitle', $options->sortby, $options->sorthow); $table->head[] = $this->helper_sortable_heading(get_string('receivedgrades', 'teamwork')); if ($options->showsubmissiongrade) { $table->head[] = $this->helper_sortable_heading(get_string('submissiongradeof', 'teamwork', $data->maxgrade), 'submissiongrade', $options->sortby, $options->sorthow); } $table->head[] = $this->helper_sortable_heading(get_string('givengrades', 'teamwork')); if ($options->showgradinggrade) { $table->head[] = $this->helper_sortable_heading(get_string('gradinggradeof', 'teamwork', $data->maxgradinggrade), 'gradinggrade', $options->sortby, $options->sorthow); } $table->rowclasses = array(); $table->colclasses = array(); $table->data = array(); foreach ($grades as $participant) { $numofreceived = count($participant->reviewedby); $numofgiven = count($participant->reviewerof); $published = $participant->submissionpublished; // compute the number of <tr> table rows needed to display this participant if ($numofreceived > 0 and $numofgiven > 0) { $numoftrs = teamwork::lcm($numofreceived, $numofgiven); $spanreceived = $numoftrs / $numofreceived; $spangiven = $numoftrs / $numofgiven; } elseif ($numofreceived == 0 and $numofgiven > 0) { $numoftrs = $numofgiven; $spanreceived = $numoftrs; $spangiven = $numoftrs / $numofgiven; } elseif ($numofreceived > 0 and $numofgiven == 0) { $numoftrs = $numofreceived; $spanreceived = $numoftrs / $numofreceived; $spangiven = $numoftrs; } else { $numoftrs = 1; $spanreceived = 1; $spangiven = 1; } for ($tr = 0; $tr < $numoftrs; $tr++) { $row = new html_table_row(); if ($published) { $row->attributes['class'] = 'published'; } // column #1 - participant - spans over all rows if ($tr == 0) { $cell = new html_table_cell(); $cell->text = $this->helper_grading_report_participant($participant, $userinfo); $cell->rowspan = $numoftrs; $cell->attributes['class'] = 'participant'; $row->cells[] = $cell; } // column #2 - submission - spans over all rows if ($tr == 0) { $cell = new html_table_cell(); $cell->text = $this->helper_grading_report_submission($participant); $cell->rowspan = $numoftrs; $cell->attributes['class'] = 'submission'; $row->cells[] = $cell; } // column #3 - received grades if ($tr % $spanreceived == 0) { $idx = intval($tr / $spanreceived); $assessment = self::array_nth($participant->reviewedby, $idx); $cell = new html_table_cell(); $cell->text = $this->helper_grading_report_assessment($assessment, $options->showreviewernames, $userinfo, get_string('gradereceivedfrom', 'teamwork')); $cell->rowspan = $spanreceived; $cell->attributes['class'] = 'receivedgrade'; if (is_null($assessment) or is_null($assessment->grade)) { $cell->attributes['class'] .= ' null'; } else { $cell->attributes['class'] .= ' notnull'; } $row->cells[] = $cell; } // column #4 - total grade for submission if ($options->showsubmissiongrade and $tr == 0) { $cell = new html_table_cell(); $cell->text = $this->helper_grading_report_grade($participant->submissiongrade, $participant->submissiongradeover); $cell->rowspan = $numoftrs; $cell->attributes['class'] = 'submissiongrade'; $row->cells[] = $cell; } // column #5 - given grades if ($tr % $spangiven == 0) { $idx = intval($tr / $spangiven); $assessment = self::array_nth($participant->reviewerof, $idx); $cell = new html_table_cell(); $cell->text = $this->helper_grading_report_assessment($assessment, $options->showauthornames, $userinfo, get_string('gradegivento', 'teamwork')); $cell->rowspan = $spangiven; $cell->attributes['class'] = 'givengrade'; if (is_null($assessment) or is_null($assessment->grade)) { $cell->attributes['class'] .= ' null'; } else { $cell->attributes['class'] .= ' notnull'; } $row->cells[] = $cell; } // column #6 - total grade for assessment if ($options->showgradinggrade and $tr == 0) { $cell = new html_table_cell(); $cell->text = $this->helper_grading_report_grade($participant->gradinggrade); $cell->rowspan = $numoftrs; $cell->attributes['class'] = 'gradinggrade'; $row->cells[] = $cell; } $table->data[] = $row; } } return html_writer::table($table); }
/** * Returns example submissions to be assessed by the owner of the planner * * This is here to cache the DB query because the same list is needed later in view.php * * @see teamwork::get_examples_for_reviewer() for the format of returned value * @return array */ public function get_examples() { if (is_null($this->examples)) { $this->examples = $this->teamwork->get_examples_for_reviewer($this->userid); } return $this->examples; }
$sortby = optional_param('sortby', 'lastname', PARAM_ALPHA); $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA); $eval = optional_param('eval', null, PARAM_PLUGIN); $templetid = optional_param('templetid', 0, PARAM_INT); if ($id) { $cm = get_coursemodule_from_id('teamwork', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $teamworkrecord = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST); } else { $teamworkrecord = $DB->get_record('teamwork', array('id' => $w), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $teamworkrecord->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('teamwork', $teamworkrecord->id, $course->id, false, MUST_EXIST); } require_login($course, true, $cm); require_capability('mod/teamwork:view', $PAGE->context); $teamwork = new teamwork($teamworkrecord, $cm, $course); // Mark viewed $completion = new completion_info($course); $completion->set_module_viewed($cm); $eventdata = array(); $eventdata['objectid'] = $teamwork->id; $eventdata['context'] = $teamwork->context; $PAGE->set_url($teamwork->view_url()); $event = \mod_teamwork\event\course_module_viewed::create($eventdata); $event->add_record_snapshot('course', $course); $event->add_record_snapshot('teamwork', $teamworkrecord); $event->add_record_snapshot('course_modules', $cm); $event->trigger(); if ($teamwork->applyover == 0 and $teamwork->applyend > 0 and $teamwork->applyend < time()) { generate_instanse_from_templet($teamwork->id); $DB->set_field('teamwork', 'applyover', 1, array('id' => $teamwork->id));
/** * Prepares the form before data are set * * Additional wysiwyg editor are prepared here, the introeditor is prepared automatically by core. * Grade items are set here because the core modedit supports single grade item only. * * @param array $data to be set * @return void */ public function data_preprocessing(&$data) { if ($this->current->instance) { // editing an existing teamwork - let us prepare the added editor elements (intro done automatically) $draftitemid = file_get_submitted_draft_itemid('instructauthors'); $data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_teamwork', 'instructauthors', 0, teamwork::instruction_editors_options($this->context), $data['instructauthors']); $data['instructauthorseditor']['format'] = $data['instructauthorsformat']; $data['instructauthorseditor']['itemid'] = $draftitemid; $draftitemid = file_get_submitted_draft_itemid('instructreviewers'); $data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_teamwork', 'instructreviewers', 0, teamwork::instruction_editors_options($this->context), $data['instructreviewers']); $data['instructreviewerseditor']['format'] = $data['instructreviewersformat']; $data['instructreviewerseditor']['itemid'] = $draftitemid; $draftitemid = file_get_submitted_draft_itemid('conclusion'); $data['conclusioneditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_teamwork', 'conclusion', 0, teamwork::instruction_editors_options($this->context), $data['conclusion']); $data['conclusioneditor']['format'] = $data['conclusionformat']; $data['conclusioneditor']['itemid'] = $draftitemid; } else { // adding a new teamwork instance $draftitemid = file_get_submitted_draft_itemid('instructauthors'); file_prepare_draft_area($draftitemid, null, 'mod_teamwork', 'instructauthors', 0); // no context yet, itemid not used $data['instructauthorseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid); $draftitemid = file_get_submitted_draft_itemid('instructreviewers'); file_prepare_draft_area($draftitemid, null, 'mod_teamwork', 'instructreviewers', 0); // no context yet, itemid not used $data['instructreviewerseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid); $draftitemid = file_get_submitted_draft_itemid('conclusion'); file_prepare_draft_area($draftitemid, null, 'mod_teamwork', 'conclusion', 0); // no context yet, itemid not used $data['conclusioneditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid); } }
/** * Edit grading form in for a particular instance of teamwork * * @package mod_teamwork * @copyright 2009 David Mudrak <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once dirname(__FILE__) . '/locallib.php'; require_once dirname(__FILE__) . '/mod_form.php'; $teamworkid = required_param('teamworkid', PARAM_INT); $cm = get_coursemodule_from_instance('teamwork', $teamworkid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); require_login($course, false, $cm); $teamwork = $DB->get_record('teamwork', array('id' => $teamworkid), '*', MUST_EXIST); $teamwork = new teamwork($teamwork, $cm, $course); // todo: check if there already is some assessment done and do not allowed the change of the form // once somebody already used it to assess $jointeam_url = new moodle_url('/mod/teamwork/jointeam.php', array('teamworkid' => $teamworkid)); $PAGE->set_url($jointeam_url); $PAGE->set_title($teamwork->name); $PAGE->set_heading($course->fullname); $PAGE->navbar->add(get_string('joininteam', 'teamwork')); $mform = new teamwork_jointeam_form($course->id, $teamworkid); if ($mform->is_cancelled()) { redirect($teamwork->view_url()); } elseif ($data = $mform->get_data()) { save_data($data); redirect($teamwork->view_url(), get_string('joinedsuccess', 'teamwork'), 1); } // Output starts here
public function test_lcm() { $this->resetAfterTest(true); // fixture setup + exercise SUT + verify in one step $this->assertEquals(teamwork::lcm(1, 4), 4); $this->assertEquals(teamwork::lcm(2, 4), 4); $this->assertEquals(teamwork::lcm(4, 2), 4); $this->assertEquals(teamwork::lcm(2, 3), 6); $this->assertEquals(teamwork::lcm(6, 4), 12); }
* * @package mod_teamwork * @copyright 2009 David Mudrak <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once dirname(__FILE__) . '/locallib.php'; require_once dirname(__FILE__) . '/allocation/lib.php'; $cmid = required_param('cmid', PARAM_INT); // course module $method = optional_param('method', 'manual', PARAM_ALPHA); // method to use $cm = get_coursemodule_from_id('teamwork', $cmid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $teamwork = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST); $teamwork = new teamwork($teamwork, $cm, $course); $PAGE->set_url($teamwork->allocation_url($method)); require_login($course, false, $cm); $context = $PAGE->context; require_capability('mod/teamwork:allocate', $context); $PAGE->set_title($teamwork->name); $PAGE->set_heading($course->fullname); $PAGE->navbar->add(get_string('allocation', 'teamwork')); $allocator = $teamwork->allocator_instance($method); $initresult = $allocator->init(); // // Output starts here // $output = $PAGE->get_renderer('mod_teamwork'); echo $output->header(); echo $OUTPUT->heading(format_string($teamwork->name));
* @package mod_teamwork * @copyright 2009 David Mudrak <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once dirname(__FILE__) . '/locallib.php'; require_once dirname(__FILE__) . '/mod_form.php'; $teamworkid = required_param('teamwork', PARAM_INT); $instanceid = required_param('instance', PARAM_INT); //instance id $cm = get_coursemodule_from_instance('teamwork', $teamworkid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); require_login($course, false, $cm); require_capability('mod/teamwork:editsettings', $PAGE->context); $teamwork = $DB->get_record('teamwork', array('id' => $teamworkid), '*', MUST_EXIST); $teamwork = new teamwork($teamwork, $cm, $course); // todo: check if there already is some assessment done and do not allowed the change of the form // once somebody already used it to assess $instance_edit_url = new moodle_url('/mod/teamwork/instance_edit.php', array('teamwork' => $teamworkid, 'instance' => $instanceid)); $PAGE->set_url($instance_edit_url); $PAGE->set_title($teamwork->name); $PAGE->set_heading($course->fullname); $PAGE->navbar->add(get_string('editingprojectsettings', 'teamwork')); $mform = null; $submit = optional_param('phasenum', 0, PARAM_INT); $data = $DB->get_record('teamwork_instance', array('id' => $instanceid), '*', MUST_EXIST); $mform = new teamwork_instance_form($teamworkid, $instanceid, $submit == 0 ? $data->phase : 0); $savedata = new stdClass(); $savedata->title = $data->title; $savedata->summary['text'] = $data->summary; $savedata->teamminmembers = $data->teamminmember;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once dirname(__FILE__) . '/locallib.php'; $asid = required_param('asid', PARAM_INT); // assessment id $assessment = $DB->get_record('teamwork_assessments', array('id' => $asid), '*', MUST_EXIST); $example = $DB->get_record('teamwork_submissions', array('id' => $assessment->submissionid, 'example' => 1), '*', MUST_EXIST); $teamwork = $DB->get_record('teamwork', array('id' => $example->teamworkid), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $teamwork->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('teamwork', $teamwork->id, $course->id, false, MUST_EXIST); require_login($course, false, $cm); if (isguestuser()) { print_error('guestsarenotallowed'); } $teamwork = new teamwork($teamwork, $cm, $course); $PAGE->set_url($teamwork->exassess_url($assessment->id)); $PAGE->set_title($teamwork->name); $PAGE->set_heading($course->fullname); $PAGE->navbar->add(get_string('assessingexample', 'teamwork')); $currenttab = 'assessment'; $canmanage = has_capability('mod/teamwork:manageexamples', $teamwork->context); $isreviewer = $USER->id == $assessment->reviewerid; if ($isreviewer or $canmanage) { // such a user can continue } else { print_error('nopermissions', 'error', $teamwork->view_url(), 'assess example submission'); } // only the reviewer is allowed to modify the assessment if ($canmanage and $assessment->weight == 1 or $isreviewer and $teamwork->assessing_examples_allowed()) { $assessmenteditable = true;
require_once $CFG->dirroot . '/mod/teamwork/locallib.php'; $grades = teamwork::available_maxgrades_list(); $settings->add(new admin_setting_configselect('teamwork/grade', get_string('submissiongrade', 'teamwork'), get_string('configgrade', 'teamwork'), 80, $grades)); $settings->add(new admin_setting_configselect('teamwork/gradinggrade', get_string('gradinggrade', 'teamwork'), get_string('configgradinggrade', 'teamwork'), 20, $grades)); $options = array(); for ($i = 5; $i >= 0; $i--) { $options[$i] = $i; } $settings->add(new admin_setting_configselect('teamwork/gradedecimals', get_string('gradedecimals', 'teamwork'), get_string('configgradedecimals', 'teamwork'), 0, $options)); if (isset($CFG->maxbytes)) { $maxbytes = get_config('teamwork', 'maxbytes'); $options = get_max_upload_sizes($CFG->maxbytes, 0, 0, $maxbytes); $settings->add(new admin_setting_configselect('teamwork/maxbytes', get_string('maxbytes', 'teamwork'), get_string('configmaxbytes', 'teamwork'), 0, $options)); } $settings->add(new admin_setting_configselect('teamwork/strategy', get_string('strategy', 'teamwork'), get_string('configstrategy', 'teamwork'), 'accumulative', teamwork::available_strategies_list())); $options = teamwork::available_example_modes_list(); $settings->add(new admin_setting_configselect('teamwork/examplesmode', get_string('examplesmode', 'teamwork'), get_string('configexamplesmode', 'teamwork'), teamwork::EXAMPLES_VOLUNTARY, $options)); // include the settings of allocation subplugins $allocators = core_component::get_plugin_list('teamworkallocation'); foreach ($allocators as $allocator => $path) { if (file_exists($settingsfile = $path . '/settings.php')) { $settings->add(new admin_setting_heading('teamworkallocationsetting' . $allocator, get_string('allocation', 'teamwork') . ' - ' . get_string('pluginname', 'teamworkallocation_' . $allocator), '')); include $settingsfile; } } // include the settings of grading strategy subplugins $strategies = core_component::get_plugin_list('teamworkform'); foreach ($strategies as $strategy => $path) { if (file_exists($settingsfile = $path . '/settings.php')) { $settings->add(new admin_setting_heading('teamworkformsetting' . $strategy, get_string('strategy', 'teamwork') . ' - ' . get_string('pluginname', 'teamworkform_' . $strategy), '')); include $settingsfile;
* Various teamwork maintainance utilities * * @package mod_teamwork * @copyright 2010 David Mudrak <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once dirname(__FILE__) . '/locallib.php'; $id = required_param('id', PARAM_INT); // course_module ID $tool = required_param('tool', PARAM_ALPHA); $cm = get_coursemodule_from_id('teamwork', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $teamwork = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST); require_login($course, false, $cm); $teamwork = new teamwork($teamwork, $cm, $course); require_sesskey(); $params = array('context' => $teamwork->context, 'courseid' => $course->id, 'other' => array('teamworkid' => $teamwork->id)); switch ($tool) { case 'clearaggregatedgrades': require_capability('mod/teamwork:overridegrades', $teamwork->context); $teamwork->clear_submission_grades(); $teamwork->clear_grading_grades(); $event = \mod_teamwork\event\assessment_evaluations_reset::create($params); $event->trigger(); break; case 'clearassessments': require_capability('mod/teamwork:overridegrades', $teamwork->context); $teamwork->clear_assessments(); $event = \mod_teamwork\event\assessments_reset::create($params); $event->trigger();
* * @package mod_teamwork * @copyright 2009 David Mudrak <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once dirname(__FILE__) . '/locallib.php'; $cmid = required_param('cmid', PARAM_INT); $cm = get_coursemodule_from_id('teamwork', $cmid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $teamwork = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST); require_login($course, false, $cm); if (isguestuser()) { print_error('guestsarenotallowed'); } $teamwork = new teamwork($teamwork, $cm, $course); require_capability('mod/teamwork:editdimensions', $teamwork->context); $PAGE->set_url($teamwork->previewform_url()); $PAGE->set_title($teamwork->name); $PAGE->set_heading($course->fullname); $PAGE->navbar->add(get_string('editingassessmentform', 'teamwork'), $teamwork->editform_url(), navigation_node::TYPE_CUSTOM); $PAGE->navbar->add(get_string('previewassessmentform', 'teamwork')); $currenttab = 'editform'; // load the grading strategy logic $strategy = $teamwork->grading_strategy_instance(); // load the assessment form $mform = $strategy->get_assessment_form($teamwork->editform_url(), 'preview'); // output starts here echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($teamwork->name)); echo $OUTPUT->heading(get_string('assessmentform', 'teamwork'), 3);
require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once dirname(__FILE__) . '/locallib.php'; $cmid = required_param('cmid', PARAM_INT); // course module id $sid = required_param('sid', PARAM_INT); // example submission id $aid = required_param('aid', PARAM_INT); // the user's assessment id $cm = get_coursemodule_from_id('teamwork', $cmid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); require_login($course, false, $cm); if (isguestuser()) { print_error('guestsarenotallowed'); } $teamwork = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST); $teamwork = new teamwork($teamwork, $cm, $course); $strategy = $teamwork->grading_strategy_instance(); $PAGE->set_url($teamwork->excompare_url($sid, $aid)); $example = $teamwork->get_example_by_id($sid); $assessment = $teamwork->get_assessment_by_id($aid); if ($assessment->submissionid != $example->id) { print_error('invalidarguments'); } $mformassessment = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, false); if ($refasid = $DB->get_field('teamwork_assessments', 'id', array('submissionid' => $example->id, 'weight' => 1))) { $reference = $teamwork->get_assessment_by_id($refasid); $mformreference = $strategy->get_assessment_form($PAGE->url, 'assessment', $reference, false); } $canmanage = has_capability('mod/teamwork:manageexamples', $teamwork->context); $isreviewer = $USER->id == $assessment->reviewerid; if ($canmanage) {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once dirname(__FILE__) . '/locallib.php'; $cmid = required_param('cmid', PARAM_INT); // course module $confirm = optional_param('confirm', false, PARAM_BOOL); // confirmation // the params to be re-passed to view.php $page = optional_param('page', 0, PARAM_INT); $sortby = optional_param('sortby', 'lastname', PARAM_ALPHA); $sorthow = optional_param('sorthow', 'ASC', PARAM_ALPHA); $cm = get_coursemodule_from_id('teamwork', $cmid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $teamwork = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST); $teamwork = new teamwork($teamwork, $cm, $course); $PAGE->set_url($teamwork->aggregate_url(), compact('confirm', 'page', 'sortby', 'sorthow')); require_login($course, false, $cm); require_capability('mod/teamwork:overridegrades', $PAGE->context); // load and init the grading evaluator $evaluator = $teamwork->grading_evaluation_instance(); $settingsform = $evaluator->get_settings_form($PAGE->url); if ($settingsdata = $settingsform->get_data()) { $teamwork->aggregate_submission_grades(); // updates 'grade' in {teamwork_submissions} $evaluator->update_grading_grades($settingsdata); // updates 'gradinggrade' in {teamwork_assessments} $teamwork->aggregate_grading_grades(); // updates 'gradinggrade' in {teamwork_aggregations} } redirect(new moodle_url($teamwork->view_url(), compact('page', 'sortby', 'sorthow')));
$instanceid = optional_param('instance', 0, PARAM_INT); $phase = optional_param('phase', 0, PARAM_INT); $page = optional_param('page', 0, PARAM_INT); $perpage = optional_param('perpage', null, PARAM_INT); if ($id) { $cm = get_coursemodule_from_id('teamwork', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $teamworkrecord = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST); } else { $teamworkrecord = $DB->get_record('teamwork', array('id' => $w), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $teamworkrecord->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('teamwork', $teamworkrecord->id, $course->id, false, MUST_EXIST); } require_login($course, true, $cm); require_capability('mod/teamwork:view', $PAGE->context); $teamwork = new teamwork($teamworkrecord, $cm, $course); if (!is_null($editmode) && $PAGE->user_allowed_editing()) { $USER->editing = $editmode; } $PAGE->set_title($teamwork->name); $PAGE->set_heading($course->fullname); $PAGE->set_url(new moodle_url("/mod/teamwork/project.php", array('w' => $w, 'instance' => $instanceid))); if ($perpage and $perpage > 0 and $perpage <= 1000) { require_sesskey(); set_user_preference('teamwork_perpage', $perpage); redirect($PAGE->url); } $output = $PAGE->get_renderer('mod_teamwork'); /// Output starts here $instancerecord = $DB->get_record('teamwork_instance', array('id' => $instanceid)); $teamrecord = $DB->get_record('teamwork_team', array('id' => $instancerecord->team));
/** * Performs the reset of all teamwork instances in the course. * * @param stdClass $data The actual course reset settings. * @return array List of results, each being array[(string)component, (string)item, (string)error] */ function teamwork_reset_userdata(stdClass $data) { global $CFG, $DB; if (empty($data->reset_teamwork_submissions) and empty($data->reset_teamwork_assessments) and empty($data->reset_teamwork_phase)) { // Nothing to do here. return array(); } $teamworkrecords = $DB->get_records('teamwork', array('course' => $data->courseid)); if (empty($teamworkrecords)) { // What a boring course - no teamworks here! return array(); } require_once $CFG->dirroot . '/mod/teamwork/locallib.php'; $course = $DB->get_record('course', array('id' => $data->courseid), '*', MUST_EXIST); $status = array(); foreach ($teamworkrecords as $teamworkrecord) { $cm = get_coursemodule_from_instance('teamwork', $teamworkrecord->id, $course->id, false, MUST_EXIST); $teamwork = new teamwork($teamworkrecord, $cm, $course); $status = array_merge($status, $teamwork->reset_userdata($data)); } return $status; }
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once dirname(__FILE__) . '/locallib.php'; $asid = required_param('asid', PARAM_INT); // assessment id $assessment = $DB->get_record('teamwork_assessments', array('id' => $asid), '*', MUST_EXIST); $submission = $DB->get_record('teamwork_submissions', array('id' => $assessment->submissionid, 'example' => 0), '*', MUST_EXIST); $teamwork = $DB->get_record('teamwork', array('id' => $submission->teamworkid), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $teamwork->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('teamwork', $teamwork->id, $course->id, false, MUST_EXIST); require_login($course, false, $cm); if (isguestuser()) { print_error('guestsarenotallowed'); } $teamwork = new teamwork($teamwork, $cm, $course); $PAGE->set_url($teamwork->assess_url($assessment->id)); $PAGE->set_title($teamwork->name); $PAGE->set_heading($course->fullname); $PAGE->navbar->add(get_string('assessingsubmission', 'teamwork')); $canviewallassessments = has_capability('mod/teamwork:viewallassessments', $teamwork->context); $canviewallsubmissions = has_capability('mod/teamwork:viewallsubmissions', $teamwork->context); $cansetassessmentweight = has_capability('mod/teamwork:allocate', $teamwork->context); $canoverridegrades = has_capability('mod/teamwork:overridegrades', $teamwork->context); $isreviewer = $USER->id == $assessment->reviewerid; $isauthor = $USER->id == $submission->authorid; if ($canviewallsubmissions) { // check this flag against the group membership yet if (groups_get_activity_groupmode($teamwork->cm) == SEPARATEGROUPS) { // user must have accessallgroups or share at least one group with the submission author if (!has_capability('moodle/site:accessallgroups', $teamwork->context)) {
/** * Edit grading form in for a particular instance of teamwork * * @package mod_teamwork * @copyright 2009 David Mudrak <*****@*****.**> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once dirname(dirname(dirname(__FILE__))) . '/config.php'; require_once dirname(__FILE__) . '/locallib.php'; $cmid = required_param('cmid', PARAM_INT); $cm = get_coursemodule_from_id('teamwork', $cmid, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); require_login($course, false, $cm); require_capability('mod/teamwork:editdimensions', $PAGE->context); $teamwork = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST); $teamwork = new teamwork($teamwork, $cm, $course); // todo: check if there already is some assessment done and do not allowed the change of the form // once somebody already used it to assess $PAGE->set_url($teamwork->editform_url()); $PAGE->set_title($teamwork->name); $PAGE->set_heading($course->fullname); $PAGE->navbar->add(get_string('editingassessmentform', 'teamwork')); // load the grading strategy logic $strategy = $teamwork->grading_strategy_instance(); // load the form to edit the grading strategy dimensions $mform = $strategy->get_edit_strategy_form($PAGE->url); if ($mform->is_cancelled()) { redirect($teamwork->view_url()); } elseif ($data = $mform->get_data()) { if ($data->teamworkid != $teamwork->id or $data->strategy != $teamwork->strategy) { // this may happen if someone changes the teamwork setting while the user had the
/** * Definition of the setting form elements */ public function definition() { global $OUTPUT; $mform = $this->_form; $teamwork = $this->_customdata['teamwork']; $current = $this->_customdata['current']; if (!empty($teamwork->submissionend)) { $strtimeexpected = teamwork::timestamp_formats($teamwork->submissionend); } if (!empty($current->timeallocated)) { $strtimeexecuted = teamwork::timestamp_formats($current->timeallocated); } $mform->addElement('header', 'scheduledallocationsettings', get_string('scheduledallocationsettings', 'teamworkallocation_scheduled')); $mform->addHelpButton('scheduledallocationsettings', 'scheduledallocationsettings', 'teamworkallocation_scheduled'); $mform->addElement('checkbox', 'enablescheduled', get_string('enablescheduled', 'teamworkallocation_scheduled'), get_string('enablescheduledinfo', 'teamworkallocation_scheduled'), 1); $mform->addElement('header', 'scheduledallocationinfo', get_string('currentstatus', 'teamworkallocation_scheduled')); if ($current === false) { $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'teamworkallocation_scheduled'), get_string('resultdisabled', 'teamworkallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/invalid')))); } else { if (!empty($current->timeallocated)) { $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'teamworkallocation_scheduled'), get_string('currentstatusexecution1', 'teamworkallocation_scheduled', $strtimeexecuted) . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/valid')))); if ($current->resultstatus == teamwork_allocation_result::STATUS_EXECUTED) { $strstatus = get_string('resultexecuted', 'teamworkallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/valid'))); } else { if ($current->resultstatus == teamwork_allocation_result::STATUS_FAILED) { $strstatus = get_string('resultfailed', 'teamworkallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/invalid'))); } else { $strstatus = get_string('resultvoid', 'teamworkallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/invalid'))); } } if (!empty($current->resultmessage)) { $strstatus .= html_writer::empty_tag('br') . $current->resultmessage; // yes, this is ugly. better solution suggestions are welcome. } $mform->addElement('static', 'inforesult', get_string('currentstatusresult', 'teamworkallocation_scheduled'), $strstatus); if ($current->timeallocated < $teamwork->submissionend) { $mform->addElement('static', 'infoexpected', get_string('currentstatusnext', 'teamworkallocation_scheduled'), get_string('currentstatusexecution2', 'teamworkallocation_scheduled', $strtimeexpected) . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/caution')))); $mform->addHelpButton('infoexpected', 'currentstatusnext', 'teamworkallocation_scheduled'); } else { $mform->addElement('checkbox', 'reenablescheduled', get_string('currentstatusreset', 'teamworkallocation_scheduled'), get_string('currentstatusresetinfo', 'teamworkallocation_scheduled')); $mform->addHelpButton('reenablescheduled', 'currentstatusreset', 'teamworkallocation_scheduled'); } } else { if (empty($current->enabled)) { $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'teamworkallocation_scheduled'), get_string('resultdisabled', 'teamworkallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/invalid')))); } else { if ($teamwork->phase != teamwork::PHASE_SUBMISSION) { $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'teamworkallocation_scheduled'), get_string('resultfailed', 'teamworkallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/invalid'))) . html_writer::empty_tag('br') . get_string('resultfailedphase', 'teamworkallocation_scheduled')); } else { if (empty($teamwork->submissionend)) { $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'teamworkallocation_scheduled'), get_string('resultfailed', 'teamworkallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/invalid'))) . html_writer::empty_tag('br') . get_string('resultfaileddeadline', 'teamworkallocation_scheduled')); } else { if ($teamwork->submissionend < time()) { // next cron will execute it $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'teamworkallocation_scheduled'), get_string('currentstatusexecution4', 'teamworkallocation_scheduled') . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/caution')))); } else { $mform->addElement('static', 'infostatus', get_string('currentstatusexecution', 'teamworkallocation_scheduled'), get_string('currentstatusexecution3', 'teamworkallocation_scheduled', $strtimeexpected) . ' ' . html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/caution')))); } } } } } } parent::definition(); $mform->addHelpButton('randomallocationsettings', 'randomallocationsettings', 'teamworkallocation_scheduled'); }
/** * Regular jobs to execute via cron */ function teamworkallocation_scheduled_cron() { global $CFG, $DB; $sql = "SELECT w.*\n FROM {teamworkallocation_scheduled} a\n JOIN {teamwork} w ON a.teamworkid = w.id\n WHERE a.enabled = 1\n AND w.phase = 20\n AND w.submissionend > 0\n AND w.submissionend < ?\n AND (a.timeallocated IS NULL OR a.timeallocated < w.submissionend)"; $teamworks = $DB->get_records_sql($sql, array(time())); if (empty($teamworks)) { mtrace('... no teamworks awaiting scheduled allocation. ', ''); return; } mtrace('... executing scheduled allocation in ' . count($teamworks) . ' teamwork(s) ... ', ''); // let's have some fun! require_once $CFG->dirroot . '/mod/teamwork/locallib.php'; foreach ($teamworks as $teamwork) { $cm = get_coursemodule_from_instance('teamwork', $teamwork->id, $teamwork->course, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $teamwork = new teamwork($teamwork, $cm, $course); $allocator = $teamwork->allocator_instance('scheduled'); $result = $allocator->execute(); // todo inform the teachers about the results } }
$w = optional_param('w', 0, PARAM_INT); // teamwork instance ID\ $page = optional_param('page', 0, PARAM_INT); $perpage = optional_param('perpage', null, PARAM_INT); if ($id) { $cm = get_coursemodule_from_id('teamwork', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $teamworkrecord = $DB->get_record('teamwork', array('id' => $cm->instance), '*', MUST_EXIST); } else { $teamworkrecord = $DB->get_record('teamwork', array('id' => $w), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $teamworkrecord->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('teamwork', $teamworkrecord->id, $course->id, false, MUST_EXIST); } require_login($course, true, $cm); require_capability('mod/teamwork:view', $PAGE->context); $teamwork = new teamwork($teamworkrecord, $cm, $course); if (!is_null($editmode) && $PAGE->user_allowed_editing()) { $USER->editing = $editmode; } $PAGE->set_title($teamwork->name); $PAGE->set_heading($course->fullname); $PAGE->set_url(new moodle_url("/mod/teamwork/project.php", array('w' => $w, 'instance' => $instanceid))); $output = $PAGE->get_renderer('mod_teamwork'); /// Output starts here echo $output->header(); $user_record = $DB->get_record('user', array('id' => $uid)); $team_member_record = $DB->get_record('teamwork_teammembers', array('userid' => $uid)); $teamid = $team_member_record->team; $team_record = $DB->get_record('teamwork_team', array('id' => $teamid)); $project_record = $DB->get_record('teamwork_instance', array('team' => $teamid)); echo $output->heading(format_string($project_record->title . '@' . $team_record->name . ':' . $user_record->lastname . ' ' . $user_record->firstname));