Ejemplo n.º 1
0
/**
 * Prints form items with the names $day, $month and $year
 *
 * @param int $filtername - the name of the filter to set up i.e coursename, courseid, location, trainer
 * @param int $currentvalue
 * @param boolean $return
 */
function print_facetoface_filters($startdate, $enddate, $currentcoursename, $currentcourseid, $currentlocation, $currenttrainer) {
    global $CFG, $DB, $USER;

    $coursenames = array();
    $sessions = array();
    $locations = array();
    $courseids = array();
    $trainers = array();



    if (is_siteadmin()) {
        $coscentercondition = "";
    } else {
        // to get costcenter info  of the logged in user
        if (isset($USER->id)) {
            $training_managercostcenterinfo = $DB->get_record('local_costcenter_permissions', array('userid' => $USER->id));
            if (isset($training_managercostcenterinfo->costcenterid)) {
                $costcenterid = $training_managercostcenterinfo->costcenterid;
            } else {
                $userinfo = $DB->get_record('local_userdata', array('userid' => $USER->id));
                $costcenterid = $userinfo->costcenterid;
            }
            $coscentercondition = " AND c.costcenter=$costcenterid ";
        }
    }


    $results = $DB->get_records_sql("SELECT s.id AS sessionid, c.id as courseid, c.idnumber, c.fullname,
                                       f.id AS facetofaceid
                                    FROM {course} c
                                    JOIN {facetoface} f ON f.course = c.id
                                    JOIN {facetoface_sessions} s ON f.id = s.facetoface
                                    WHERE c.visible = 1 $coscentercondition
                                    GROUP BY c.id, c.idnumber, c.fullname, s.id, f.id
                                    ORDER BY c.fullname ASC");

    add_location_info($results);

    if (!empty($results)) {
        foreach ($results as $result) {
            // create unique list of coursenames
            if (!array_key_exists($result->fullname, $coursenames)) {
                $coursenames[$result->fullname] = $result->fullname;
            }

            // created unique list of locations
            if (isset($result->location)) {
                if (!array_key_exists($result->location, $locations)) {
                    $locations[$result->location] = $result->location;
                }
            }

            // create unique list of courseids
            if (!array_key_exists($result->idnumber, $courseids) and $result->idnumber) {
                $courseids[$result->idnumber] = $result->idnumber;
            }

            // create unique list of trainers
            // check if $trainers hasn't already been populated by the cached list
            if (empty($trainers)) {
                if (isset($result->trainers)) {
                    foreach ($result->trainers as $trainer) {
                        if (!array_key_exists($trainer, $trainers)) {
                            $trainers[$trainer] = $trainer;
                        }
                    }
                }
            }
        }
    }

    // Build or print result
    $table = new html_table();
    $table->tablealign = 'left';
    $table->data[] = array(html_writer::tag('label', get_string('daterange', 'block_facetoface'), array('for' => 'menustartdate')),
        html_writer::select_time('days', 'startday', $startdate) .
        html_writer::select_time('months', 'startmonth', $startdate) .
        html_writer::select_time('years', 'startyear', $startdate) . ' ' . strtolower(get_string('to')) . ' ' .
        html_writer::select_time('days', 'endday', $enddate) .
        html_writer::select_time('months', 'endmonth', $enddate) .
        html_writer::select_time('years', 'endyear', $enddate));
    $table->data[] = array(html_writer::tag('label', get_string('coursefullname', 'block_facetoface') . ':', array('for' => 'menucoursename')),
        html_writer::select($coursenames, 'coursename', $currentcoursename, array('' => get_string('all'))));
    if ($locations) {
        $table->data[] = array(html_writer::tag('label', get_string('location', 'facetoface') . ':', array('for' => 'menulocation')),
            html_writer::select($locations, 'location', $currentlocation, array('' => get_string('all'))));
    }
    echo html_writer::table($table);
}
Ejemplo n.º 2
0
                                 LEFT JOIN {facetoface_signups_status} ss
                                        ON ss.signupid = su.id AND ss.superceded = 0
                                     WHERE ss.statuscode >= ?
                                  GROUP BY sessionid) su ON su.sessionid = d.sessionid
                              JOIN {course} c ON f.course = c.id

                              JOIN {course_modules} cm ON cm.course = f.course
                                   AND cm.instance = f.id
                              JOIN {modules} m ON m.id = cm.module

                             WHERE d.timestart >= ? AND d.timefinish <= ?
                                   AND m.name = 'facetoface'
                                $coursenamesql
                                $courseidsql", array_merge(array(MDL_F2F_STATUS_BOOKED, $startdate, $enddate), $coursenameparam, $courseidparam));

$show_location = add_location_info($records);

// Only keep the sessions for which this user can see attendees
$dates = array();
if ($records) {
    $capability = 'mod/facetoface:viewattendees';

    // Check the system context first
    $contextsystem = context_system::instance();
    if (has_capability($capability, $contextsystem)) {

        // check if the location or trainer filters need to be used
        if ($location or $trainer) {
            foreach ($records as $record) {

                if ($record->location === $location) {
Ejemplo n.º 3
0
    $users = get_users_search($search);
} else {
    // Get all Face-to-face signups from the DB
    $signups = $DB->get_records_sql("SELECT d.id, c.id as courseid, c.fullname AS coursename, f.name,
                                       f.id as facetofaceid, s.id as sessionid, s.datetimeknown,
                                       d.timestart, d.timefinish, d.sessiontimezone, su.userid, ss.statuscode as status
                                  FROM {facetoface_sessions_dates} d
                                  JOIN {facetoface_sessions} s ON s.id = d.sessionid
                                  JOIN {facetoface} f ON f.id = s.facetoface
                                  JOIN {facetoface_signups} su ON su.sessionid = s.id
                                  JOIN {facetoface_signups_status} ss ON su.id = ss.signupid AND ss.superceded = 0
                                  JOIN {course} c ON f.course = c.id
                                 WHERE d.timestart >= ? AND d.timefinish <= ? AND
                                       su.userid = ?", array($startdate, $enddate, $user->id));

    $show_location = add_location_info($signups);
}

// format the session and dates to only show one booking where they span multiple dates
// i.e. multiple days startdate = firstday, finishdate = last day
$groupeddates = array();
if ($signups and count($signups > 0)) {
    $groupeddates = group_session_dates($signups);
}

// out of the results separate out the future sessions
$futuresessions = future_session_dates($groupeddates);
$nbfuture = 0;
if ($futuresessions and count($futuresessions) > 0) {
    $nbfuture = count($futuresessions);
}