Skip to content

Commit

Permalink
OU Blog & OUWiki: Add last updated indicator #82566
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-platts authored and sammarshallou committed Nov 27, 2015
1 parent 0a5f2c1 commit 1ddf6eb
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lang/en/ouwiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
$string['pluginadministration'] = 'OU wiki administration';
$string['pluginname'] = 'OU wiki';

$string['lastmodified'] = 'Last edit: {$a}';
$string['strftimerecent'] = '%d %B %y, %H:%M';

$string['summary'] = 'Summary';

$string['attachments'] = 'Attachments';
Expand Down
19 changes: 19 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,25 @@ function ouwiki_cm_info_dynamic(cm_info $cm) {
}
}

/**
* Show last updated date + time (version created).
*
* @param cm_info $cm
*/
function ouwiki_cm_info_view(cm_info $cm) {
global $CFG;
if (!$cm->uservisible) {
return;
}
require_once($CFG->dirroot . '/mod/ouwiki/locallib.php');

$lastpostdate = ouwiki_get_last_modified($cm, $cm->get_course());
if (!empty($lastpostdate)) {
$cm->set_after_link(html_writer::span(get_string('lastmodified', 'ouwiki',
userdate($lastpostdate, get_string('strftimerecent', 'ouwiki'))), 'lastmodtext ouwikilmt'));
}
}

/**
* List of view style log actions
* @return array
Expand Down
30 changes: 28 additions & 2 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2830,6 +2830,8 @@ function handleFailure(o) {
* account the user's groups/individual settings if required. (Does not check
* that user can view the wiki.)
*
* Info is static cached, so can be called in multiple places on page.
*
* @param object $cm Course-modules entry for wiki
* @param object $Course Course object
* @param int $userid User ID or 0 = current
Expand All @@ -2841,7 +2843,29 @@ function ouwiki_get_last_modified($cm, $course, $userid = 0) {
if (!$userid) {
$userid = $USER->id;
}
$ouwiki = $DB->get_record('ouwiki', array('id' => $cm->instance));

static $results;
if (!isset($results)) {
$results = array();
}
if (!array_key_exists($userid, $results)) {
$results[$userid] = array();
} else if (array_key_exists($cm->id, $results[$userid])) {
return $results[$userid][$cm->id];
}

static $ouwikis;
if (!isset($ouwikis)) {
$ouwikis = array();
}
if (empty($ouwikis[$course->id])) {
$ouwikis[$course->id] = $DB->get_records('ouwiki', array('course' => $course->id));
}
// Get wiki record.
if (!isset($ouwikis[$course->id][$cm->instance])) {
return false;
}
$ouwiki = $ouwikis[$course->id][$cm->instance];

// Default applies no restriction
$restrictjoin = '';
Expand Down Expand Up @@ -2902,7 +2926,9 @@ function ouwiki_get_last_modified($cm, $course, $userid = 0) {
'wikiid' => $cm->instance
);

return $DB->get_field_sql($sql, $params);
$result = $DB->get_field_sql($sql, $params);
$results[$userid][$cm->id] = $result;
return $result;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -895,3 +895,8 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited {
.ouwiki_import.ouwiki_import_step4 ul {
list-style: none;
}

.ouwikilmt {
font-size: 0.8em;
margin-left: 5px;
}
110 changes: 110 additions & 0 deletions tests/behat/lastupdated.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
@ou @ou_vle @mod @mod_ouwiki @lastmodified
Feature: Show last updated information on activity link
In know when a wiki was last updated
As a user
I need to see the last post date on the wiki link

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@asd.com |
| student2 | Student | 2 | student2@asd.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| student2 | C1 | student |
And the following "groups" exist:
| name | course | idnumber |
| G1 | C1 | G1 |
| G2 | C1 | G2 |
And the following "group members" exist:
| user | group |
| student1 | G1 |
| student2 | G2 |

Scenario: No groups - basic test etc
Given I log in as "admin"
And I am on site homepage
And I follow "Course 1"
And I turn editing mode on
When I add a "OU wiki" to section "1" and I fill the form with:
| Name | W.WC |
| Description | wiki with no groups |
| Group mode | No groups |
Then I should see "W.WC"
And ".lastmodtext.ouwikilmt" "css_element" should not exist
Given I follow "W.WC"
And "Create page" "button" should exist
And I press "Create page"
And I set the field "Content" to "C1 no groups wiki"
And I press "Save changes"
When I follow "Course 1"
Then ".lastmodtext.ouwikilmt" "css_element" should exist

Scenario: Group wikis
Given I log in as "admin"
And I am on site homepage
And I follow "Course 1"
And I turn editing mode on
And I add a "OU wiki" to section "1" and I fill the form with:
| Name | W.SG |
| Description | Separate groups |
| Sub-wikis | One wiki per group |
| Group mode | Separate groups |
And I add a "OU wiki" to section "2" and I fill the form with:
| Name | W.VG |
| Description | Visible groups |
| Sub-wikis | One wiki per group |
| Group mode | Visible groups |
And I log out
# Test for student1 in group 1.
Given I log in as "student1"
And I am on site homepage
When I follow "Course 1"
Then "/descendant::div[@class='activityinstance'][1]//span[@class='lastmodtext ouwikilmt']" "xpath_element" should not exist
And "/descendant::div[@class='activityinstance'][2]//span[@class='lastmodtext ouwikilmt']" "xpath_element" should not exist
Given I follow "W.SG"
And I press "Create page"
And I set the field "Content" to "C2 separate groups wiki"
And I press "Save changes"
And I follow "Course 1"
When I follow "W.VG"
And I press "Create page"
And I set the field "Content" to "C3 visible groups wiki"
And I press "Save changes"
And I follow "Course 1"
Then "/descendant::div[@class='activityinstance'][1]//span[@class='lastmodtext ouwikilmt']" "xpath_element" should exist
And "/descendant::div[@class='activityinstance'][2]//span[@class='lastmodtext ouwikilmt']" "xpath_element" should exist
And I log out
# Test for student 2 in group 2.
Given I log in as "student2"
And I am on site homepage
When I follow "Course 1"
Then "/descendant::div[@class='activityinstance'][1]//span[@class='lastmodtext ouwikilmt']" "xpath_element" should not exist
And "/descendant::div[@class='activityinstance'][2]//span[@class='lastmodtext ouwikilmt']" "xpath_element" should exist

Scenario: Individual wikis
Given I log in as "admin"
And I am on site homepage
And I follow "Course 1"
And I turn editing mode on
And I add a "OU wiki" to section "1" and I fill the form with:
| Name | W.SI |
| Description | individual wikis |
| Sub-wikis |Separate wiki for every user |
| Group mode | No groups |
When I follow "W.SI"
And I press "Create page"
And I set the field "Content" to "C4 individual wiki"
And I press "Save changes"
And I follow "Course 1"
Then "/descendant::div[@class='activityinstance'][1]//span[@class='lastmodtext ouwikilmt']" "xpath_element" should exist
And I log out
# Checking individual wiki for student 1 (visible info only).
Given I log in as "student1"
And I am on site homepage
And I follow "Course 1"
Then "/descendant::div[@class='activityinstance'][1]//span[@class='lastmodtext ouwikilmt']" "xpath_element" should not exist
38 changes: 36 additions & 2 deletions tests/locallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function setUp() {
ouwiki_tree_index()
ouwiki_display_entirewiki_page_in_index()
ouwiki_get_sub_tree_from_index()
ouwiki_get_last_modified()
Functions not covered:
Delete/undelete page version - no backend functions for this process
Expand Down Expand Up @@ -590,6 +591,39 @@ public function test_ouwiki_structure() {
$this->assertEquals(2, count(ouwiki_get_sub_tree_from_index($page->pageid, $index)));
}

/**
* Simple test of last modified time returning
*/
public function test_ouwiki_get_last_modified() {
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
$user = $this->get_new_user();
$user2 = $this->get_new_user('testouwikiuser2');
$course = $this->get_new_course();
$ouwiki = $this->get_new_ouwiki($course->id, OUWIKI_SUBWIKIS_SINGLE);
$cm = get_coursemodule_from_instance('ouwiki', $ouwiki->id);
$context = context_module::instance($cm->id);

$result = ouwiki_get_last_modified($cm, $course);
$this->assertEmpty($result);

// Create page + test last modified returns something.
$subwiki = ouwiki_get_subwiki($course, $ouwiki, $cm, $context, 0, $user2->id, true);
$page = ouwiki_get_current_page($subwiki, 'startpage', OUWIKI_GETPAGE_CREATE);
ouwiki_save_new_version($course, $cm, $ouwiki, $subwiki, 'startpage', 'content', -1, -1, -1);

$result = ouwiki_get_last_modified($cm, $course, $user2->id);
$this->assertNotEmpty($result);
// Check other user gets a time.
$result2 = ouwiki_get_last_modified($cm, $course, $user->id);
$this->assertNotEmpty($result2);
$this->assertEquals($result, $result2);
// Check admin gets cached.
$result = ouwiki_get_last_modified($cm, $course);
$this->assertEmpty($result);
}

/*
These functions enable us to create database entries and/or grab objects to make it possible to test the
many permuations required for OU Wiki.
Expand All @@ -613,8 +647,8 @@ public function get_page_from_index_by_pageid($pageid, $index) {
return null;
}

public function get_new_user() {
return $this->getDataGenerator()->create_user(array('username' => 'testouwikiuser'));
public function get_new_user($username = 'testouwikiuser') {
return $this->getDataGenerator()->create_user(array('username' => $username));
}


Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$plugin->version = 2015051100;
$plugin->version = 2015101500;
$plugin->requires = 2014051200;
$plugin->component = 'mod_ouwiki';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '2.7 r1';
$plugin->release = '2.9 r1';

0 comments on commit 1ddf6eb

Please sign in to comment.