Example #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');
            }
            $sessionobj = facetoface_format_session_times($date->timestart, $date->timefinish, $date->sessiontimezone);
            if ($sessionobj->startdate == $sessionobj->enddate) {
                $html .= $sessionobj->startdate . ', ';
            } else {
                $html .= $sessionobj->startdate . ' - ' . $sessionobj->enddate . ', ';
            }
            $html .= $sessionobj->starttime . ' - ' . $sessionobj->endtime . ' ' . $sessionobj->timezone;
        }
        $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'), get_string('capacityallowoverbook', 'facetoface', $session->capacity));
        } else {
            $table->data[] = array(get_string('capacity', 'facetoface'), $session->capacity);
        }
    }
    elseif (!$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));
    }

    // Display room information
    $session->room = $DB->get_record('facetoface_room', array('id' => $session->roomid));
    if (!empty($session->room)) {
        $roomstring = '';
        $roomstring = isset($session->room->name) ? format_string($session->room->name) . ', '. html_writer::empty_tag('br') : '';
        $roomstring .= isset($session->room->building) ? format_string($session->room->building) . ', ' . html_writer::empty_tag('br') : '';
        $roomstring .= isset($session->room->address) ? format_string($session->room->address) . html_writer::empty_tag('br') : '';

        $systemcontext = context_system::instance();
        $editoroptions = array(
            'noclean'  => false,
            'maxfiles' => EDITOR_UNLIMITED_FILES,
            'context'  => $systemcontext,
        );

        $session->room->descriptionformat = FORMAT_HTML;
        $session->room = file_prepare_standard_editor($session->room, 'description', $editoroptions, $systemcontext, 'facetoface', 'room', $session->room->id);

        $roomstring .= $session->room->description_editor['text'];

        $table->data[] = array(get_string('room', 'facetoface'), $roomstring);
    }

    if (!empty($session->normalcost)) {
        $table->data[] = array(get_string('normalcost', 'facetoface'), format_string($session->normalcost));
    }
    if (!empty($session->discountcost)) {
        $table->data[] = array(get_string('discountcost', 'facetoface'), format_string($session->discountcost));
    }

    // Display trainers.
    $courseid = $DB->get_field('facetoface', 'course', array('id' => $session->facetoface));
    $coursecontext = context_course::instance($courseid);

    if (!empty($session->details)) {
        if ($cm = get_coursemodule_from_instance('facetoface', $facetoface->id, $courseid)) {
            $context = context_module::instance($cm->id);
            $session->details = file_rewrite_pluginfile_urls($session->details, 'pluginfile.php', $context->id, 'mod_facetoface', 'session', $session->id);
        }
        $details = format_text($session->details, FORMAT_HTML);
        $table->data[] = array(get_string('details', 'facetoface'), $details);
    }

    $trainerroles = facetoface_get_trainer_roles($coursecontext);

    if ($trainerroles) {
        // Get trainers.
        $trainers = facetoface_get_trainers($session->id);

        foreach ($trainerroles as $role => $rolename) {
            $rolename = $rolename->localname;

            if (empty($trainers[$role])) {
                continue;
            }

            $trainer_names = array();
            foreach ($trainers[$role] as $trainer) {
                $trainer_url = new moodle_url('/user/view.php', array('id' => $trainer->id));
                $trainer_names[] = html_writer::link($trainer_url, fullname($trainer));
            }

            $table->data[] = array($rolename, implode(', ', $trainer_names));
        }
    }

    return html_writer::table($table, $return);
}
Example #2
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(' ', '&nbsp;', format_string($field->name)), $data);
    }
    $strdatetime = str_replace(' ', '&nbsp;', 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} &ndash; {$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);
}
Example #3
0
 public function definition()
 {
     global $CFG, $DB;
     $mform =& $this->_form;
     // Course Module ID.
     $mform->addElement('hidden', 'id', $this->_customdata['id']);
     $mform->setType('id', PARAM_INT);
     // Facetoface Instance ID.
     $mform->addElement('hidden', 'f', $this->_customdata['f']);
     $mform->setType('f', PARAM_INT);
     // Facetoface Session ID.
     $mform->addElement('hidden', 's', $this->_customdata['s']);
     $mform->setType('s', PARAM_INT);
     // Copy Session Flag.
     $mform->addElement('hidden', 'c', $this->_customdata['c']);
     $mform->setType('c', PARAM_INT);
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $editoroptions = $this->_customdata['editoroptions'];
     // Show all custom fields.
     $customfields = $this->_customdata['customfields'];
     facetoface_add_customfields_to_form($mform, $customfields);
     // Hack to put help files on these custom fields.
     // TODO: add to the admin page a feature to put help text on custom fields.
     if ($mform->elementExists('custom_location')) {
         $mform->addHelpButton('custom_location', 'location', 'facetoface');
     }
     if ($mform->elementExists('custom_venue')) {
         $mform->addHelpButton('custom_venue', 'venue', 'facetoface');
     }
     if ($mform->elementExists('custom_room')) {
         $mform->addHelpButton('custom_room', 'room', 'facetoface');
     }
     $formarray = array();
     $formarray[] = $mform->createElement('selectyesno', 'datetimeknown', get_string('sessiondatetimeknown', 'facetoface'));
     $formarray[] = $mform->createElement('static', 'datetimeknownhint', '', html_writer::tag('span', get_string('datetimeknownhinttext', 'facetoface'), array('class' => 'hint-text')));
     $mform->addGroup($formarray, 'datetimeknown_group', get_string('sessiondatetimeknown', 'facetoface'), array(' '), false);
     $mform->addGroupRule('datetimeknown_group', null, 'required', null, 'client');
     $mform->setDefault('datetimeknown', false);
     $mform->addHelpButton('datetimeknown_group', 'sessiondatetimeknown', 'facetoface');
     $repeatarray = array();
     $repeatarray[] =& $mform->createElement('hidden', 'sessiondateid', 0);
     $mform->setType('sessiondateid', PARAM_INT);
     $repeatarray[] =& $mform->createElement('date_time_selector', 'timestart', get_string('timestart', 'facetoface'));
     $repeatarray[] =& $mform->createElement('date_time_selector', 'timefinish', get_string('timefinish', 'facetoface'));
     $checkboxelement =& $mform->createElement('checkbox', 'datedelete', '', get_string('dateremove', 'facetoface'));
     unset($checkboxelement->_attributes['id']);
     // Necessary until MDL-20441 is fixed.
     $repeatarray[] = $checkboxelement;
     $repeatarray[] =& $mform->createElement('html', html_writer::empty_tag('br'));
     // Spacer.
     $repeatcount = $this->_customdata['nbdays'];
     $repeatoptions = array();
     $repeatoptions['timestart']['disabledif'] = array('datetimeknown', 'eq', 0);
     $repeatoptions['timefinish']['disabledif'] = array('datetimeknown', 'eq', 0);
     $mform->setType('timestart', PARAM_INT);
     $mform->setType('timefinish', PARAM_INT);
     $this->repeat_elements($repeatarray, $repeatcount, $repeatoptions, 'date_repeats', 'date_add_fields', 1, get_string('dateadd', 'facetoface'), true);
     $mform->addElement('text', 'capacity', get_string('capacity', 'facetoface'), 'size="5"');
     $mform->addRule('capacity', null, 'required', null, 'client');
     $mform->setType('capacity', PARAM_INT);
     $mform->setDefault('capacity', 10);
     $mform->addHelpButton('capacity', 'capacity', 'facetoface');
     $mform->addElement('checkbox', 'allowoverbook', get_string('allowoverbook', 'facetoface'));
     $mform->addHelpButton('allowoverbook', 'allowoverbook', 'facetoface');
     $mform->addElement('text', 'duration', get_string('duration', 'facetoface'), 'size="5"');
     $mform->setType('duration', PARAM_TEXT);
     $mform->addHelpButton('duration', 'duration', 'facetoface');
     if (!get_config(null, 'facetoface_hidecost')) {
         $formarray = array();
         $formarray[] = $mform->createElement('text', 'normalcost', get_string('normalcost', 'facetoface'), 'size="5"');
         $formarray[] = $mform->createElement('static', 'normalcosthint', '', html_writer::tag('span', get_string('normalcosthinttext', 'facetoface'), array('class' => 'hint-text')));
         $mform->addGroup($formarray, 'normalcost_group', get_string('normalcost', 'facetoface'), array(' '), false);
         $mform->setType('normalcost', PARAM_TEXT);
         $mform->addHelpButton('normalcost_group', 'normalcost', 'facetoface');
         if (!get_config(null, 'facetoface_hidediscount')) {
             $formarray = array();
             $formarray[] = $mform->createElement('text', 'discountcost', get_string('discountcost', 'facetoface'), 'size="5"');
             $formarray[] = $mform->createElement('static', 'discountcosthint', '', html_writer::tag('span', get_string('discountcosthinttext', 'facetoface'), array('class' => 'hint-text')));
             $mform->addGroup($formarray, 'discountcost_group', get_string('discountcost', 'facetoface'), array(' '), false);
             $mform->setType('discountcost', PARAM_TEXT);
             $mform->addHelpButton('discountcost_group', 'discountcost', 'facetoface');
         }
     }
     $mform->addElement('editor', 'details_editor', get_string('details', 'facetoface'), null, $editoroptions);
     $mform->setType('details_editor', PARAM_RAW);
     $mform->addHelpButton('details_editor', 'details', 'facetoface');
     // Choose users for trainer roles.
     $rolenames = facetoface_get_trainer_roles();
     if ($rolenames) {
         // Get current trainers.
         $currenttrainers = facetoface_get_trainers($this->_customdata['s']);
         // Loop through all selected roles.
         $headershown = false;
         foreach ($rolenames as $role => $rolename) {
             $rolename = $rolename->name;
             // Get course context.
             $context = context_course::instance($this->_customdata['course']->id);
             // Attempt to load users with this role in this course.
             $usernamefields = get_all_user_name_fields(true);
             $rs = $DB->get_recordset_sql("\n                    SELECT\n                        u.id,\n                        {$usernamefields}\n                    FROM\n                        {role_assignments} ra\n                    LEFT JOIN\n                        {user} u\n                      ON ra.userid = u.id\n                    WHERE\n                        contextid = {$context->id}\n                    AND roleid = {$role}\n                ");
             if (!$rs) {
                 continue;
             }
             $choices = array();
             foreach ($rs as $roleuser) {
                 $choices[$roleuser->id] = fullname($roleuser);
             }
             $rs->close();
             // Show header (if haven't already).
             if ($choices && !$headershown) {
                 $mform->addElement('header', 'trainerroles', get_string('sessionroles', 'facetoface'));
                 $headershown = true;
             }
             // If only a few, use checkboxes.
             if (count($choices) < 4) {
                 $roleshown = false;
                 foreach ($choices as $cid => $choice) {
                     // Only display the role title for the first checkbox for each role.
                     if (!$roleshown) {
                         $roledisplay = $rolename;
                         $roleshown = true;
                     } else {
                         $roledisplay = '';
                     }
                     $mform->addElement('advcheckbox', 'trainerrole[' . $role . '][' . $cid . ']', $roledisplay, $choice, null, array('', $cid));
                     $mform->setType('trainerrole[' . $role . '][' . $cid . ']', PARAM_INT);
                 }
             } else {
                 $mform->addElement('select', 'trainerrole[' . $role . ']', $rolename, $choices, array('multiple' => 'multiple'));
                 $mform->setType('trainerrole[' . $role . ']', PARAM_SEQUENCE);
             }
             // Select current trainers.
             if ($currenttrainers) {
                 foreach ($currenttrainers as $role => $trainers) {
                     $t = array();
                     foreach ($trainers as $trainer) {
                         $t[] = $trainer->id;
                         $mform->setDefault('trainerrole[' . $role . '][' . $trainer->id . ']', $trainer->id);
                     }
                     $mform->setDefault('trainerrole[' . $role . ']', implode(',', $t));
                 }
             }
         }
     }
     $this->add_action_buttons();
 }
    function definition() {
        global $CFG, $DB;

        $mform =& $this->_form;

        $mform->addElement('hidden', 'id', $this->_customdata['id']);
        $mform->addElement('hidden', 'f', $this->_customdata['f']);
        $mform->addElement('hidden', 's', $this->_customdata['s']);
        $mform->addElement('hidden', 'c', $this->_customdata['c']);
        $mform->setType('id', PARAM_INT);
        $mform->setType('f', PARAM_INT);
        $mform->setType('s', PARAM_INT);
        $mform->setType('c', PARAM_INT);

        $mform->addElement('header', 'general', get_string('general', 'form'));

        $editoroptions = $this->_customdata['editoroptions'];

        // Show all custom fields
        $customfields = $this->_customdata['customfields'];
        facetoface_add_customfields_to_form($mform, $customfields);

        $formarray  = array();
        $formarray[] = $mform->createElement('selectyesno', 'datetimeknown', get_string('sessiondatetimeknown', 'facetoface'));
        $formarray[] = $mform->createElement('static', 'datetimeknownhint', '', html_writer::tag('span', get_string('datetimeknownhinttext','facetoface'), array('class' => 'hint-text')));
        $mform->addGroup($formarray,'datetimeknown_group', get_string('sessiondatetimeknown','facetoface'), array(' '),false);
        $mform->addGroupRule('datetimeknown_group', null, 'required', null, 'client');
        $mform->setDefault('datetimeknown', false);
        $mform->addHelpButton('datetimeknown_group', 'sessiondatetimeknown', 'facetoface');

        $repeatarray = array();
        $timezones = get_clean_timezone_list(true);
        $timezones[get_string('sessiontimezoneunknown', 'facetoface')] = get_string('sessiontimezoneunknown', 'facetoface');
        $repeatarray[] = &$mform->createElement('hidden', 'sessiondateid', 0);
        $repeatarray[] = $mform->createElement('select', 'sessiontimezone', get_string('sessiontimezone', 'facetoface'), $timezones);
        $repeatarray[] = &$mform->createElement('date_time_selector', 'timestart', get_string('timestart', 'facetoface'));
        $repeatarray[] = &$mform->createElement('date_time_selector', 'timefinish', get_string('timefinish', 'facetoface'));
        $checkboxelement = &$mform->createElement('checkbox', 'datedelete', '', get_string('dateremove', 'facetoface'));
        unset($checkboxelement->_attributes['id']); // necessary until MDL-20441 is fixed
        $repeatarray[] = $checkboxelement;
        $repeatarray[] = &$mform->createElement('html', html_writer::empty_tag('br')); // spacer

        $repeatcount = $this->_customdata['nbdays'];

        $repeatoptions = array();
        $repeatoptions['timestart']['disabledif'] = array('datetimeknown', 'eq', 0);
        $repeatoptions['timefinish']['disabledif'] = array('datetimeknown', 'eq', 0);
        $repeatoptions['sessiontimezone']['disabledif'] = array('datetimeknown', 'eq', 0);
        $repeatoptions['sessiontimezone']['default'] = $this->_customdata['defaulttimezone'];
        $mform->setType('timestart', PARAM_INT);
        $mform->setType('timefinish', PARAM_INT);
        $mform->setType('sessiontimezone', PARAM_TEXT);
        $mform->setType('sessiondateid', PARAM_INT);
        $this->repeat_elements($repeatarray, $repeatcount, $repeatoptions, 'date_repeats', 'date_add_fields',
                               1, get_string('dateadd', 'facetoface'), true);

        // Rooms form
        $pdroom = '';
        $roomnote = '';
        if (!empty($this->_customdata['s'])) {
            $sql = "SELECT r.*
                FROM {facetoface_sessions} s
                INNER JOIN {facetoface_room} r ON s.roomid = r.id
                WHERE s.id = ? AND r.custom = 0";
            $params = array($this->_customdata['s']);
            if ($room = $DB->get_record_sql($sql, $params)) {
                $pdroom = $room->name.', '.$room->building.', '.$room->address.', '.$room->description." (".get_string('capacity', 'facetoface').": ".$room->capacity.")";
                $pdroom = format_string($pdroom);
                if ($room->type == 'external') {
                    $roomnote = '<br><em>'.get_string('roommustbebookedtoexternalcalendar', 'facetoface').'</em>';
                }
            }
        }
        $mform->addElement('static', 'predefinedroom', get_string('room', 'facetoface'),
            '<span id="pdroom">'.$pdroom.'</span><span id="roomnote">'.$roomnote.'</span>');
        $mform->addElement('static', 'addpdroom', '', '<input type="button" value="'.get_string('choosepredefinedroom', 'facetoface').'" name="show-addpdroom-dialog" id="show-addpdroom-dialog" />');
        $mform->addElement('hidden', 'pdroomid', 0);
        $mform->setType('pdroomid', PARAM_INT);
        $mform->addElement('hidden', 'pdroomcapacity', 0);
        $mform->setType('pdroomcapacity', PARAM_INT);

        $mform->addElement('checkbox', 'customroom', '', get_string('otherroom', 'facetoface'));
        $mform->setType('customroom', PARAM_INT);
        $mform->disabledIf('customroom', 'datetimeknown', 'eq', 0);

        $mform->addElement('html', '<div class="fitem"><div class="fitemtitle"></div><table><tr><td>');
        $mform->addElement('static', '', '', get_string('roomname', 'facetoface'));
        $mform->addElement('html', '</td><td>');
        $mform->addElement('static', '', '', get_string('building', 'facetoface'));
        $mform->addElement('html', '</td><td>');
        $mform->addElement('static', '', '', get_string('address', 'facetoface'));
        $mform->addElement('html', '</td><td>');
        $mform->addElement('static', '', '', get_string('capacity', 'facetoface'));
        $mform->addElement('html', '</td></tr><td>');
        $mform->addElement('text', 'croomname', array(), array('class' => 'cellwidth', 'maxlength' => '90'));
        $mform->setType('croomname', PARAM_TEXT);
        $mform->disabledIf('croomname', 'customroom', 'notchecked');
        $mform->addElement('html', '</td><td>');
        $mform->addElement('text', 'croombuilding', array(), array('class' => 'cellwidth', 'maxlength' => '90'));
        $mform->setType('croombuilding', PARAM_TEXT);
        $mform->disabledIf('croombuilding', 'customroom', 'notchecked');
        $mform->addElement('html', '</td><td>');
        $mform->addElement('text', 'croomaddress', array(), array('class' => 'cellwidth', 'maxlength' => '230'));
        $mform->setType('croomaddress', PARAM_TEXT);
        $mform->disabledIf('croomaddress', 'customroom', 'notchecked');
        $mform->addElement('html', '</td><td>');
        $mform->addElement('text', 'croomcapacity', array(), array('class' => 'cellwidth', 'maxlength' => '10'));
        $mform->disabledIf('croomcapacity', 'customroom', 'notchecked');
        $mform->setType('croomcapacity', PARAM_INT);
        $mform->addElement('html', '</td><tr></table></div>');

        $mform->addElement('text', 'capacity', get_string('capacity', 'facetoface'), 'size="5"');
        $mform->addRule('capacity', null, 'required', null, 'client');
        $mform->setType('capacity', PARAM_INT);
        $mform->setDefault('capacity', 10);
        $mform->addRule('capacity', null, 'numeric', null, 'client');
        $mform->addHelpButton('capacity', 'capacity', 'facetoface');

        $mform->addElement('checkbox', 'allowoverbook', get_string('allowoverbook', 'facetoface'));
        $mform->addHelpButton('allowoverbook', 'allowoverbook', 'facetoface');

        $mform->addElement('text', 'duration', get_string('duration', 'facetoface'), 'size="5"');
        $mform->setType('duration', PARAM_TEXT);
        $mform->addHelpButton('duration', 'duration', 'facetoface');

        if (!get_config(NULL, 'facetoface_hidecost')) {
            $formarray  = array();
            $formarray[] = $mform->createElement('text', 'normalcost', get_string('normalcost', 'facetoface'), 'size="5"');
            $formarray[] = $mform->createElement('static', 'normalcosthint', '', html_writer::tag('span', get_string('normalcosthinttext','facetoface'), array('class' => 'hint-text')));
            $mform->addGroup($formarray,'normalcost_group', get_string('normalcost','facetoface'), array(' '),false);
            $mform->setType('normalcost', PARAM_TEXT);
            $mform->addHelpButton('normalcost_group', 'normalcost', 'facetoface');

            if (!get_config(NULL, 'facetoface_hidediscount')) {
                $formarray  = array();
                $formarray[] = $mform->createElement('text', 'discountcost', get_string('discountcost', 'facetoface'), 'size="5"');
                $formarray[] = $mform->createElement('static', 'discountcosthint', '', html_writer::tag('span', get_string('discountcosthinttext','facetoface'), array('class' => 'hint-text')));
                $mform->addGroup($formarray,'discountcost_group', get_string('discountcost','facetoface'), array(' '),false);
                $mform->setType('discountcost', PARAM_TEXT);
                $mform->addHelpButton('discountcost_group', 'discountcost', 'facetoface');
            }
        }

        $mform->addElement('editor', 'details_editor', get_string('details', 'facetoface'), null, $editoroptions);
        $mform->setType('details_editor', PARAM_RAW);
        $mform->addHelpButton('details_editor', 'details', 'facetoface');

        // Choose users for trainer roles
        $context = context_course::instance($this->_customdata['course']->id);
        $roles = facetoface_get_trainer_roles($context);

        if ($roles) {
            // Get current trainers
            $current_trainers = facetoface_get_trainers($this->_customdata['s']);
            // Get course context and roles
            $rolenames = role_get_names($context);
            // Loop through all selected roles
            $header_shown = false;
            foreach ($roles as $role) {
                $rolename = format_string($rolenames[$role->id]->localname);

                // Attempt to load users with this role in this context.
                $rs = get_role_users($role->id, $context, true, 'u.id, u.firstname, u.lastname', 'u.id ASC');

                if (!$rs) {
                    continue;
                }

                $choices = array();
                foreach ($rs as $roleuser) {
                    $choices[$roleuser->id] = fullname($roleuser);
                }

                // Show header (if haven't already)
                if ($choices && !$header_shown) {
                    $mform->addElement('header', 'trainerroles', get_string('sessionroles', 'facetoface'));
                    $header_shown = true;
                }

                // If only a few, use checkboxes
                if (count($choices) < 4) {
                    $role_shown = false;
                    foreach ($choices as $cid => $choice) {
                        // Only display the role title for the first checkbox for each role
                        if (!$role_shown) {
                            $roledisplay = $rolename;
                            $role_shown = true;
                        } else {
                            $roledisplay = '';
                        }

                        $mform->addElement('advcheckbox', 'trainerrole['.$role->id.']['.$cid.']', $roledisplay, $choice, null, array('', $cid));
                        $mform->setType('trainerrole['.$role->id.']['.$cid.']', PARAM_INT);
                    }
                } else {
                    $mform->addElement('select', 'trainerrole['.$role->id.']', $rolename, $choices, array('multiple' => 'multiple'));
                    $mform->setType('trainerrole['.$role->id.']', PARAM_SEQUENCE);
                }

                // Select current trainers
                if ($current_trainers) {
                    foreach ($current_trainers as $roleid => $trainers) {
                        $t = array();
                        foreach ($trainers as $trainer) {
                            $t[] = $trainer->id;
                            $mform->setDefault('trainerrole['.$roleid.']['.$trainer->id.']', $trainer->id);
                        }

                        $mform->setDefault('trainerrole['.$roleid.']', implode(',', $t));
                    }
                }
            }
        }

        // If conflicts are disabled
        if (!empty($CFG->facetoface_allowschedulingconflicts)) {
            $mform->addElement('selectyesno', 'allowconflicts', get_string('allowschedulingconflicts', 'facetoface'));
            $mform->setDefault('allowconflicts', 0); // defaults to 'no'
            $mform->addHelpButton('allowconflicts', 'allowschedulingconflicts', 'facetoface');
            $mform->setType('allowconflicts', PARAM_BOOL);
        }

        $this->add_action_buttons();
    }
Example #5
0
    function test_facetoface_get_trainer_roles() {
        global $CFG;
        // Test method - returns array.

        $context = context_course::instance(4);

        // No session roles.
        $this->assertFalse((bool)facetoface_get_trainer_roles($context), $this->msgfalse);

        // Add some roles.
        set_config('facetoface_session_roles', "4");

        $result = facetoface_get_trainer_roles($context);
        $this->assertEquals($result[4]->localname, 'Trainer');

        $this->resetAfterTest(true);
    }