Skip to content

Commit

Permalink
Merge branch 'MDL-48943-master' of git://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Mar 11, 2015
2 parents 728e272 + dc3b252 commit 3fb98d6
Show file tree
Hide file tree
Showing 18 changed files with 1,038 additions and 487 deletions.
69 changes: 36 additions & 33 deletions calendar/lib.php
Expand Up @@ -179,7 +179,7 @@ function calendar_get_starting_weekday() {
*/
function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyear = false, $placement = false,
$courseid = false, $time = 0) {
global $CFG, $OUTPUT;
global $CFG, $OUTPUT, $PAGE;

// Get the calendar type we are using.
$calendartype = \core_calendar\type_factory::get_calendar_instance();
Expand Down Expand Up @@ -289,7 +289,8 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea

// Accessibility: added summary and <abbr> elements.
$summary = get_string('calendarheading', 'calendar', userdate($display->tstart, get_string('strftimemonthyear')));
$content .= '<table class="minicalendar calendartable" summary="'.$summary.'">'; // Begin table.
// Begin table.
$content .= '<table class="minicalendar calendartable" summary="' . $summary . '">';
if (($placement !== false) && ($courseid !== false)) {
$content .= '<caption>'. calendar_top_controls($placement, array('id' => $courseid, 'time' => $time)) .'</caption>';
}
Expand Down Expand Up @@ -320,6 +321,7 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
// Now display all the calendar
$daytime = strtotime('-1 day', $display->tstart);
for($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
$cellattributes = array();
$daytime = strtotime('+1 day', $daytime);
if($dayweek > $display->maxwday) {
// We need to change week (table row)
Expand All @@ -336,8 +338,8 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
$class = 'day';
}

// Special visual fx if an event is defined
if(isset($eventsbyday[$day])) {
if (isset($eventsbyday[$day])) {
// There is at least one event on this day.

$class .= ' hasevent';
$hrefparams['view'] = 'day';
Expand Down Expand Up @@ -381,12 +383,12 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
$popupcontent .= html_writer::end_tag('div');
}

//Accessibility: functionality moved to calendar_get_popup.
if($display->thismonth && $day == $d) {
$popupid = calendar_get_popup(true, $events[$eventid]->timestart, $popupcontent);
if ($display->thismonth && $day == $d) {
$popupdata = calendar_get_popup(true, $events[$eventid]->timestart, $popupcontent);
} else {
$popupid = calendar_get_popup(false, $events[$eventid]->timestart, $popupcontent);
$popupdata = calendar_get_popup(false, $events[$eventid]->timestart, $popupcontent);
}
$cellattributes = array_merge($cellattributes, $popupdata);

// Class and cell content
if(isset($typesbyday[$day]['startglobal'])) {
Expand All @@ -398,7 +400,7 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
} else if(isset($typesbyday[$day]['startuser'])) {
$class .= ' calendar_event_user';
}
$cell = html_writer::link($dayhref, $day, array('id' => $popupid));
$cell = html_writer::link($dayhref, $day);
} else {
$cell = $day;
}
Expand Down Expand Up @@ -432,25 +434,23 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
}
}

// Special visual fx for today
//Accessibility: hidden text for today, and popup.
if($display->thismonth && $day == $d) {
if ($display->thismonth && $day == $d) {
// The current cell is for today - add appropriate classes and additional information for styling.
$class .= ' today';
$today = get_string('today', 'calendar').' '.userdate(time(), get_string('strftimedayshort'));

if(! isset($eventsbyday[$day])) {
if (!isset($eventsbyday[$day])) {
$class .= ' eventnone';
$popupid = calendar_get_popup(true, false);
$cell = html_writer::link('#', $day, array('id' => $popupid));
$popupdata = calendar_get_popup(true, false);
$cellattributes = array_merge($cellattributes, $popupdata);
$cell = html_writer::link('#', $day);
}
$cell = get_accesshide($today.' ').$cell;
$cell = get_accesshide($today . ' ') . $cell;
}

// Just display it
if(!empty($class)) {
$class = ' class="'.$class.'"';
}
$content .= '<td'.$class.'>'.$cell."</td>\n";
$cellattributes['class'] = $class;
$content .= html_writer::tag('td', $cell, $cellattributes);
}

// Paddding (the last week may have blank days at the end)
Expand All @@ -461,6 +461,11 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea

$content .= '</table>'; // Tabular display of days ends

static $jsincluded = false;
if (!$jsincluded) {
$PAGE->requires->yui_module('moodle-calendar-info', 'Y.M.core_calendar.info.init');
$jsincluded = true;
}
return $content;
}

Expand All @@ -475,28 +480,26 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
* @param string $popupcontent content for the popup window/layout.
* @return string eventid for the calendar_tooltip popup window/layout.
*/
function calendar_get_popup($is_today, $event_timestart, $popupcontent='') {
function calendar_get_popup($today = false, $timestart, $popupcontent = '') {
global $PAGE;
static $popupcount;
if ($popupcount === null) {
$popupcount = 1;
}

$popupcaption = '';
if($is_today) {
$popupcaption = get_string('today', 'calendar').' ';
if ($today) {
$popupcaption = get_string('today', 'calendar') . ' ';
}
if (false === $event_timestart) {

if (false === $timestart) {
$popupcaption .= userdate(time(), get_string('strftimedayshort'));
$popupcontent = get_string('eventnone', 'calendar');

} else {
$popupcaption .= get_string('eventsfor', 'calendar', userdate($event_timestart, get_string('strftimedayshort')));
$popupcaption .= get_string('eventsfor', 'calendar', userdate($timestart, get_string('strftimedayshort')));
}
$id = 'calendar_tooltip_'.$popupcount;
$PAGE->requires->yui_module('moodle-calendar-eventmanager', 'M.core_calendar.add_event', array(array('eventId'=>$id,'title'=>$popupcaption, 'content'=>$popupcontent)));

$popupcount++;
return $id;
return array(
'data-core_calendar-title' => $popupcaption,
'data-core_calendar-popupcontent' => $popupcontent,
);
}

/**
Expand Down
54 changes: 52 additions & 2 deletions calendar/tests/behat/behat_calendar.php
Expand Up @@ -40,7 +40,7 @@
class behat_calendar extends behat_base {

/**
* Create event.
* Create event when starting on the front page.
*
* @Given /^I create a calendar event with form data:$/
* @param TableNode $data
Expand All @@ -53,10 +53,60 @@ public function i_create_a_calendar_event_with_form_data($data) {

return array(
new Given('I follow "' . get_string('monththis', 'calendar') . '"'),
new Given('I create a calendar event:', $data),
);
}

/**
* Create event.
*
* @Given /^I create a calendar event:$/
* @param TableNode $data
* @return array the list of actions to perform
*/
public function i_create_a_calendar_event($data) {
// Get the event name.
$eventname = $data->getRow(1);
$eventname = $eventname[1];

return array(
new Given('I click on "' . get_string('newevent', 'calendar') .'" "button"'),
new Given('I set the following fields to these values:', $data),
new Given('I press "' . get_string('savechanges') . '"'),
new Given('I should see "' . $eventname . '"')
);
}
}

/**
* Hover over a specific day in the calendar.
*
* @Given /^I hover over day "(?P<dayofmonth>\d+)" of this month in the calendar$/
* @param int $day The day of the current month
* @return Given[]
*/
public function i_hover_over_day_of_this_month_in_calendar($day) {
$summarytitle = get_string('calendarheading', 'calendar', userdate(time(), get_string('strftimemonthyear')));
// The current month table.
$currentmonth = "table[contains(concat(' ', normalize-space(@summary), ' '), ' {$summarytitle} ')]";

// Strings for the class cell match.
$cellclasses = "contains(concat(' ', normalize-space(@class), ' '), ' day ')";
$daycontains = "text()[contains(concat(' ', normalize-space(.), ' '), ' {$day} ')]";
$daycell = "td[{$cellclasses}]";
$dayofmonth = "a[{$daycontains}]";
return array(
new Given('I hover "//' . $currentmonth . '/descendant::' . $daycell . '/' . $dayofmonth . '" "xpath_element"'),
);
}

/**
* Hover over today in the calendar.
*
* @Given /^I hover over today in the calendar$/
* @return Given[]
*/
public function i_hover_over_today_in_the_calendar() {
$todaysday = trim(strftime('%e'));
return $this->i_hover_over_day_of_this_month_in_calendar($todaysday);
}
}
48 changes: 48 additions & 0 deletions calendar/tests/behat/minicalendar.feature
@@ -0,0 +1,48 @@
@core @core_calendar @arn
Feature: Open calendar popup
In order to view calendar information
As a user
I need to interact with the calendar

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@asd.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
And I log in as "admin"

@javascript
Scenario: I view calendar details of a day with multiple events
Given I follow "This month"
And I create a calendar event:
| Type of event | site |
| Event title | Event 1:1 |
| timestart[day] | 1 |
And I create a calendar event:
| Type of event | site |
| Event title | Event 1:2 |
| timestart[day] | 1 |
When I hover over day "1" of this month in the calendar
Then I should see "Event 1:1"
And I should see "Event 1:2"
And I follow "Home"
And I hover over day "1" of this month in the calendar
And I should see "Event 1:1"
And I should see "Event 1:2"

@javascript
Scenario: I view calendar details for today
Given I follow "This month"
And I create a calendar event:
| Type of event | site |
| Event title | Today's event |
When I hover over today in the calendar
Then I should see "Today's event"
And I follow "Home"
And I hover over today in the calendar
And I should see "Today's event"

0 comments on commit 3fb98d6

Please sign in to comment.