Example #1
0
 /**
  * Build this UI element.
  *
  * @return element
  */
 public function determine_format()
 {
     $decimals = $this->item->get_decimals();
     $min = format_float($this->item->grademin, $decimals);
     $max = format_float($this->item->grademax, $decimals);
     return new empty_element("{$min} - {$max}");
 }
 function col_frequency($response){
     if ($this->question->_stats->s){
         return format_float((($response->rcount / $this->question->_stats->s)*100),2).'%';
     } else {
         return '';
     }
 }
 public function test_adaptive_multichoice()
 {
     // Create a multiple choice, single response question.
     $mc = test_question_maker::make_a_multichoice_single_question();
     $mc->penalty = 0.3333333;
     $this->start_attempt_at_question($mc, 'adaptive', 3);
     $rightindex = $this->get_mc_right_answer_index($mc);
     $wrongindex = ($rightindex + 1) % 3;
     // Check the initial state.
     $this->check_current_state(question_state::$todo);
     $this->check_current_mark(null);
     $this->check_current_output($this->get_contains_marked_out_of_summary(), $this->get_contains_question_text_expectation($mc), $this->get_contains_mc_radio_expectation(0, true, false), $this->get_contains_mc_radio_expectation(1, true, false), $this->get_contains_mc_radio_expectation(2, true, false), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_feedback_expectation());
     // Process a submit.
     $this->process_submission(array('answer' => $wrongindex, '-submit' => 1));
     // Verify.
     $this->check_current_state(question_state::$todo);
     $this->check_current_mark(0);
     $this->check_current_output($this->get_contains_mark_summary(0), $this->get_contains_mc_radio_expectation($wrongindex, true, true), $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false), $this->get_contains_mc_radio_expectation(($wrongindex + 2) % 3, true, false), $this->get_contains_incorrect_expectation());
     $this->assertPattern('/B|C/', $this->quba->get_response_summary($this->slot));
     // Process a change of answer to the right one, but not sumbitted.
     $this->process_submission(array('answer' => $rightindex));
     // Verify.
     $this->check_current_state(question_state::$todo);
     $this->check_current_mark(0);
     $this->check_current_output($this->get_contains_mark_summary(0), $this->get_contains_mc_radio_expectation($rightindex, true, true), $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false), $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false));
     $this->assertPattern('/B|C/', $this->quba->get_response_summary($this->slot));
     // Now submit the right answer.
     $this->process_submission(array('answer' => $rightindex, '-submit' => 1));
     // Verify.
     $this->check_current_state(question_state::$complete);
     $this->check_current_mark(3 * (1 - $mc->penalty));
     $this->check_current_output($this->get_contains_mark_summary(3 * (1 - $mc->penalty)), $this->get_contains_mc_radio_expectation($rightindex, true, true), $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false), $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false), $this->get_contains_correct_expectation(), new PatternExpectation('/' . preg_quote(get_string('gradingdetailspenalty', 'qbehaviour_adaptive', format_float($mc->penalty, $this->displayoptions->markdp))) . '/'));
     $this->assertEqual('A', $this->quba->get_response_summary($this->slot));
     // Finish the attempt.
     $this->quba->finish_all_questions();
     // Verify.
     $this->check_current_state(question_state::$gradedright);
     $this->check_current_mark(3 * (1 - $mc->penalty));
     $this->check_current_output($this->get_contains_mark_summary(3 * (1 - $mc->penalty)), $this->get_contains_mc_radio_expectation($rightindex, false, true), $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false), $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, false, false), $this->get_contains_correct_expectation());
     // Process a manual comment.
     $this->manual_grade('Not good enough!', 1);
     // Verify.
     $this->check_current_state(question_state::$mangrpartial);
     $this->check_current_mark(1);
     $this->check_current_output($this->get_contains_mark_summary(1), new PatternExpectation('/' . preg_quote('Not good enough!') . '/'));
     // Now change the correct answer to the question, and regrade.
     $mc->answers[13]->fraction = -0.33333333;
     $mc->answers[15]->fraction = 1;
     $this->quba->regrade_all_questions();
     // Verify.
     $this->check_current_state(question_state::$mangrpartial);
     $this->check_current_mark(1);
     $this->check_current_output($this->get_contains_mark_summary(1), $this->get_contains_partcorrect_expectation());
     $autogradedstep = $this->get_step($this->get_step_count() - 2);
     $this->assertWithinMargin($autogradedstep->get_fraction(), 0, 1.0E-7);
 }
Example #4
0
 /**
  * Get the value for this input.
  *
  * @return string The value based on the grade_grade.
  */
 public function get_value()
 {
     $this->label = $this->grade->grade_item->itemname;
     $val = $this->grade->finalgrade;
     if ($this->grade->grade_item->scaleid) {
         return $val ? (int) $val : -1;
     } else {
         return $val ? format_float($val, $this->grade->grade_item->get_decimals()) : '';
     }
 }
Example #5
0
 /**
  * Get the value for this input.
  *
  * @return string The value based on the grade_grade.
  */
 public function get_value()
 {
     $this->label = $this->grade->grade_item->itemname;
     // Manual item raw grade support.
     $val = $this->grade->grade_item->is_manual_item() && !is_null($this->grade->rawgrade) ? $this->grade->rawgrade : $this->grade->finalgrade;
     if ($this->grade->grade_item->scaleid) {
         return $val ? (int) $val : -1;
     } else {
         return $val ? format_float($val, $this->grade->grade_item->get_decimals()) : '';
     }
 }
Example #6
0
function get_course_cost($plugininstance)
{
    $defaultplugin = enrol_get_plugin('authorize');
    $cost = (double) 0;
    $currency = !empty($plugininstance->currency) ? $plugininstance->currency : (empty($defaultplugin->currency) ? 'USD' : $defaultplugin->enrol_currency);
    if (!empty($plugininstance->cost)) {
        $cost = (double) ((double) $plugininstance->cost < 0) ? $defaultplugin->cost : $plugininstance->cost;
    }
    $cost = format_float($cost, 2);
    $ret = array('cost' => $cost, 'currency' => $currency);
    return $ret;
}
Example #7
0
function get_course_cost($course)
{
    global $CFG;
    $cost = (double) 0;
    $currency = !empty($course->currency) ? $course->currency : (empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency);
    if (!empty($course->cost)) {
        $cost = (double) ((double) $course->cost < 0) ? $CFG->enrol_cost : $course->cost;
    }
    $cost = format_float($cost, 2);
    $ret = array('cost' => $cost, 'currency' => $currency);
    return $ret;
}
 /**
  * Add appropriate form elements to the critieria form
  *
  * @param moodle_form $mform Moodle forms object
  * @param stdClass $data containing default values to be set in the form
  */
 public function config_form_display(&$mform, $data = null)
 {
     $mform->addElement('checkbox', 'criteria_grade', get_string('enable'));
     $mform->addElement('text', 'criteria_grade_value', get_string('graderequired', 'completion'));
     $mform->disabledIf('criteria_grade_value', 'criteria_grade');
     $mform->setType('criteria_grade_value', PARAM_RAW);
     // Uses unformat_float.
     $mform->setDefault('criteria_grade_value', format_float($data));
     if ($this->id) {
         $mform->setDefault('criteria_grade', 1);
         $mform->setDefault('criteria_grade_value', format_float($this->gradepass));
     }
 }
 public static function results_as_columns($results)
 {
     $header[] = get_string('choiceoptions', 'choice');
     $votes[] = get_string('numberofuser', 'choice');
     $percent[] = get_string('numberofuserinpercentage', 'choice');
     $graph[] = get_string('responsesresultgraphheader', 'choice');
     foreach ($results as $result) {
         $header[] = $result['text'];
         $votes[] = $result['votes'];
         $percent[] = format_float($result['percent'], 1) . '%';
         $graph[] = progress::level($result['percent']);
     }
     return array('header' => $header, 'rows' => array($votes, $percent, $graph));
 }
Example #10
0
 public function test_quiz_rescale_grade()
 {
     $quiz = new stdClass();
     $quiz->decimalpoints = 2;
     $quiz->questiondecimalpoints = 3;
     $quiz->grade = 10;
     $quiz->sumgrades = 10;
     $this->assertEquals(quiz_rescale_grade(0.12345678, $quiz, false), 0.12345678);
     $this->assertEquals(quiz_rescale_grade(0.12345678, $quiz, true), format_float(0.12, 2));
     $this->assertEquals(quiz_rescale_grade(0.12345678, $quiz, 'question'), format_float(0.123, 3));
     $quiz->sumgrades = 5;
     $this->assertEquals(quiz_rescale_grade(0.12345678, $quiz, false), 0.24691356);
     $this->assertEquals(quiz_rescale_grade(0.12345678, $quiz, true), format_float(0.25, 2));
     $this->assertEquals(quiz_rescale_grade(0.12345678, $quiz, 'question'), format_float(0.247, 3));
 }
 /**
  * Get the value for this input.
  *
  * @return string The value based on the grade_grade.
  */
 public function get_value()
 {
     $this->label = $this->grade->grade_item->itemname;
     $isoverridden = $this->grade->is_overridden();
     if (!empty($isoverridden)) {
         $val = $this->grade->finalgrade;
     } else {
         $val = $this->grade->rawgrade;
     }
     if ($this->grade->grade_item->scaleid) {
         return $val ? (int) $val : -1;
     } else {
         return $val ? format_float($val, $this->grade->grade_item->get_decimals()) : '';
     }
 }
Example #12
0
 function definition()
 {
     $mform = $this->_form;
     list($instance, $plugin, $context) = $this->_customdata;
     $mform->addElement('header', 'header', get_string('pluginname', 'enrol_ipay'));
     $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
     $mform->setType('name', PARAM_TEXT);
     $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), ENROL_INSTANCE_DISABLED => get_string('no'));
     $mform->addElement('select', 'status', get_string('status', 'enrol_ipay'), $options);
     $mform->setDefault('status', $plugin->get_config('status'));
     $mform->addElement('text', 'businessname', get_string('businessname', 'enrol_ipay'));
     $mform->setType('businessname', PARAM_TEXT);
     // test if i can see business name
     $mform->setDefault('businessname', $plugin->get_config('businessname'));
     //this faetches from the configured setings the business name
     $mform->addElement('text', 'cost', get_string('cost', 'enrol_ipay'), array('size' => 4));
     $mform->setType('cost', PARAM_RAW);
     // Use unformat_float to get real value.
     $mform->setDefault('cost', format_float($plugin->get_config('cost'), 2, true));
     $ipaycurrencies = $plugin->get_currencies();
     $mform->addElement('select', 'currency', get_string('currency', 'enrol_ipay'), $ipaycurrencies);
     $mform->setDefault('currency', $plugin->get_config('currency'));
     if ($instance->id) {
         $roles = get_default_enrol_roles($context, $instance->roleid);
     } else {
         $roles = get_default_enrol_roles($context, $plugin->get_config('roleid'));
     }
     $mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_ipay'), $roles);
     $mform->setDefault('roleid', $plugin->get_config('roleid'));
     $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod', 'enrol_ipay'), array('optional' => true, 'defaultunit' => 86400));
     $mform->setDefault('enrolperiod', $plugin->get_config('enrolperiod'));
     $mform->addHelpButton('enrolperiod', 'enrolperiod', 'enrol_ipay');
     $mform->addElement('date_time_selector', 'enrolstartdate', get_string('enrolstartdate', 'enrol_ipay'), array('optional' => true));
     $mform->setDefault('enrolstartdate', 0);
     $mform->addHelpButton('enrolstartdate', 'enrolstartdate', 'enrol_ipay');
     $mform->addElement('date_time_selector', 'enrolenddate', get_string('enrolenddate', 'enrol_ipay'), array('optional' => true));
     $mform->setDefault('enrolenddate', 0);
     $mform->addHelpButton('enrolenddate', 'enrolenddate', 'enrol_ipay');
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'courseid');
     $mform->setType('courseid', PARAM_INT);
     if (enrol_accessing_via_instance($instance)) {
         $mform->addElement('static', 'selfwarn', get_string('instanceeditselfwarning', 'core_enrol'), get_string('instanceeditselfwarningtext', 'core_enrol'));
     }
     $this->add_action_buttons(true, $instance->id ? null : get_string('addinstance', 'enrol'));
     $this->set_data($instance);
 }
Example #13
0
 /**
  * Get the value for this input.
  *
  * @return string The value based on the grade_grade.
  */
 public function get_value()
 {
     $this->label = $this->grade->grade_item->itemname;
     $isoverridden = $this->grade->is_overridden();
     // If the grade is overridden or the grade type is not an activity then use finalgrade.
     if (!empty($isoverridden) || $this->grade->grade_item->itemtype != 'mod') {
         $val = $this->grade->finalgrade;
     } else {
         $val = $this->grade->rawgrade;
     }
     if ($this->grade->grade_item->scaleid) {
         return $val ? (int) $val : -1;
     } else {
         return $val ? format_float($val, $this->grade->grade_item->get_decimals()) : '';
     }
 }
 public function test_quiz_format_question_grade()
 {
     $quiz = new stdClass();
     $quiz->decimalpoints = 2;
     $quiz->questiondecimalpoints = 2;
     $this->assertEquals(quiz_format_question_grade($quiz, 0.12345678), format_float(0.12, 2));
     $this->assertEquals(quiz_format_question_grade($quiz, 0), format_float(0, 2));
     $this->assertEquals(quiz_format_question_grade($quiz, 1.0), format_float(1, 2));
     $quiz->decimalpoints = 3;
     $quiz->questiondecimalpoints = -1;
     $this->assertEquals(quiz_format_question_grade($quiz, 0.12345678), format_float(0.123, 3));
     $this->assertEquals(quiz_format_question_grade($quiz, 0), format_float(0, 3));
     $this->assertEquals(quiz_format_question_grade($quiz, 1.0), format_float(1, 3));
     $quiz->questiondecimalpoints = 4;
     $this->assertEquals(quiz_format_question_grade($quiz, 0.12345678), format_float(0.1235, 4));
     $this->assertEquals(quiz_format_question_grade($quiz, 0), format_float(0, 4));
     $this->assertEquals(quiz_format_question_grade($quiz, 1.0), format_float(1, 4));
 }
 public function feedback(question_attempt $qa, question_display_options $options)
 {
     if (!$options->feedback) {
         return '';
     }
     if ($qa->get_state() == question_state::$gaveup || $qa->get_state() == question_state::$mangaveup) {
         return '';
     }
     $feedback = '';
     if (!$qa->get_last_behaviour_var('certainty') && $qa->get_last_behaviour_var('_assumedcertainty')) {
         $feedback .= html_writer::tag('p', get_string('assumingcertainty', 'qbehaviour_deferredcbm', question_cbm::get_string($qa->get_last_behaviour_var('_assumedcertainty'))));
     }
     if ($options->marks >= question_display_options::MARK_AND_MAX) {
         $a->rawmark = format_float($qa->get_last_behaviour_var('_rawfraction') * $qa->get_max_mark(), $options->markdp);
         $a->mark = $qa->format_mark($options->markdp);
         $feedback .= html_writer::tag('p', get_string('markadjustment', 'qbehaviour_deferredcbm', $a));
     }
     return $feedback;
 }
 protected function get_other_values(renderer_base $output)
 {
     $proficientcompetencypercentage = 0;
     $proficientcompetencypercentageformatted = '';
     if ($this->data->competencycount > 0) {
         $proficientcompetencypercentage = (double) $this->data->proficientcompetencycount / (double) $this->data->competencycount * 100.0;
         $proficientcompetencypercentageformatted = format_float($proficientcompetencypercentage);
     }
     $competencies = array();
     $contextcache = array();
     foreach ($this->data->leastproficientcompetencies as $competency) {
         if (!isset($contextcache[$competency->get_competencyframeworkid()])) {
             $contextcache[$competency->get_competencyframeworkid()] = $competency->get_context();
         }
         $context = $contextcache[$competency->get_competencyframeworkid()];
         $exporter = new competency_exporter($competency, array('context' => $context));
         $competencies[] = $exporter->export($output);
     }
     return array('proficientcompetencypercentage' => $proficientcompetencypercentage, 'proficientcompetencypercentageformatted' => $proficientcompetencypercentageformatted, 'leastproficient' => $competencies, 'leastproficientcount' => count($competencies), 'canbegradedincourse' => has_capability('moodle/competency:coursecompetencygradable', $this->related['context']), 'canmanagecoursecompetencies' => has_capability('moodle/competency:coursecompetencymanage', $this->related['context']));
 }
Example #17
0
 /**
  * Defines forms elements
  */
 public function definition()
 {
     $mform = $this->_form;
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('paypalname', 'paypal'), array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEAN);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $mform->addHelpButton('name', 'paypalname', 'paypal');
     $this->standard_intro_elements();
     $mform->addElement('text', 'businessemail', get_string('businessemail', 'paypal'));
     $mform->setType('businessemail', PARAM_EMAIL);
     $mform->setDefault('businessemail', '');
     $mform->addElement('text', 'cost', get_string('cost', 'paypal'), array('size' => 4));
     $mform->setType('cost', PARAM_FLOAT);
     $mform->setDefault('cost', format_float(0, 2, true));
     $paypalcurrencies = $this->get_currencies();
     $mform->addElement('select', 'currency', get_string('currency', 'paypal'), $paypalcurrencies);
     $mform->setDefault('currency', 'BRL');
     $mform->addElement('text', 'itemname', get_string('itemname', 'paypal'));
     $mform->setType('itemname', PARAM_TEXT);
     $mform->setDefault('itemname', '');
     $mform->addElement('text', 'itemnumber', get_string('itemnumber', 'paypal'));
     $mform->setType('itemnumber', PARAM_TEXT);
     $mform->setDefault('itemnumber', '');
     $mform->addElement('checkbox', 'mailadmins', get_string('mailadmins', 'paypal'));
     $mform->addHelpButton('mailadmins', 'mailadmins', 'paypal');
     $mform->addElement('checkbox', 'mailstudents', get_string('mailstudents', 'paypal'));
     $mform->addHelpButton('mailstudents', 'mailstudents', 'paypal');
     $mform->addElement('checkbox', 'mailteachers', get_string('mailteachers', 'paypal'));
     $mform->addHelpButton('mailteachers', 'mailteachers', 'paypal');
     $this->standard_grading_coursemodule_elements();
     $this->standard_coursemodule_elements();
     $this->add_action_buttons();
 }
Example #18
0
 function display_browse_field($recordid, $template)
 {
     if ($content = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid)) {
         if (strlen($content->content) < 1) {
             return false;
         }
         $number = $content->content;
         $decimals = trim($this->field->param1);
         // only apply number formatting if param1 contains an integer number >= 0:
         if (preg_match("/^\\d+\$/", $decimals)) {
             $decimals = $decimals * 1;
             // removes leading zeros (eg. '007' -> '7'; '00' -> '0')
             $str = format_float($number, $decimals, true);
             // For debugging only:
             #                $str .= " ($decimals)";
         } else {
             $str = $number;
         }
         return $str;
     }
     return false;
 }
Example #19
0
    public function feedback(question_attempt $qa, question_display_options $options) {
        // Try to find the last graded step.

        $gradedstep = $this->get_graded_step($qa);
        if (is_null($gradedstep) || $qa->get_max_mark() == 0 ||
                $options->marks < question_display_options::MARK_AND_MAX) {
            return '';
        }

        // Display the grading details from the last graded state
        $mark = new stdClass();
        $mark->max = $qa->format_max_mark($options->markdp);

        $actualmark = $gradedstep->get_fraction() * $qa->get_max_mark();
        $mark->cur = format_float($actualmark, $options->markdp);

        $rawmark = $gradedstep->get_behaviour_var('_rawfraction') * $qa->get_max_mark();
        $mark->raw = format_float($rawmark, $options->markdp);

        // let student know wether the answer was correct
        if ($qa->get_state()->is_commented()) {
            $class = $qa->get_state()->get_feedback_class();
        } else {
            $class = question_state::graded_state_for_fraction(
                    $gradedstep->get_behaviour_var('_rawfraction'))->get_feedback_class();
        }

        $gradingdetails = get_string('gradingdetails', 'qbehaviour_adaptive', $mark);

        $gradingdetails .= $this->penalty_info($qa, $mark);

        $output = '';
        $output .= html_writer::tag('div', get_string($class, 'question'),
                array('class' => 'correctness ' . $class));
        $output .= html_writer::tag('div', $gradingdetails,
                array('class' => 'gradingdetails'));
        return $output;
    }
function offlinequiz_get_question_infostring($offlinequiz, $question)
{
    if ($offlinequiz->showgrades || $offlinequiz->showquestioninfo) {
        $infostr = '(';
        $questioninfo = offlinequiz_get_questioninfo($offlinequiz, $question);
        if ($questioninfo) {
            $infostr .= $questioninfo;
            if ($offlinequiz->showgrades) {
                $infostr .= ', ';
            }
        }
        if ($offlinequiz->showgrades) {
            $pointstr = get_string('points', 'grades');
            if ($question->maxmark == 1) {
                $pointstr = get_string('point', 'offlinequiz');
            }
            $infostr = $infostr . format_float($question->maxmark, $offlinequiz->decimalpoints) . ' ' . $pointstr;
        }
        $infostr = $infostr . ')';
        return $infostr;
    }
    return null;
}
 protected function get_other_values(renderer_base $output)
 {
     $linkedcompetencycount = $this->data->competencycount - $this->data->unlinkedcompetencycount;
     if ($linkedcompetencycount < 0) {
         // Should never happen.
         $linkedcompetencycount = 0;
     }
     $linkedcompetencypercentage = 0;
     $linkedcompetencypercentageformatted = '';
     if ($this->data->competencycount > 0) {
         $linkedcompetencypercentage = (double) $linkedcompetencycount / (double) $this->data->competencycount * 100.0;
         $linkedcompetencypercentageformatted = format_float($linkedcompetencypercentage);
     }
     $completedplanpercentage = 0;
     $completedplanpercentageformatted = '';
     if ($this->data->plancount > 0) {
         $completedplanpercentage = (double) $this->data->completedplancount / (double) $this->data->plancount * 100.0;
         $completedplanpercentageformatted = format_float($completedplanpercentage);
     }
     $proficientusercompetencyplanpercentage = 0;
     $proficientusercompetencyplanpercentageformatted = '';
     if ($this->data->usercompetencyplancount > 0) {
         $proficientusercompetencyplanpercentage = (double) $this->data->proficientusercompetencyplancount / (double) $this->data->usercompetencyplancount * 100.0;
         $proficientusercompetencyplanpercentageformatted = format_float($proficientusercompetencyplanpercentage);
     }
     $competencies = array();
     $contextcache = array();
     foreach ($this->data->leastproficientcompetencies as $competency) {
         if (!isset($contextcache[$competency->get_competencyframeworkid()])) {
             $contextcache[$competency->get_competencyframeworkid()] = $competency->get_context();
         }
         $context = $contextcache[$competency->get_competencyframeworkid()];
         $exporter = new competency_exporter($competency, array('context' => $context));
         $competencies[] = $exporter->export($output);
     }
     return array('linkedcompetencycount' => $linkedcompetencycount, 'linkedcompetencypercentage' => $linkedcompetencypercentage, 'linkedcompetencypercentageformatted' => $linkedcompetencypercentageformatted, 'completedplanpercentage' => $completedplanpercentage, 'completedplanpercentageformatted' => $completedplanpercentageformatted, 'proficientusercompetencyplanpercentage' => $proficientusercompetencyplanpercentage, 'proficientusercompetencyplanpercentageformatted' => $proficientusercompetencyplanpercentageformatted, 'leastproficient' => $competencies, 'leastproficientcount' => count($competencies));
 }
Example #22
0
 /**
  * Calculates the real value of a grade
  *
  * @param float $value percentual value from 0 to 100
  * @param float $max   the maximal grade
  * @return string
  */
 public function real_grade_value($value, $max) {
     $localized = true;
     if (is_null($value) or $value === '') {
         return null;
     } elseif ($max == 0) {
         return 0;
     } else {
         return format_float($max * $value / 100, $this->gradedecimals, $localized);
     }
 }
Example #23
0
 function get_access_icons($course)
 {
     global $CFG;
     $str = '';
     if ((double) $course->cost < 0) {
         $cost = (double) $CFG->enrol_cost;
     } else {
         $cost = (double) $course->cost;
     }
     if (abs($cost) < 0.01) {
         $manual = enrolment_factory::factory('manual');
         $str = $manual->get_access_icons($course);
     } else {
         $strrequirespayment = get_string("requirespayment");
         $strcost = get_string("cost");
         if (empty($CFG->enrol_currency)) {
             set_config('enrol_currency', 'USD');
         }
         switch ($CFG->enrol_currency) {
             case 'EUR':
                 $currency = '&euro;';
                 break;
             case 'CAD':
                 $currency = '$';
                 break;
             case 'GBP':
                 $currency = '&pound;';
                 break;
             case 'JPY':
                 $currency = '&yen;';
                 break;
             case 'AUD':
                 $currency = '$';
                 break;
             default:
                 $currency = '$';
                 break;
         }
         $str .= '<div class="cost" title="' . $strrequirespayment . '">' . $strcost . ': ';
         $str .= $currency . format_float($cost, 2) . '</div>';
     }
     return $str;
 }
Example #24
0
 function print_row_stats_data(&$q)
 {
     $qid = $q['id'];
     $question = get_record('question', 'id', $qid);
     $options = new stdClass();
     $options->para = false;
     $options->noclean = true;
     $options->newlines = false;
     $qtype = $question->qtype;
     $qname = format_text($question->name, FORMAT_MOODLE, $options);
     $qtext = format_text($question->questiontext, FORMAT_MOODLE, $options);
     $responses = array();
     foreach ($q['responses'] as $aid => $resp) {
         $response = new stdClass();
         if ($q['credits'][$aid] <= 0) {
             $qclass = 'uncorrect';
         } elseif ($q['credits'][$aid] == 1) {
             $qclass = 'correct';
         } else {
             $qclass = 'partialcorrect';
         }
         $response->credit = " (" . format_float($q['credits'][$aid], 2) . ") ";
         $response->text = format_text("{$resp}", FORMAT_MOODLE, $options);
         $count = $q['rcounts'][$aid] . '/' . $q['count'];
         $response->rcount = $count;
         $response->rpercent = '(' . format_float($q['rcounts'][$aid] / $q['count'] * 100, 0) . '%)';
         $responses[] = $response;
     }
     $count = format_float($q['count'], 0);
     $facility = format_float($q['facility'] * 100, 0);
     $qsd = format_float($q['qsd'], 4);
     $di = format_float($q['disc_index'], 3);
     $dc = format_float($q['disc_coeff'], 3);
     $result = array();
     $response = array_shift($responses);
     $result[] = array($qid, $qtype, $qname, $qtext, $response->text, $response->credit, $response->rcount, $response->rpercent, $count, $facility, $qsd, $di, $dc);
     foreach ($responses as $response) {
         $result[] = array('', '', '', '', $response->text, $response->credit, $response->rcount, $response->rpercent, '', '', '', '', '');
     }
     return $result;
 }
Example #25
0
 /**
  * This function is called after the table has been built and the aggregationhints
  * have been collected. We need this info to walk up the list of parents of each
  * grade_item.
  *
  * @param $element - An array containing the table data for the current row.
  */
 public function fill_contributions_column($element)
 {
     // Recursively iterate through all child elements.
     if (isset($element['children'])) {
         foreach ($element['children'] as $key => $child) {
             $this->fill_contributions_column($element['children'][$key]);
         }
     } else {
         if ($element['type'] == 'item') {
             // This is a grade item (We don't do this for categories or we would double count).
             $grade_object = $element['object'];
             $itemid = $grade_object->id;
             // Ignore anything with no hint - e.g. a hidden row.
             if (isset($this->aggregationhints[$itemid])) {
                 // Normalise the gradeval.
                 $gradecat = $grade_object->load_parent_category();
                 if ($gradecat->aggregation == GRADE_AGGREGATE_SUM) {
                     // Natural aggregation/Sum of grades does not consider the mingrade, cannot traditionnally normalise it.
                     $graderange = $this->aggregationhints[$itemid]['grademax'];
                     if ($graderange != 0) {
                         $gradeval = $this->aggregationhints[$itemid]['grade'] / $graderange;
                     } else {
                         $gradeval = 0;
                     }
                 } else {
                     $gradeval = grade_grade::standardise_score($this->aggregationhints[$itemid]['grade'], $this->aggregationhints[$itemid]['grademin'], $this->aggregationhints[$itemid]['grademax'], 0, 1);
                 }
                 // Multiply the normalised value by the weight
                 // of all the categories higher in the tree.
                 $parent = null;
                 do {
                     if (!is_null($this->aggregationhints[$itemid]['weight'])) {
                         $gradeval *= $this->aggregationhints[$itemid]['weight'];
                     } else {
                         if (empty($parent)) {
                             // If we are in the first loop, and the weight is null, then we cannot calculate the contribution.
                             $gradeval = null;
                             break;
                         }
                     }
                     // The second part of this if is to prevent infinite loops
                     // in case of crazy data.
                     if (isset($this->aggregationhints[$itemid]['parent']) && $this->aggregationhints[$itemid]['parent'] != $itemid) {
                         $parent = $this->aggregationhints[$itemid]['parent'];
                         $itemid = $parent;
                     } else {
                         // We are at the top of the tree.
                         $parent = false;
                     }
                 } while ($parent);
                 // Finally multiply by the course grademax.
                 if (!is_null($gradeval)) {
                     // Convert to percent.
                     $gradeval *= 100;
                 }
                 // Now we need to loop through the "built" table data and update the
                 // contributions column for the current row.
                 $header_row = "row_{$grade_object->id}_{$this->user->id}";
                 foreach ($this->tabledata as $key => $row) {
                     if (isset($row['itemname']) && $row['itemname']['id'] == $header_row) {
                         // Found it - update the column.
                         $content = '-';
                         if (!is_null($gradeval)) {
                             $decimals = $grade_object->get_decimals();
                             $content = format_float($gradeval, $decimals, true) . ' %';
                         }
                         $this->tabledata[$key]['contributiontocoursetotal']['content'] = $content;
                         break;
                     }
                 }
             }
         }
     }
 }
Example #26
0
 /**
  * Print the grading page for a single user submission.
  *
  * @param moodleform $mform
  * @return string
  */
 protected function view_single_grade_page($mform)
 {
     global $DB, $CFG;
     $o = '';
     $instance = $this->get_instance();
     require_once $CFG->dirroot . '/mod/assign/gradeform.php';
     // Need submit permission to submit an assignment.
     require_capability('mod/assign:grade', $this->context);
     $header = new assign_header($instance, $this->get_context(), false, $this->get_course_module()->id, get_string('grading', 'assign'));
     $o .= $this->get_renderer()->render($header);
     // If userid is passed - we are only grading a single student.
     $rownum = required_param('rownum', PARAM_INT);
     $useridlistid = optional_param('useridlistid', time(), PARAM_INT);
     $userid = optional_param('userid', 0, PARAM_INT);
     $attemptnumber = optional_param('attemptnumber', -1, PARAM_INT);
     $cache = cache::make_from_params(cache_store::MODE_SESSION, 'mod_assign', 'useridlist');
     if (!$userid) {
         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 {
         $rownum = 0;
         $useridlist = array($userid);
     }
     if ($rownum < 0 || $rownum > count($useridlist)) {
         throw new coding_exception('Row is out of bounds for the current grading table: ' . $rownum);
     }
     $last = false;
     $userid = $useridlist[$rownum];
     if ($rownum == count($useridlist) - 1) {
         $last = true;
     }
     $user = $DB->get_record('user', array('id' => $userid));
     if ($user) {
         $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context());
         $usersummary = new assign_user_summary($user, $this->get_course()->id, $viewfullnames, $this->is_blind_marking(), $this->get_uniqueid_for_user($user->id), get_extra_user_fields($this->get_context()), !$this->is_active_user($userid));
         $o .= $this->get_renderer()->render($usersummary);
     }
     $submission = $this->get_user_submission($userid, false, $attemptnumber);
     $submissiongroup = null;
     $teamsubmission = null;
     $notsubmitted = array();
     if ($instance->teamsubmission) {
         $teamsubmission = $this->get_group_submission($userid, 0, false, $attemptnumber);
         $submissiongroup = $this->get_submission_group($userid);
         $groupid = 0;
         if ($submissiongroup) {
             $groupid = $submissiongroup->id;
         }
         $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
     }
     // Get the requested grade.
     $grade = $this->get_user_grade($userid, false, $attemptnumber);
     $flags = $this->get_user_flags($userid, false);
     if ($this->can_view_submission($userid)) {
         $gradelocked = $flags && $flags->locked || $this->grading_disabled($userid);
         $extensionduedate = null;
         if ($flags) {
             $extensionduedate = $flags->extensionduedate;
         }
         $showedit = $this->submissions_open($userid) && $this->is_any_submission_plugin_enabled();
         $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context());
         $submissionstatus = new assign_submission_status($instance->allowsubmissionsfromdate, $instance->alwaysshowdescription, $submission, $instance->teamsubmission, $teamsubmission, $submissiongroup, $notsubmitted, $this->is_any_submission_plugin_enabled(), $gradelocked, $this->is_graded($userid), $instance->duedate, $instance->cutoffdate, $this->get_submission_plugins(), $this->get_return_action(), $this->get_return_params(), $this->get_course_module()->id, $this->get_course()->id, assign_submission_status::GRADER_VIEW, $showedit, false, $viewfullnames, $extensionduedate, $this->get_context(), $this->is_blind_marking(), '', $instance->attemptreopenmethod, $instance->maxattempts);
         $o .= $this->get_renderer()->render($submissionstatus);
     }
     if ($grade) {
         $data = new stdClass();
         if ($grade->grade !== null && $grade->grade >= 0) {
             $data->grade = format_float($grade->grade, 2);
         }
         if (!empty($flags->workflowstate)) {
             $data->workflowstate = $flags->workflowstate;
         }
         if (!empty($flags->allocatedmarker)) {
             $data->allocatedmarker = $flags->allocatedmarker;
         }
     } else {
         $data = new stdClass();
         $data->grade = '';
     }
     // Warning if required.
     $allsubmissions = $this->get_all_submissions($userid);
     if ($attemptnumber != -1) {
         $params = array('attemptnumber' => $attemptnumber + 1, 'totalattempts' => count($allsubmissions));
         $message = get_string('editingpreviousfeedbackwarning', 'assign', $params);
         $o .= $this->get_renderer()->notification($message);
     }
     // Now show the grading form.
     if (!$mform) {
         $pagination = array('rownum' => $rownum, 'useridlistid' => $useridlistid, 'last' => $last, 'userid' => optional_param('userid', 0, PARAM_INT), 'attemptnumber' => $attemptnumber);
         $formparams = array($this, $data, $pagination);
         $mform = new mod_assign_grade_form(null, $formparams, 'post', '', array('class' => 'gradeform'));
     }
     $o .= $this->get_renderer()->heading(get_string('grade'), 3);
     $o .= $this->get_renderer()->render(new assign_form('gradingform', $mform));
     if (count($allsubmissions) > 1 && $attemptnumber == -1) {
         $allgrades = $this->get_all_grades($userid);
         $history = new assign_attempt_history($allsubmissions, $allgrades, $this->get_submission_plugins(), $this->get_feedback_plugins(), $this->get_course_module()->id, $this->get_return_action(), $this->get_return_params(), true);
         $o .= $this->get_renderer()->render($history);
     }
     $msg = get_string('viewgradingformforstudent', 'assign', array('id' => $user->id, 'fullname' => fullname($user)));
     $this->add_to_log('view grading form', $msg);
     $o .= $this->view_footer();
     return $o;
 }
Example #27
0
     die;
 }
 if (!($course = $DB->get_record('course', array('id' => $data->courseid)))) {
     // Check that course exists
     message_paypal_error_to_admin("Course {$data->courseid} doesn't exist", $data);
     die;
 }
 $coursecontext = context_course::instance($course->id, IGNORE_MISSING);
 // Check that amount paid is the correct amount
 if ((double) $plugin_instance->cost <= 0) {
     $cost = (double) $plugin->get_config('cost');
 } else {
     $cost = (double) $plugin_instance->cost;
 }
 if ($data->payment_gross < $cost) {
     $cost = format_float($cost, 2);
     message_paypal_error_to_admin("Amount paid is not enough ({$data->payment_gross} < {$cost}))", $data);
     die;
 }
 // ALL CLEAR !
 $DB->insert_record("enrol_paypal", $data);
 if ($plugin_instance->enrolperiod) {
     $timestart = time();
     $timeend = $timestart + $plugin_instance->enrolperiod;
 } else {
     $timestart = 0;
     $timeend = 0;
 }
 // Enrol user
 $plugin->enrol_user($plugin_instance, $user->id, $plugin_instance->roleid, $timestart, $timeend);
 // Pass $view=true to filter hidden caps if the user cannot see them
 /**
  * Format a column of data for display
  *
  * @param stdClass $row
  * @return string
  */
 public function col_grademax(stdClass $row)
 {
     return format_float($this->assignment->get_instance()->grade, 2);
 }
     die;
 }
 if (!($course = $DB->get_record('course', array('id' => $data->courseid)))) {
     // Check that course exists
     message_paypal_error_to_admin("Course {$data->courseid} doesn't exist", $data);
     die;
 }
 $coursecontext = context_course::instance($course->id, IGNORE_MISSING);
 // Check that amount paid is the correct amount
 if ((double) $plugin_instance->cost <= 0) {
     $cost = (double) $plugin->get_config('cost');
 } else {
     $cost = (double) $plugin_instance->cost;
 }
 // Use the same rounding of floats as on the enrol form.
 $cost = format_float($cost, 2, false);
 if ($data->payment_gross < $cost) {
     message_paypal_error_to_admin("Amount paid is not enough ({$data->payment_gross} < {$cost}))", $data);
     die;
 }
 // ALL CLEAR !
 $DB->insert_record("enrol_paypal", $data);
 if ($plugin_instance->enrolperiod) {
     $timestart = time();
     $timeend = $timestart + $plugin_instance->enrolperiod;
 } else {
     $timestart = 0;
     $timeend = 0;
 }
 // Enrol user
 $plugin->enrol_user($plugin_instance, $user->id, $plugin_instance->roleid, $timestart, $timeend);
 /**
  * Test localised float formatting.
  */
 public function test_format_float()
 {
     // Special case for null.
     $this->assertEquals('', format_float(null));
     // Default 1 decimal place.
     $this->assertEquals('5.4', format_float(5.43));
     $this->assertEquals('5.0', format_float(5.001));
     // Custom number of decimal places.
     $this->assertEquals('5.43000', format_float(5.43, 5));
     // Option to strip ending zeros after rounding.
     $this->assertEquals('5.43', format_float(5.43, 5, true, true));
     $this->assertEquals('5', format_float(5.0001, 3, true, true));
     // Tests with a localised decimal separator.
     $this->define_local_decimal_separator();
     // Localisation on (default).
     $this->assertEquals('5X43000', format_float(5.43, 5));
     $this->assertEquals('5X43', format_float(5.43, 5, true, true));
     // Localisation off.
     $this->assertEquals('5.43000', format_float(5.43, 5, false));
     $this->assertEquals('5.43', format_float(5.43, 5, false, true));
 }