Exemple #1
0
function calendar_top_controls($type, $data)
{
    global $CFG, $CALENDARDAYS, $THEME;
    $content = '';
    if (!isset($data['d'])) {
        $data['d'] = 1;
    }
    // Ensure course id passed if relevant
    // Required due to changes in view/lib.php mainly (calendar_session_vars())
    $courseid = '';
    if (!empty($data['id'])) {
        $courseid = '&course=' . $data['id'];
    }
    if (!checkdate($data['m'], $data['d'], $data['y'])) {
        $time = time();
    } else {
        $time = make_timestamp($data['y'], $data['m'], $data['d']);
    }
    $date = usergetdate($time);
    $data['m'] = $date['mon'];
    $data['y'] = $date['year'];
    //Accessibility: calendar block controls, replaced <table> with <div>.
    //$nexttext = link_arrow_right(get_string('monthnext', 'access'), $url='', $accesshide=true);
    //$prevtext = link_arrow_left(get_string('monthprev', 'access'), $url='', $accesshide=true);
    switch ($type) {
        case 'frontpage':
            list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
            list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
            $nextlink = calendar_get_link_next(get_string('monthnext', 'access'), 'index.php?', 0, $nextmonth, $nextyear, $accesshide = true);
            $prevlink = calendar_get_link_previous(get_string('monthprev', 'access'), 'index.php?', 0, $prevmonth, $prevyear, true);
            $content .= "\n" . '<div class="calendar-controls">' . $prevlink;
            $content .= '<span class="hide"> | </span><span class="current"><a href="' . calendar_get_link_href(CALENDAR_URL . 'view.php?view=month' . $courseid . '&amp;', 1, $data['m'], $data['y']) . '">' . userdate($time, get_string('strftimemonthyear')) . '</a></span>';
            $content .= '<span class="hide"> | </span>' . $nextlink . "\n";
            $content .= "<span class=\"clearer\"><!-- --></span></div>\n";
            break;
        case 'course':
            list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
            list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
            $nextlink = calendar_get_link_next(get_string('monthnext', 'access'), 'view.php?id=' . $data['id'] . '&amp;', 0, $nextmonth, $nextyear, $accesshide = true);
            $prevlink = calendar_get_link_previous(get_string('monthprev', 'access'), 'view.php?id=' . $data['id'] . '&amp;', 0, $prevmonth, $prevyear, true);
            $content .= "\n" . '<div class="calendar-controls">' . $prevlink;
            $content .= '<span class="hide"> | </span><span class="current"><a href="' . calendar_get_link_href(CALENDAR_URL . 'view.php?view=month' . $courseid . '&amp;', 1, $data['m'], $data['y']) . '">' . userdate($time, get_string('strftimemonthyear')) . '</a></span>';
            $content .= '<span class="hide"> | </span>' . $nextlink . "\n";
            $content .= "<span class=\"clearer\"><!-- --></span></div>\n";
            break;
        case 'upcoming':
            $content .= '<div style="text-align: center;"><a href="' . CALENDAR_URL . 'view.php?view=upcoming"' . $courseid . '>' . userdate($time, get_string('strftimemonthyear')) . "</a></div>\n";
            break;
        case 'display':
            $content .= '<div style="text-align: center;"><a href="' . calendar_get_link_href(CALENDAR_URL . 'view.php?view=month' . $courseid . '&amp;', 1, $data['m'], $data['y']) . '">' . userdate($time, get_string('strftimemonthyear')) . "</a></div>\n";
            break;
        case 'month':
            list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
            list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
            $prevdate = make_timestamp($prevyear, $prevmonth, 1);
            $nextdate = make_timestamp($nextyear, $nextmonth, 1);
            $content .= "\n" . '<div class="calendar-controls">';
            $content .= calendar_get_link_previous(userdate($prevdate, get_string('strftimemonthyear')), 'view.php?view=month' . $courseid . '&amp;', 1, $prevmonth, $prevyear);
            $content .= '<span class="hide"> | </span><span class="current">' . userdate($time, get_string('strftimemonthyear')) . "</span>\n";
            $content .= '<span class="hide"> | </span>' . calendar_get_link_next(userdate($nextdate, get_string('strftimemonthyear')), 'view.php?view=month' . $courseid . '&amp;', 1, $nextmonth, $nextyear);
            $content .= "<span class=\"clearer\"><!-- --></span></div>\n";
            break;
        case 'day':
            $data['d'] = $date['mday'];
            // Just for convenience
            $prevdate = usergetdate(make_timestamp($data['y'], $data['m'], $data['d'] - 1));
            $nextdate = usergetdate(make_timestamp($data['y'], $data['m'], $data['d'] + 1));
            $prevname = calendar_wday_name($CALENDARDAYS[$prevdate['wday']]);
            $nextname = calendar_wday_name($CALENDARDAYS[$nextdate['wday']]);
            $content .= "\n" . '<div class="calendar-controls">';
            $content .= calendar_get_link_previous($prevname, 'view.php?view=day' . $courseid . '&amp;', $prevdate['mday'], $prevdate['mon'], $prevdate['year']);
            // Get the format string
            $text = get_string('strftimedaydate');
            /*
            // Regexp hackery to make a link out of the month/year part
            $text = ereg_replace('(%B.+%Y|%Y.+%B|%Y.+%m[^ ]+)', '<a href="'.calendar_get_link_href('view.php?view=month&amp;', 1, $data['m'], $data['y']).'">\\1</a>', $text);
            $text = ereg_replace('(F.+Y|Y.+F|Y.+m[^ ]+)', '<a href="'.calendar_get_link_href('view.php?view=month&amp;', 1, $data['m'], $data['y']).'">\\1</a>', $text);
            */
            // Replace with actual values and lose any day leading zero
            $text = userdate($time, $text);
            // Print the actual thing
            $content .= '<span class="hide"> | </span><span class="current">' . $text . '</span>';
            $content .= '<span class="hide"> | </span>' . calendar_get_link_next($nextname, 'view.php?view=day' . $courseid . '&amp;', $nextdate['mday'], $nextdate['mon'], $nextdate['year']);
            $content .= "<span class=\"clearer\"><!-- --></span></div>\n";
            break;
    }
    return $content;
}
Exemple #2
0
/**
 * Get control options for Calendar
 *
 * @param string $type of calendar
 * @param array $data calendar information
 * @return string $content return available control for the calender in html
 */
function calendar_top_controls($type, $data)
{
    global $CFG;
    $content = '';
    if (!isset($data['d'])) {
        $data['d'] = 1;
    }
    // Ensure course id passed if relevant
    // Required due to changes in view/lib.php mainly (calendar_session_vars())
    $courseid = '';
    if (!empty($data['id'])) {
        $courseid = '&amp;course=' . $data['id'];
    }
    if (!checkdate($data['m'], $data['d'], $data['y'])) {
        $time = time();
    } else {
        $time = make_timestamp($data['y'], $data['m'], $data['d']);
    }
    $date = usergetdate($time);
    $data['m'] = $date['mon'];
    $data['y'] = $date['year'];
    //Accessibility: calendar block controls, replaced <table> with <div>.
    //$nexttext = link_arrow_right(get_string('monthnext', 'access'), $url='', $accesshide=true);
    //$prevtext = link_arrow_left(get_string('monthprev', 'access'), $url='', $accesshide=true);
    switch ($type) {
        case 'frontpage':
            list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
            list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
            $nextlink = calendar_get_link_next(get_string('monthnext', 'access'), 'index.php?', 0, $nextmonth, $nextyear, $accesshide = true);
            $prevlink = calendar_get_link_previous(get_string('monthprev', 'access'), 'index.php?', 0, $prevmonth, $prevyear, true);
            $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')), 1, $data['m'], $data['y']);
            if (!empty($data['id'])) {
                $calendarlink->param('course', $data['id']);
            }
            if (right_to_left()) {
                $left = $nextlink;
                $right = $prevlink;
            } else {
                $left = $prevlink;
                $right = $nextlink;
            }
            $content .= html_writer::start_tag('div', array('class' => 'calendar-controls'));
            $content .= $left . '<span class="hide"> | </span>';
            $content .= html_writer::tag('span', html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')), array('title' => get_string('monththis', 'calendar'))), array('class' => 'current'));
            $content .= '<span class="hide"> | </span>' . $right;
            $content .= "<span class=\"clearer\"><!-- --></span>\n";
            $content .= html_writer::end_tag('div');
            break;
        case 'course':
            list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
            list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
            $nextlink = calendar_get_link_next(get_string('monthnext', 'access'), 'view.php?id=' . $data['id'] . '&amp;', 0, $nextmonth, $nextyear, $accesshide = true);
            $prevlink = calendar_get_link_previous(get_string('monthprev', 'access'), 'view.php?id=' . $data['id'] . '&amp;', 0, $prevmonth, $prevyear, true);
            $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')), 1, $data['m'], $data['y']);
            if (!empty($data['id'])) {
                $calendarlink->param('course', $data['id']);
            }
            if (right_to_left()) {
                $left = $nextlink;
                $right = $prevlink;
            } else {
                $left = $prevlink;
                $right = $nextlink;
            }
            $content .= html_writer::start_tag('div', array('class' => 'calendar-controls'));
            $content .= $left . '<span class="hide"> | </span>';
            $content .= html_writer::tag('span', html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')), array('title' => get_string('monththis', 'calendar'))), array('class' => 'current'));
            $content .= '<span class="hide"> | </span>' . $right;
            $content .= "<span class=\"clearer\"><!-- --></span>";
            $content .= html_writer::end_tag('div');
            break;
        case 'upcoming':
            $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'upcoming')), 1, $data['m'], $data['y']);
            if (!empty($data['id'])) {
                $calendarlink->param('course', $data['id']);
            }
            $calendarlink = html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')));
            $content .= html_writer::tag('div', $calendarlink, array('class' => 'centered'));
            break;
        case 'display':
            $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')), 1, $data['m'], $data['y']);
            if (!empty($data['id'])) {
                $calendarlink->param('course', $data['id']);
            }
            $calendarlink = html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')));
            $content .= html_writer::tag('h3', $calendarlink);
            break;
        case 'month':
            list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
            list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
            $prevdate = make_timestamp($prevyear, $prevmonth, 1);
            $nextdate = make_timestamp($nextyear, $nextmonth, 1);
            $prevlink = calendar_get_link_previous(userdate($prevdate, get_string('strftimemonthyear')), 'view.php?view=month' . $courseid . '&amp;', 1, $prevmonth, $prevyear);
            $nextlink = calendar_get_link_next(userdate($nextdate, get_string('strftimemonthyear')), 'view.php?view=month' . $courseid . '&amp;', 1, $nextmonth, $nextyear);
            if (right_to_left()) {
                $left = $nextlink;
                $right = $prevlink;
            } else {
                $left = $prevlink;
                $right = $nextlink;
            }
            $content .= html_writer::start_tag('div', array('class' => 'calendar-controls'));
            $content .= $left . '<span class="hide"> | </span><h1 class="current">' . userdate($time, get_string('strftimemonthyear')) . "</h1>";
            $content .= '<span class="hide"> | </span>' . $right;
            $content .= '<span class="clearer"><!-- --></span>';
            $content .= html_writer::end_tag('div') . "\n";
            break;
        case 'day':
            $days = calendar_get_days();
            $data['d'] = $date['mday'];
            // Just for convenience
            $prevdate = usergetdate(make_timestamp($data['y'], $data['m'], $data['d'] - 1));
            $nextdate = usergetdate(make_timestamp($data['y'], $data['m'], $data['d'] + 1));
            $prevname = calendar_wday_name($days[$prevdate['wday']]);
            $nextname = calendar_wday_name($days[$nextdate['wday']]);
            $prevlink = calendar_get_link_previous($prevname, 'view.php?view=day' . $courseid . '&amp;', $prevdate['mday'], $prevdate['mon'], $prevdate['year']);
            $nextlink = calendar_get_link_next($nextname, 'view.php?view=day' . $courseid . '&amp;', $nextdate['mday'], $nextdate['mon'], $nextdate['year']);
            if (right_to_left()) {
                $left = $nextlink;
                $right = $prevlink;
            } else {
                $left = $prevlink;
                $right = $nextlink;
            }
            $content .= html_writer::start_tag('div', array('class' => 'calendar-controls'));
            $content .= $left;
            $content .= '<span class="hide"> | </span><span class="current">' . userdate($time, get_string('strftimedaydate')) . '</span>';
            $content .= '<span class="hide"> | </span>' . $right;
            $content .= "<span class=\"clearer\"><!-- --></span>";
            $content .= html_writer::end_tag('div') . "\n";
            break;
    }
    return $content;
}
Exemple #3
0
/**
 * Get control options for Calendar
 *
 * @param string $type of calendar
 * @param array $data calendar information
 * @return string $content return available control for the calender in html
 */
function calendar_top_controls($type, $data)
{
    global $PAGE;
    // Get the calendar type we are using.
    $calendartype = \core_calendar\type_factory::get_calendar_instance();
    $content = '';
    // Ensure course id passed if relevant.
    $courseid = '';
    if (!empty($data['id'])) {
        $courseid = '&amp;course=' . $data['id'];
    }
    // If we are passing a month and year then we need to convert this to a timestamp to
    // support multiple calendars. No where in core should these be passed, this logic
    // here is for third party plugins that may use this function.
    if (!empty($data['m']) && !empty($date['y'])) {
        if (!isset($data['d'])) {
            $data['d'] = 1;
        }
        if (!checkdate($data['m'], $data['d'], $data['y'])) {
            $time = time();
        } else {
            $time = make_timestamp($data['y'], $data['m'], $data['d']);
        }
    } else {
        if (!empty($data['time'])) {
            $time = $data['time'];
        } else {
            $time = time();
        }
    }
    // Get the date for the calendar type.
    $date = $calendartype->timestamp_to_date_array($time);
    $urlbase = $PAGE->url;
    // We need to get the previous and next months in certain cases.
    if ($type == 'frontpage' || $type == 'course' || $type == 'month') {
        $prevmonth = calendar_sub_month($date['mon'], $date['year']);
        $prevmonthtime = $calendartype->convert_to_gregorian($prevmonth[1], $prevmonth[0], 1);
        $prevmonthtime = make_timestamp($prevmonthtime['year'], $prevmonthtime['month'], $prevmonthtime['day'], $prevmonthtime['hour'], $prevmonthtime['minute']);
        $nextmonth = calendar_add_month($date['mon'], $date['year']);
        $nextmonthtime = $calendartype->convert_to_gregorian($nextmonth[1], $nextmonth[0], 1);
        $nextmonthtime = make_timestamp($nextmonthtime['year'], $nextmonthtime['month'], $nextmonthtime['day'], $nextmonthtime['hour'], $nextmonthtime['minute']);
    }
    switch ($type) {
        case 'frontpage':
            $prevlink = calendar_get_link_previous(get_string('monthprev', 'access'), $urlbase, false, false, false, true, $prevmonthtime);
            $nextlink = calendar_get_link_next(get_string('monthnext', 'access'), $urlbase, false, false, false, true, $nextmonthtime);
            $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')), false, false, false, $time);
            if (!empty($data['id'])) {
                $calendarlink->param('course', $data['id']);
            }
            if (right_to_left()) {
                $left = $nextlink;
                $right = $prevlink;
            } else {
                $left = $prevlink;
                $right = $nextlink;
            }
            $content .= html_writer::start_tag('div', array('class' => 'calendar-controls'));
            $content .= $left . '<span class="hide"> | </span>';
            $content .= html_writer::tag('span', html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')), array('title' => get_string('monththis', 'calendar'))), array('class' => 'current'));
            $content .= '<span class="hide"> | </span>' . $right;
            $content .= "<span class=\"clearer\"><!-- --></span>\n";
            $content .= html_writer::end_tag('div');
            break;
        case 'course':
            $prevlink = calendar_get_link_previous(get_string('monthprev', 'access'), $urlbase, false, false, false, true, $prevmonthtime);
            $nextlink = calendar_get_link_next(get_string('monthnext', 'access'), $urlbase, false, false, false, true, $nextmonthtime);
            $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')), false, false, false, $time);
            if (!empty($data['id'])) {
                $calendarlink->param('course', $data['id']);
            }
            if (right_to_left()) {
                $left = $nextlink;
                $right = $prevlink;
            } else {
                $left = $prevlink;
                $right = $nextlink;
            }
            $content .= html_writer::start_tag('div', array('class' => 'calendar-controls'));
            $content .= $left . '<span class="hide"> | </span>';
            $content .= html_writer::tag('span', html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')), array('title' => get_string('monththis', 'calendar'))), array('class' => 'current'));
            $content .= '<span class="hide"> | </span>' . $right;
            $content .= "<span class=\"clearer\"><!-- --></span>";
            $content .= html_writer::end_tag('div');
            break;
        case 'upcoming':
            $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'upcoming')), false, false, false, $time);
            if (!empty($data['id'])) {
                $calendarlink->param('course', $data['id']);
            }
            $calendarlink = html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')));
            $content .= html_writer::tag('div', $calendarlink, array('class' => 'centered'));
            break;
        case 'display':
            $calendarlink = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', array('view' => 'month')), false, false, false, $time);
            if (!empty($data['id'])) {
                $calendarlink->param('course', $data['id']);
            }
            $calendarlink = html_writer::link($calendarlink, userdate($time, get_string('strftimemonthyear')));
            $content .= html_writer::tag('h3', $calendarlink);
            break;
        case 'month':
            $prevlink = calendar_get_link_previous(userdate($prevmonthtime, get_string('strftimemonthyear')), 'view.php?view=month' . $courseid . '&amp;', false, false, false, false, $prevmonthtime);
            $nextlink = calendar_get_link_next(userdate($nextmonthtime, get_string('strftimemonthyear')), 'view.php?view=month' . $courseid . '&amp;', false, false, false, false, $nextmonthtime);
            if (right_to_left()) {
                $left = $nextlink;
                $right = $prevlink;
            } else {
                $left = $prevlink;
                $right = $nextlink;
            }
            $content .= html_writer::start_tag('div', array('class' => 'calendar-controls'));
            $content .= $left . '<span class="hide"> | </span><h1 class="current">' . userdate($time, get_string('strftimemonthyear')) . "</h1>";
            $content .= '<span class="hide"> | </span>' . $right;
            $content .= '<span class="clearer"><!-- --></span>';
            $content .= html_writer::end_tag('div') . "\n";
            break;
        case 'day':
            $days = calendar_get_days();
            $prevtimestamp = $time - DAYSECS;
            $nexttimestamp = $time + DAYSECS;
            $prevdate = $calendartype->timestamp_to_date_array($prevtimestamp);
            $nextdate = $calendartype->timestamp_to_date_array($nexttimestamp);
            $prevname = $days[$prevdate['wday']]['fullname'];
            $nextname = $days[$nextdate['wday']]['fullname'];
            $prevlink = calendar_get_link_previous($prevname, 'view.php?view=day' . $courseid . '&amp;', false, false, false, false, $prevtimestamp);
            $nextlink = calendar_get_link_next($nextname, 'view.php?view=day' . $courseid . '&amp;', false, false, false, false, $nexttimestamp);
            if (right_to_left()) {
                $left = $nextlink;
                $right = $prevlink;
            } else {
                $left = $prevlink;
                $right = $nextlink;
            }
            $content .= html_writer::start_tag('div', array('class' => 'calendar-controls'));
            $content .= $left;
            $content .= '<span class="hide"> | </span><span class="current">' . userdate($time, get_string('strftimedaydate')) . '</span>';
            $content .= '<span class="hide"> | </span>' . $right;
            $content .= "<span class=\"clearer\"><!-- --></span>";
            $content .= html_writer::end_tag('div') . "\n";
            break;
    }
    return $content;
}
function top_controls($month, $year) {
    global $OUTPUT, $currenttab;

    $content = '';

    $time = make_timestamp($year, $month, 1);
    $date = usergetdate($time);

    $data['m'] = $date['mon'];
    $data['y'] = $date['year'];

    list($prevmonth, $prevyear) = calendar_sub_month($data['m'], $data['y']);
    list($nextmonth, $nextyear) = calendar_add_month($data['m'], $data['y']);
    $prevdate = make_timestamp($prevyear, $prevmonth, 1);
    $nextdate = make_timestamp($nextyear, $nextmonth, 1);
    $content .= $OUTPUT->container_start('calendar-controls');
    $content .= html_writer::start_tag('table', array('summary' => '')) . html_writer::start_tag('tr') . html_writer::start_tag('td');
    $content .= calendar_get_link_previous(userdate($prevdate, get_string('strftimemonthyear')), "calendar.php?tab=$currenttab&amp;", 1, $prevmonth, $prevyear);
    $content .= html_writer::end_tag('td') . html_writer::tag('td', html_writer::tag('span', '|', array('class' => 'hide')) . html_writer::tag('span', userdate($time, get_string('strftimemonthyear')), array('class' => 'current')), array('align' => 'center'));
    $content .= html_writer::tag('td', html_writer::tag('span', '|', array('class' => 'hide')) . calendar_get_link_next(userdate($nextdate, get_string('strftimemonthyear')), "calendar.php?tab=$currenttab&amp;", 1, $nextmonth, $nextyear) . html_writer::tag('span', '<!-- -->', array('class' => 'clearer')), array('align' => 'right'));
    $content .= html_writer::end_tag('tr') . html_writer::end_tag('table');
    $content .= $OUTPUT->container_end() . "\n";
    return $content;
}