Skip to content

Commit

Permalink
OUBlog: Update My Participation screen design #9824
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-platts authored and sammarshallou committed Jul 29, 2014
1 parent 2eac2a7 commit 073a538
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 97 deletions.
15 changes: 8 additions & 7 deletions lang/en/oublog.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,13 @@
$string['foruser'] = ' for {$a}';
$string['postsby'] = 'Posts by {$a}';
$string['commentsby'] = 'Comments by {$a}';
$string['commentonby'] = 'Comment on <u>{$a->title}</u> by <u>{$a->author}</u>';
$string['commentonby'] = 'Comment on post <u>{$a->title}</u> {$a->date} by <u>{$a->author}</u>';
$string['nouserposts'] = 'No posts made.';
$string['nousercomments'] = 'No comments made.';
$string['savegrades'] = 'Save grades';
$string['gradesupdated'] = 'Grades updated';
$string['usergrade'] = 'User grade';
$string['nousergrade'] = 'User grade not available.';

// Participation download strings.
$string['downloadas'] = 'Download data as';
Expand Down Expand Up @@ -526,14 +527,14 @@
$string['import_step2_conflicts_submit'] = 'Import conflicting posts';

// My Participation.
$string['contribution'] = 'Contribution';
$string['contribution_all'] = 'Contribution - All time';
$string['contribution_from'] = 'Contribution - From {$a}';
$string['contribution_to'] = 'Contribution - To {$a}';
$string['contribution_fromto'] = 'Contribution - From {$a->start} To {$a->end}';
$string['contribution'] = 'Participation';
$string['contribution_all'] = 'Participation - All time';
$string['contribution_from'] = 'Participation - From {$a}';
$string['contribution_to'] = 'Participation - To {$a}';
$string['contribution_fromto'] = 'Participation - From {$a->start} To {$a->end}';
$string['start'] = 'From';
$string['end'] = 'To';
$string['displayperiod'] = 'Contribution selector From date - To date.';
$string['displayperiod'] = 'Participation selector From date - To date.';
$string['info'] = 'Participation within the selected period.';
$string['displayperiod_help'] = '<p>The default selects all entries.</p>
<p>You can select \'From\' a date until todays entries.</p>
Expand Down
46 changes: 32 additions & 14 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3036,10 +3036,16 @@ function oublog_get_participation($oublog, $context, $groupid=0, $cm,
* @param object $course current course object
* @param int $start optional start date
* @param int $end optional end date
* @param bool $getposts Return post data
* @param bool $getcomments Return comment data
* @param int $limitfrom limit posts/comments from
* @param int $limitnum number of posts/comments (data only) to limit to
* @param bool $getgrades return grade info
* @return array user participation
*/
function oublog_get_user_participation($oublog, $context,
$userid, $groupid=0, $cm, $course, $start = null, $end = null) {
$userid, $groupid = 0, $cm, $course, $start = null, $end = null,
$getposts = true, $getcomments = true, $limitfrom = null, $limitnum = null, $getgrades = false) {
global $DB;
$testgroupid = $groupid;
if ($oublog->individual > 0) {
Expand Down Expand Up @@ -3071,12 +3077,14 @@ function oublog_get_user_participation($oublog, $context,
$cperiod .= 'AND c.timeposted < :timeend ';
}
$authornamefields = get_all_user_name_fields(true, 'a');
$postauthornamefields = get_all_user_name_fields(true, 'pa', '', 'poster');
$commentssql = 'SELECT c.id, c.postid, c.title, c.message, c.timeposted,
a.id AS authorid, ' . $authornamefields . ',
a.id AS authorid, ' . $authornamefields . ',' . $postauthornamefields . ',
p.title AS posttitle, p.timeposted AS postdate
FROM {user} a, {oublog_comments} c
INNER JOIN {oublog_posts} p ON (c.postid = p.id)
INNER JOIN {oublog_instances} bi ON (bi.id = p.oubloginstancesid)
INNER JOIN {user} pa on bi.userid = pa.id
WHERE bi.oublogid = :oublogid AND a.id = bi.userid
AND p.timedeleted IS NULL ' . $groupcheck . $cperiod . '
AND c.userid = :userid AND c.timedeleted IS NULL
Expand All @@ -3093,11 +3101,21 @@ function oublog_get_user_participation($oublog, $context,
$fields = user_picture::fields();
$fields .= ',username,idnumber';
$user = $DB->get_record('user', array('id' => $userid), $fields, MUST_EXIST);
$participation = new StdClass;
$participation = new stdClass();
$participation->user = $user;
$participation->posts = $DB->get_records_sql($postssql, $params);
$participation->comments = $DB->get_records_sql($commentssql, $params);
if (oublog_can_grade($course, $oublog, $cm, $groupid)) {
$participation->numposts = $DB->get_field_sql("SELECT COUNT(1) FROM ($postssql) as p", $params);
if ($getposts) {
$participation->posts = $DB->get_records_sql($postssql, $params, $limitfrom, $limitnum);
} else {
$participation->posts = array();
}
$participation->numcomments = $DB->get_field_sql("SELECT COUNT(1) FROM ($commentssql) as p", $params);
if ($getcomments) {
$participation->comments = $DB->get_records_sql($commentssql, $params, $limitfrom, $limitnum);
} else {
$participation->comments = array();
}
if ($getgrades && oublog_can_grade($course, $oublog, $cm, $groupid)) {
$gradinginfo = grade_get_grades($course->id, 'mod',
'oublog', $oublog->id, array($userid));
$participation->gradeobj = $gradinginfo->items[0]->grades[$userid];
Expand Down Expand Up @@ -3899,23 +3917,23 @@ function oublog_stats_output_myparticipation($oublog, $cm, $renderer = null, $co
$context = context_module::instance($cm->id);
// Get the participation object containing User, Posts and Comments.
$participation = oublog_get_user_participation($oublog, $context,
$USER->id, $curgroup, $cm, $course);
$USER->id, $curgroup, $cm, $course, null, null, true, true, null, 8);
// Generate content data to send to renderer.
$maintitle = get_string('myparticipation', 'oublog');// The title of the block 'section'.
$content = '';
$postedcount = $commentedcount = $commenttotal = 0;
$postshow = 8;
$postscount = count($participation->posts);
if (count($participation->comments) <= 4) {
$commenttotal = count($participation->comments);
$postscount = $participation->numposts;
if ($participation->numcomments <= 4) {
$commenttotal = $participation->numcomments;
} else {
$commenttotal = 4;
}
if (!$participation->posts) {
$content .= html_writer::tag('p', get_string('nouserposts', 'oublog'));
} else {
$percent = $stat = null;
$content .= html_writer::tag('h3', get_string('numberposts', 'oublog', count($participation->posts)));
$content .= html_writer::tag('h3', get_string('numberposts', 'oublog', $participation->numposts));
foreach ($participation->posts as $post) {
if ($postedcount >= ($postshow - $commenttotal)) {
break;
Expand All @@ -3930,15 +3948,15 @@ function oublog_stats_output_myparticipation($oublog, $cm, $renderer = null, $co
}
}
// Pre test the numbers of posts/comments for display upto max.
$postspluscount = count($participation->posts) - $postedcount;
$postspluscount = $participation->numposts - $postedcount;
if ($postspluscount >= 1) {
$content .= html_writer::tag('p', get_string('numberpostsmore', 'oublog', $postspluscount));
}
if (!$participation->comments) {
$content .= html_writer::tag('p', get_string('nousercomments', 'oublog'));
} else {
$percent = $stat = null;// Removing all stats div.
$content .= html_writer::tag('h3', get_string('numbercomments', 'oublog', count($participation->comments)));
$content .= html_writer::tag('h3', get_string('numbercomments', 'oublog', $participation->numcomments));
foreach ($participation->comments as $comment) {
if (($commentedcount + $postedcount) >= $postshow ) {
break;
Expand All @@ -3954,7 +3972,7 @@ function oublog_stats_output_myparticipation($oublog, $cm, $renderer = null, $co
}
}
// If the number of comments is more than can be shown.
$commentspluscount = count($participation->comments) - $commentedcount;
$commentspluscount = $participation->numcomments - $commentedcount;
if ($commentspluscount >= 1) {
$content .= html_writer::tag('p', get_string('numbercommentsmore', 'oublog', $commentspluscount));
}
Expand Down
14 changes: 4 additions & 10 deletions participation_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ class oublog_user_participation_table extends flexible_table {
public $userfullname;
public $groupname;
public $groupid;
public $start;
public $end;

// Customised column and header info
public $detailsheader;
Expand All @@ -210,7 +208,7 @@ class oublog_user_participation_table extends flexible_table {
public $comments;

public function __construct($cmid, $course, $oublog, $userid, $userfullname,
$groupname, $groupid, $start, $end) {
$groupname, $groupid) {

$this->cmid = $cmid;
$this->course = $course;
Expand All @@ -219,13 +217,11 @@ public function __construct($cmid, $course, $oublog, $userid, $userfullname,
$this->userfullname = $userfullname;
$this->groupname = $groupname;
$this->groupid = $groupid;
$this->start = $start;
$this->end = $end;
parent::__construct('mod-oublog-user-participation');
}

public function setup($download = '') {
global $CFG;
global $CFG, $PAGE;

// Extra headers
$this->postsheader = array(
Expand Down Expand Up @@ -267,9 +263,7 @@ public function setup($download = '') {

$this->define_columns($columns);
$this->define_headers($headers);
$this->define_baseurl($CFG->wwwroot . '/mod/oublog/userparticipation.php?id=' .
$this->cmid . '&amp;user=' . $this->userid . '&amp;group=' . $this->groupid .
'&amp;start=' . $this->start .'&amp;end=' . $this->end);
$this->define_baseurl($PAGE->url);

$this->set_attribute('cellspacing', '0');
$this->set_attribute('id', 'participation');
Expand Down Expand Up @@ -302,7 +296,7 @@ public function download_buttons() {
$downloadoptions = $this->get_download_menu();
$html = '<form action="'. $this->baseurl .'" method="post">';
$html .= '<div class="mdl-align">';
$html .= '<input type="submit" value="'.get_string('downloadas', 'oublog').'"/>';
$html .= '<input type="submit" value="'.get_string('downloadas', 'oublog').'"/> ';
$html .= html_writer::select($downloadoptions, 'download',
$this->defaultdownloadformat, false);
$html .= '</div></form>';
Expand Down
36 changes: 17 additions & 19 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public function render_participation_list($cm, $course, $oublog, $groupid,
* @param string groupname group name for display, default ''
*/
public function render_user_participation_list($cm, $course, $oublog, $participation, $groupid,
$download, $page, $context, $viewfullnames, $groupname, $start, $end) {
$download, $page, $context, $viewfullnames, $groupname) {
global $DB, $CFG;

$user = $participation->user;
Expand All @@ -541,18 +541,16 @@ public function render_user_participation_list($cm, $course, $oublog, $participa
}
$filename .= '-'.format_string($fullname, true);
$table = new oublog_user_participation_table($cm->id, $course, $oublog,
$user->id, $fullname, $groupname, $groupid, $start, $end);
$user->id, $fullname, $groupname, $groupid);
$table->setup($download);
$table->is_downloading($download, $filename, get_string('participation', 'oublog'));

// Print standard output.
$output = '';
$modcontext = context_module::instance($cm->id);
if (!$table->is_downloading()) {
$output .= html_writer::tag('h2', get_string('postsby', 'oublog', $fullname));
if (!$participation->posts) {
$output .= html_writer::tag('p', get_string('nouserposts', 'oublog'));
} else {
if ($participation->posts) {
$output .= html_writer::tag('h2', get_string('postsby', 'oublog', $fullname));
$counter = 0;
foreach ($participation->posts as $post) {
$row = ($counter % 2) ? 'oublog-odd' : 'oublog-even';
Expand Down Expand Up @@ -617,36 +615,34 @@ public function render_user_participation_list($cm, $course, $oublog, $participa
}
}

$output .= html_writer::tag('h2', get_string('commentsby', 'oublog', $fullname));
if (!$participation->comments) {
$output .= html_writer::tag('p', get_string('nousercomments', 'oublog'));
} else {
if ($participation->comments) {
$output .= html_writer::tag('h2', get_string('commentsby', 'oublog', $fullname));
$output .= html_writer::start_tag('div',
array('id' => 'oublogcomments', 'class' => 'oublog-post-comments oublogpartcomments'));
foreach ($participation->comments as $comment) {
$output .= html_writer::start_tag('div', array('class'=>'oublog-comment'));

$author = new StdClass;
$author = new stdClass();
$author->id = $comment->authorid;
$userfields = get_all_user_name_fields();
foreach ($userfields as $field) {
$author->$field = $comment->$field;
$userfields = get_all_user_name_fields(false, '', 'poster');
foreach ($userfields as $field => $retfield) {
$author->$field = $comment->$retfield;
}
$authorurl = new moodle_url('/user/view.php', array('id' => $author->id));
$authorlink = html_writer::link($authorurl, fullname($author, $viewfullnames));
if (isset($comment->posttitle) && !empty($comment->posttitle)) {
$viewposturl = new moodle_url('/mod/oublog/viewpost.php',
array('post' => $comment->postid));
$viewpostlink = html_writer::link($viewposturl, s($comment->posttitle));
$strparams = array('title' => $viewpostlink, 'author' => $authorlink);
$strparams = array('title' => $viewpostlink, 'author' => $authorlink, 'date' => oublog_date($comment->postdate));
$output .= html_writer::tag('h3', get_string('commentonby', 'oublog',
$strparams));
} else {
$viewposturl = new moodle_url('/mod/oublog/viewpost.php',
array('post' => $comment->postid));
$viewpostlink = html_writer::link($viewposturl,
oublog_date($comment->postdate));
$strparams = array('title' => $viewpostlink, 'author' => $authorlink);
$strparams = array('title' => $viewpostlink, 'author' => $authorlink, 'date' => '');
$output .= html_writer::tag('h3', get_string('commentonby', 'oublog',
$strparams));
}
Expand Down Expand Up @@ -675,8 +671,10 @@ public function render_user_participation_list($cm, $course, $oublog, $participa
}
$output .= html_writer::end_tag('div');
}
// Only printing the download buttons.
echo $table->download_buttons();
if (!empty($participation->posts) || !empty($participation->comments)) {
// Only printing the download buttons.
echo $table->download_buttons();
}

// Print the actual output.
echo $output;
Expand Down Expand Up @@ -721,7 +719,7 @@ public function render_user_participation_list($cm, $course, $oublog, $participa
$table->add_data($table->comments);
$table->add_data($table->commentsheader);
foreach ($participation->comments as $comment) {
$author = new StdClass;
$author = new stdClass();
$author->id = $comment->authorid;
$userfields = get_all_user_name_fields();
foreach ($userfields as $field) {
Expand Down
6 changes: 6 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ div.oublog-individualselector {
margin-top: 1em;
}

#page-mod-oublog-userparticipation .oublog-comment-date {
font-size: 1em;
}
#page-mod-oublog-userparticipation .tabtree {
margin-top: 1.25em;
}
#oublogbuttons form,
#oublogbuttons div {
display: inline;
Expand Down
13 changes: 12 additions & 1 deletion tests/participation_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ public function test_participation() {
null, (time() + 3600));
$this->assertCount(2, $userparticipation->posts);
$this->assertCount(2, $userparticipation->comments);
// Test oublog_get_user_participation() filtering.
$userparticipation = oublog_get_user_participation($oublog, $context, $student1->id, 0, $cm, $course,
null, null, true, false, null, 1);
$this->assertCount(1, $userparticipation->posts);
$this->assertCount(0, $userparticipation->comments);
$userparticipation = oublog_get_user_participation($oublog, $context, $student1->id, 0, $cm, $course,
null, null, false, true);
$this->assertCount(0, $userparticipation->posts);
$this->assertCount(2, $userparticipation->comments);

// Test deleted posts/comments don't show.
$DB->update_record('oublog_posts', (object) array('id' => $post1, 'timedeleted' => time(), 'deletedby' => $USER->id));
$DB->update_record('oublog_comments', (object) array('id' => $comment, 'timedeleted' => time(), 'deletedby' => $USER->id));
Expand Down Expand Up @@ -364,7 +374,8 @@ public function test_participation_grades() {
$this->assertNotEmpty($participation[$student1->id]->gradeobj);
$this->assertEquals(55, $participation[$student1->id]->gradeobj->grade);

$userparticipation = oublog_get_user_participation($oublog, $context, $student1->id, 0, $cm, $course);
$userparticipation = oublog_get_user_participation($oublog, $context, $student1->id, 0, $cm, $course,
null, null, true, true, null, null, true);
$this->assertTrue(isset($userparticipation->gradeobj));
$this->assertNotEmpty($userparticipation->gradeobj);
$this->assertEquals(55, $userparticipation->gradeobj->grade);
Expand Down
Loading

0 comments on commit 073a538

Please sign in to comment.