Beispiel #1
0
/**
 * Print the details of a session
 *
 * @param object $session         Record from facetoface_sessions
 * @param boolean $showcapacity   Show the capacity (true) or only the seats available (false)
 * @param boolean $calendaroutput Whether the output should be formatted for a calendar event
 * @param boolean $return         Whether to return (true) the html or print it directly (true)
 * @param boolean $hidesignup     Hide any messages relating to signing up
 */
function facetoface_print_session($session, $showcapacity, $calendaroutput = false, $return = false, $hidesignup = false)
{
    global $CFG, $DB;
    $table = new html_table();
    $table->summary = get_string('sessionsdetailstablesummary', 'facetoface');
    $table->attributes['class'] = 'generaltable f2fsession';
    $table->align = array('right', 'left');
    if ($calendaroutput) {
        $table->tablealign = 'left';
    }
    $customfields = facetoface_get_session_customfields();
    $customdata = $DB->get_records('facetoface_session_data', array('sessionid' => $session->id), '', 'fieldid, data');
    foreach ($customfields as $field) {
        $data = '';
        if (!empty($customdata[$field->id])) {
            if (CUSTOMFIELD_TYPE_MULTISELECT == $field->type) {
                $values = explode(CUSTOMFIELD_DELIMITER, format_string($customdata[$field->id]->data));
                $data = implode(html_writer::empty_tag('br'), $values);
            } else {
                $data = format_string($customdata[$field->id]->data);
            }
        }
        $table->data[] = array(str_replace(' ', ' ', format_string($field->name)), $data);
    }
    $strdatetime = str_replace(' ', ' ', get_string('sessiondatetime', 'facetoface'));
    if ($session->datetimeknown) {
        $html = '';
        foreach ($session->sessiondates as $date) {
            if (!empty($html)) {
                $html .= html_writer::empty_tag('br');
            }
            $timestart = userdate($date->timestart, get_string('strftimedatetime'));
            $timefinish = userdate($date->timefinish, get_string('strftimedatetime'));
            $html .= "{$timestart} – {$timefinish}";
        }
        $table->data[] = array($strdatetime, $html);
    } else {
        $table->data[] = array($strdatetime, html_writer::tag('i', get_string('wait-listed', 'facetoface')));
    }
    $signupcount = facetoface_get_num_attendees($session->id);
    $placesleft = $session->capacity - $signupcount;
    if ($showcapacity) {
        if ($session->allowoverbook) {
            $table->data[] = array(get_string('capacity', 'facetoface'), $session->capacity . ' (' . strtolower(get_string('allowoverbook', 'facetoface')) . ')');
        } else {
            $table->data[] = array(get_string('capacity', 'facetoface'), $session->capacity);
        }
    } else {
        if (!$calendaroutput) {
            $table->data[] = array(get_string('seatsavailable', 'facetoface'), max(0, $placesleft));
        }
    }
    // Display requires approval notification.
    $facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface));
    if ($facetoface->approvalreqd) {
        $table->data[] = array('', get_string('sessionrequiresmanagerapproval', 'facetoface'));
    }
    // Display waitlist notification.
    if (!$hidesignup && $session->allowoverbook && $placesleft < 1) {
        $table->data[] = array('', get_string('userwillbewaitlisted', 'facetoface'));
    }
    if (!empty($session->duration)) {
        $table->data[] = array(get_string('duration', 'facetoface'), format_duration($session->duration));
    }
    if (!empty($session->normalcost)) {
        $table->data[] = array(get_string('normalcost', 'facetoface'), format_cost($session->normalcost));
    }
    if (!empty($session->discountcost)) {
        $table->data[] = array(get_string('discountcost', 'facetoface'), format_cost($session->discountcost));
    }
    if (!empty($session->details)) {
        $details = clean_text($session->details, FORMAT_HTML);
        $table->data[] = array(get_string('details', 'facetoface'), $details);
    }
    // Display trainers.
    $trainerroles = facetoface_get_trainer_roles();
    if ($trainerroles) {
        // Get trainers.
        $trainers = facetoface_get_trainers($session->id);
        foreach ($trainerroles as $role => $rolename) {
            $rolename = $rolename->name;
            if (empty($trainers[$role])) {
                continue;
            }
            $trainernames = array();
            foreach ($trainers[$role] as $trainer) {
                $trainerurl = new moodle_url('/user/view.php', array('id' => $trainer->id));
                $trainernames[] = html_writer::link($trainerurl, fullname($trainer));
            }
            $table->data[] = array($rolename, implode(', ', $trainernames));
        }
    }
    return html_writer::table($table, $return);
}
 public function test_format_cost()
 {
     // Test each method with the html parameter as true/ false /null.
     // Test for a valid value.
     $this->assertEqual(format_cost(1000, true), '$1000');
     $this->assertEqual(format_cost(1000, false), '$1000');
     $this->assertEqual(format_cost(1000), '$1000');
     // Test for a large negative value, html true/ false/ null.
     $this->assertEqual(format_cost(-34000, true), '$-34000');
     $this->assertEqual(format_cost(-34000, false), '$-34000');
     $this->assertEqual(format_cost(-34000), '$-34000');
     // Test for a large positive value.
     $this->assertEqual(format_cost(100000000000, true), '$100000000000');
     $this->assertEqual(format_cost(100000000000, false), '$100000000000');
     $this->assertEqual(format_cost(100000000000), '$100000000000');
     // Test for a decimal value.
     $this->assertEqual(format_cost(32768.9045, true), '$32768.9045');
     $this->assertEqual(format_cost(32768.9045, false), '$32768.9045');
     $this->assertEqual(format_cost(32768.9045), '$32768.9045');
     // Test for a null value.
     $this->assertEqual(format_cost(null, true), '$');
     $this->assertEqual(format_cost(null, false), '$');
     $this->assertEqual(format_cost(null), '$');
     // Test for a text string value.
     $this->assertEqual(format_cost('string', true), '$string');
     $this->assertEqual(format_cost('string', false), '$string');
     $this->assertEqual(format_cost('string'), '$string');
 }