MDL-51239 core_blog: coding style fixes

This commit is contained in:
Andrew Davis 2015-08-28 16:13:26 +08:00
parent c18acb8997
commit 0e32a56591
8 changed files with 88 additions and 84 deletions

View file

@ -132,8 +132,12 @@ if ($action === 'delete') {
redirect($returnurl); redirect($returnurl);
} }
} else if (blog_user_can_edit_entry($entry)) { } else if (blog_user_can_edit_entry($entry)) {
$optionsyes = array('entryid'=>$id, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'courseid'=>$courseid); $optionsyes = array('entryid' => $id,
$optionsno = array('userid'=>$entry->userid, 'courseid'=>$courseid); 'action' => 'delete',
'confirm' => 1,
'sesskey' => sesskey(),
'courseid' => $courseid);
$optionsno = array('userid' => $entry->userid, 'courseid' => $courseid);
$PAGE->set_title("$SITE->shortname: $strblogs"); $PAGE->set_title("$SITE->shortname: $strblogs");
$PAGE->set_heading($SITE->fullname); $PAGE->set_heading($SITE->fullname);
echo $OUTPUT->header(); echo $OUTPUT->header();
@ -181,9 +185,9 @@ if (!empty($entry->id)) {
} }
require_once('edit_form.php'); require_once('edit_form.php');
$summaryoptions = array('maxfiles'=> 99, 'maxbytes'=>$CFG->maxbytes, 'trusttext'=>true, 'context'=>$sitecontext, $summaryoptions = array('maxfiles' => 99, 'maxbytes' => $CFG->maxbytes, 'trusttext' => true, 'context' => $sitecontext,
'subdirs'=>file_area_contains_subdirs($sitecontext, 'blog', 'post', $entry->id)); 'subdirs' => file_area_contains_subdirs($sitecontext, 'blog', 'post', $entry->id));
$attachmentoptions = array('subdirs'=>false, 'maxfiles'=> 99, 'maxbytes'=>$CFG->maxbytes); $attachmentoptions = array('subdirs' => false, 'maxfiles' => 99, 'maxbytes' => $CFG->maxbytes);
$blogeditform = new blog_edit_form(null, compact('entry', $blogeditform = new blog_edit_form(null, compact('entry',
'summaryoptions', 'summaryoptions',

View file

@ -94,7 +94,7 @@ if (!empty($blogs)) {
$editurl = new moodle_url('/blog/external_blog_edit.php', array('id' => $blog->id)); $editurl = new moodle_url('/blog/external_blog_edit.php', array('id' => $blog->id));
$editicon = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('editexternalblog', 'blog'))); $editicon = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('editexternalblog', 'blog')));
$deletelink = new moodle_url('/blog/external_blogs.php', array('delete' => $blog->id, 'sesskey'=>sesskey())); $deletelink = new moodle_url('/blog/external_blogs.php', array('delete' => $blog->id, 'sesskey' => sesskey()));
$deleteicon = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', get_string('deleteexternalblog', 'blog'))); $deleteicon = $OUTPUT->action_icon($deletelink, new pix_icon('t/delete', get_string('deleteexternalblog', 'blog')));
$table->data[] = new html_table_row(array($blog->name, $table->data[] = new html_table_row(array($blog->name,

View file

@ -40,13 +40,13 @@ $search = optional_param('search', null, PARAM_RAW);
comment::init(); comment::init();
$url_params = compact('id', 'start', 'tag', 'userid', 'tagid', 'modid', 'entryid', 'groupid', 'courseid', 'search'); $urlparams = compact('id', 'start', 'tag', 'userid', 'tagid', 'modid', 'entryid', 'groupid', 'courseid', 'search');
foreach ($url_params as $var => $val) { foreach ($urlparams as $var => $val) {
if (empty($val)) { if (empty($val)) {
unset($url_params[$var]); unset($urlparams[$var]);
} }
} }
$PAGE->set_url('/blog/index.php', $url_params); $PAGE->set_url('/blog/index.php', $urlparams);
// Correct tagid if a text tag is provided as a param. // Correct tagid if a text tag is provided as a param.
if (!empty($tag)) { if (!empty($tag)) {
@ -121,7 +121,7 @@ if (!empty($groupid) && empty($courseid)) {
if (!$userid && has_capability('moodle/blog:view', $sitecontext) && $CFG->bloglevel > BLOG_USER_LEVEL) { if (!$userid && has_capability('moodle/blog:view', $sitecontext) && $CFG->bloglevel > BLOG_USER_LEVEL) {
if ($entryid) { if ($entryid) {
if (!$entryobject = $DB->get_record('post', array('id'=>$entryid))) { if (!$entryobject = $DB->get_record('post', array('id' => $entryid))) {
print_error('nosuchentry', 'blog'); print_error('nosuchentry', 'blog');
} }
$userid = $entryobject->userid; $userid = $entryobject->userid;
@ -148,12 +148,12 @@ if ((empty($courseid) ? true : $courseid == SITEID) && empty($userid)) {
print_error('cannotviewsiteblog', 'blog'); print_error('cannotviewsiteblog', 'blog');
} }
$COURSE = $DB->get_record('course', array('format'=>'site')); $COURSE = $DB->get_record('course', array('format' => 'site'));
$courseid = $COURSE->id; $courseid = $COURSE->id;
} }
if (!empty($courseid)) { if (!empty($courseid)) {
if (!$course = $DB->get_record('course', array('id'=>$courseid))) { if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourseid'); print_error('invalidcourseid');
} }
@ -176,7 +176,7 @@ if (!empty($groupid)) {
print_error(get_string('invalidgroupid', 'blog')); print_error(get_string('invalidgroupid', 'blog'));
} }
if (!$course = $DB->get_record('course', array('id'=>$group->courseid))) { if (!$course = $DB->get_record('course', array('id' => $group->courseid))) {
print_error('invalidcourseid'); print_error('invalidcourseid');
} }
@ -200,7 +200,7 @@ if (!empty($userid)) {
print_error('blogdisable', 'blog'); print_error('blogdisable', 'blog');
} }
if (!$user = $DB->get_record('user', array('id'=>$userid))) { if (!$user = $DB->get_record('user', array('id' => $userid))) {
print_error('invaliduserid'); print_error('invaliduserid');
} }

View file

@ -332,9 +332,9 @@ function blog_get_all_options(moodle_page $page, stdClass $userid = null) {
$userid = $page->context->instanceid; $userid = $page->context->instanceid;
} }
// Check the userid var. // Check the userid var.
if (!is_null($userid) && $userid!==$USER->id) { if (!is_null($userid) && $userid !== $USER->id) {
// Load the user from the userid... it MUST EXIST throw a wobbly if it doesn't! // Load the user from the userid... it MUST EXIST throw a wobbly if it doesn't!
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST); $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
} else { } else {
$user = null; $user = null;
} }
@ -350,7 +350,7 @@ function blog_get_all_options(moodle_page $page, stdClass $userid = null) {
// Get the options for the user. // Get the options for the user.
if ($user !== null and !isguestuser($user)) { if ($user !== null and !isguestuser($user)) {
// Load for the requested user. // Load for the requested user.
$options[CONTEXT_USER+1] = blog_get_options_for_user($user); $options[CONTEXT_USER + 1] = blog_get_options_for_user($user);
} }
// Load for the current user. // Load for the current user.
if (isloggedin() and !isguestuser()) { if (isloggedin() and !isguestuser()) {
@ -413,7 +413,7 @@ function blog_get_options_for_user(stdClass $user=null) {
// Not the current user, but we can view and its blogs are enabled for SITE or GLOBAL. // Not the current user, but we can view and its blogs are enabled for SITE or GLOBAL.
$options['userentries'] = array( $options['userentries'] = array(
'string' => get_string('viewuserentries', 'blog', fullname($user)), 'string' => get_string('viewuserentries', 'blog', fullname($user)),
'link' => new moodle_url('/blog/index.php', array('userid'=>$user->id)) 'link' => new moodle_url('/blog/index.php', array('userid' => $user->id))
); );
} else { } else {
// It's the current user. // It's the current user.
@ -421,14 +421,14 @@ function blog_get_options_for_user(stdClass $user=null) {
// We can view our own blogs .... BIG surprise. // We can view our own blogs .... BIG surprise.
$options['view'] = array( $options['view'] = array(
'string' => get_string('blogentries', 'blog'), 'string' => get_string('blogentries', 'blog'),
'link' => new moodle_url('/blog/index.php', array('userid'=>$USER->id)) 'link' => new moodle_url('/blog/index.php', array('userid' => $USER->id))
); );
} }
if (has_capability('moodle/blog:create', $sitecontext)) { if (has_capability('moodle/blog:create', $sitecontext)) {
// We can add to our own blog. // We can add to our own blog.
$options['add'] = array( $options['add'] = array(
'string' => get_string('addnewentry', 'blog'), 'string' => get_string('addnewentry', 'blog'),
'link' => new moodle_url('/blog/edit.php', array('action'=>'add')) 'link' => new moodle_url('/blog/edit.php', array('action' => 'add'))
); );
} }
} }
@ -560,13 +560,13 @@ function blog_get_options_for_module($module, $user=null) {
$a->type = $modulename; $a->type = $modulename;
$options['moduleview'] = array( $options['moduleview'] = array(
'string' => get_string('viewallmodentries', 'blog', $a), 'string' => get_string('viewallmodentries', 'blog', $a),
'link' => new moodle_url('/blog/index.php', array('modid'=>$module->id)) 'link' => new moodle_url('/blog/index.php', array('modid' => $module->id))
); );
} }
// View MY entries about this module. // View MY entries about this module.
$options['moduleviewmine'] = array( $options['moduleviewmine'] = array(
'string' => get_string('viewmyentriesaboutmodule', 'blog', $modulename), 'string' => get_string('viewmyentriesaboutmodule', 'blog', $modulename),
'link' => new moodle_url('/blog/index.php', array('modid'=>$module->id, 'userid'=>$USER->id)) 'link' => new moodle_url('/blog/index.php', array('modid' => $module->id, 'userid' => $USER->id))
); );
if (!empty($user) && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) { if (!empty($user) && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) {
// View the given users entries about this module. // View the given users entries about this module.
@ -575,7 +575,7 @@ function blog_get_options_for_module($module, $user=null) {
$a->user = fullname($user); $a->user = fullname($user);
$options['moduleviewuser'] = array( $options['moduleviewuser'] = array(
'string' => get_string('blogentriesbyuseraboutmodule', 'blog', $a), 'string' => get_string('blogentriesbyuseraboutmodule', 'blog', $a),
'link' => new moodle_url('/blog/index.php', array('modid'=>$module->id, 'userid'=>$user->id)) 'link' => new moodle_url('/blog/index.php', array('modid' => $module->id, 'userid' => $user->id))
); );
} }
} }
@ -584,7 +584,7 @@ function blog_get_options_for_module($module, $user=null) {
// The user can blog about this module. // The user can blog about this module.
$options['moduleadd'] = array( $options['moduleadd'] = array(
'string' => get_string('blogaboutthismodule', 'blog', $modulename), 'string' => get_string('blogaboutthismodule', 'blog', $modulename),
'link' => new moodle_url('/blog/edit.php', array('action'=>'add', 'modid'=>$module->id)) 'link' => new moodle_url('/blog/edit.php', array('action' => 'add', 'modid' => $module->id))
); );
} }
// Cache the options. // Cache the options.
@ -673,7 +673,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
$headers['filters']['module'] = $modid; $headers['filters']['module'] = $modid;
// A groupid param may conflict with this coursemod's courseid. Ignore groupid in that case. // A groupid param may conflict with this coursemod's courseid. Ignore groupid in that case.
$courseid = $DB->get_field('course_modules', 'course', array('id'=>$modid)); $courseid = $DB->get_field('course_modules', 'course', array('id' => $modid));
$course = $DB->get_record('course', array('id' => $courseid)); $course = $DB->get_record('course', array('id' => $courseid));
$cm = $DB->get_record('course_modules', array('id' => $modid)); $cm = $DB->get_record('course_modules', array('id' => $modid));
$cm->modname = $DB->get_field('modules', 'name', array('id' => $cm->module)); $cm->modname = $DB->get_field('modules', 'name', array('id' => $cm->module));
@ -861,7 +861,7 @@ function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=nu
if (!empty($tagid)) { if (!empty($tagid)) {
$headers['filters']['tag'] = $tagid; $headers['filters']['tag'] = $tagid;
$blogurl->param('tagid', $tagid); $blogurl->param('tagid', $tagid);
$tagrec = $DB->get_record('tag', array('id'=>$tagid)); $tagrec = $DB->get_record('tag', array('id' => $tagid));
$PAGE->navbar->add($tagrec->name, $blogurl); $PAGE->navbar->add($tagrec->name, $blogurl);
} else if (!empty($tag)) { } else if (!empty($tag)) {
if ($tagrec = $DB->get_record('tag', array('name' => $tag))) { if ($tagrec = $DB->get_record('tag', array('name' => $tag))) {
@ -921,7 +921,7 @@ function blog_get_associated_count($courseid, $cmid=null) {
* @package core_blog * @package core_blog
* @category comment * @category comment
* *
* @param stdClass $comment_param { * @param stdClass $commentparam {
* context => context the context object * context => context the context object
* courseid => int course id * courseid => int course id
* cm => stdClass course module object * cm => stdClass course module object
@ -930,11 +930,11 @@ function blog_get_associated_count($courseid, $cmid=null) {
* } * }
* @return array * @return array
*/ */
function blog_comment_permissions($comment_param) { function blog_comment_permissions($commentparam) {
global $DB; global $DB;
// If blog is public and current user is guest, then don't let him post comments. // If blog is public and current user is guest, then don't let him post comments.
$blogentry = $DB->get_record('post', array('id' => $comment_param->itemid), 'publishstate', MUST_EXIST); $blogentry = $DB->get_record('post', array('id' => $commentparam->itemid), 'publishstate', MUST_EXIST);
if ($blogentry->publishstate != 'public') { if ($blogentry->publishstate != 'public') {
if (!isloggedin() || isguestuser()) { if (!isloggedin() || isguestuser()) {
@ -959,7 +959,7 @@ function blog_comment_permissions($comment_param) {
* } * }
* @return boolean * @return boolean
*/ */
function blog_comment_validate($comment_param) { function blog_comment_validate($commentparam) {
global $CFG, $DB, $USER; global $CFG, $DB, $USER;
// Check if blogs are enabled user can comment. // Check if blogs are enabled user can comment.
@ -968,22 +968,22 @@ function blog_comment_validate($comment_param) {
} }
// Validate comment area. // Validate comment area.
if ($comment_param->commentarea != 'format_blog') { if ($commentparam->commentarea != 'format_blog') {
throw new comment_exception('invalidcommentarea'); throw new comment_exception('invalidcommentarea');
} }
$blogentry = $DB->get_record('post', array('id' => $comment_param->itemid), '*', MUST_EXIST); $blogentry = $DB->get_record('post', array('id' => $commentparam->itemid), '*', MUST_EXIST);
// Validation for comment deletion. // Validation for comment deletion.
if (!empty($comment_param->commentid)) { if (!empty($commentparam->commentid)) {
if ($record = $DB->get_record('comments', array('id'=>$comment_param->commentid))) { if ($record = $DB->get_record('comments', array('id' => $commentparam->commentid))) {
if ($record->commentarea != 'format_blog') { if ($record->commentarea != 'format_blog') {
throw new comment_exception('invalidcommentarea'); throw new comment_exception('invalidcommentarea');
} }
if ($record->contextid != $comment_param->context->id) { if ($record->contextid != $commentparam->context->id) {
throw new comment_exception('invalidcontext'); throw new comment_exception('invalidcontext');
} }
if ($record->itemid != $comment_param->itemid) { if ($record->itemid != $commentparam->itemid) {
throw new comment_exception('invalidcommentitemid'); throw new comment_exception('invalidcommentitemid');
} }
} else { } else {
@ -1005,10 +1005,10 @@ function blog_comment_validate($comment_param) {
*/ */
function blog_page_type_list($pagetype, $parentcontext, $currentcontext) { function blog_page_type_list($pagetype, $parentcontext, $currentcontext) {
return array( return array(
'*'=>get_string('page-x', 'pagetype'), '*' => get_string('page-x', 'pagetype'),
'blog-*'=>get_string('page-blog-x', 'blog'), 'blog-*' => get_string('page-blog-x', 'blog'),
'blog-index'=>get_string('page-blog-index', 'blog'), 'blog-index' => get_string('page-blog-index', 'blog'),
'blog-edit'=>get_string('page-blog-edit', 'blog') 'blog-edit' => get_string('page-blog-edit', 'blog')
); );
} }

View file

@ -112,7 +112,7 @@ class blog_entry implements renderable {
$this->renderable = new StdClass(); $this->renderable = new StdClass();
$this->renderable->user = $DB->get_record('user', array('id'=>$this->userid)); $this->renderable->user = $DB->get_record('user', array('id' => $this->userid));
// Entry comments. // Entry comments.
if (!empty($CFG->usecomments) and $CFG->blogusecomments) { if (!empty($CFG->usecomments) and $CFG->blogusecomments) {

View file

@ -35,7 +35,7 @@ require_once($CFG->dirroot .'/blog/lib.php');
* @param int $tagid The id of the row in the tag table that identifies the RSS Feed * @param int $tagid The id of the row in the tag table that identifies the RSS Feed
* @return string * @return string
*/ */
function blog_rss_get_url($contextid, $userid, $filtertype, $filterselect=0, $tagid=0) { function blog_rss_get_url($contextid, $userid, $filtertype, $filterselect=0, $tagid =0) {
$componentname = 'blog'; $componentname = 'blog';
$additionalargs = null; $additionalargs = null;
@ -70,7 +70,7 @@ function blog_rss_get_url($contextid, $userid, $filtertype, $filterselect=0, $ta
* @param int $tagid The id of the row in the tag table that identifies the RSS Feed * @param int $tagid The id of the row in the tag table that identifies the RSS Feed
* @param string $tooltiptext The tooltip to be displayed with the link * @param string $tooltiptext The tooltip to be displayed with the link
*/ */
function blog_rss_print_link($context, $filtertype, $filterselect=0, $tagid=0, $tooltiptext='') { function blog_rss_print_link($context, $filtertype, $filterselect=0, $tagid =0, $tooltiptext='') {
global $CFG, $USER, $OUTPUT; global $CFG, $USER, $OUTPUT;
if (!isloggedin()) { if (!isloggedin()) {
@ -93,7 +93,7 @@ function blog_rss_print_link($context, $filtertype, $filterselect=0, $tagid=0, $
* @param int $filterselect The id of the item defined by $filtertype * @param int $filterselect The id of the item defined by $filtertype
* @param int $tagid The id of the row in the tag table that identifies the RSS Feed * @param int $tagid The id of the row in the tag table that identifies the RSS Feed
*/ */
function blog_rss_add_http_header($context, $title, $filtertype, $filterselect=0, $tagid=0) { function blog_rss_add_http_header($context, $title, $filtertype, $filterselect=0, $tagid =0) {
global $PAGE, $USER, $CFG; global $PAGE, $USER, $CFG;
if (!isloggedin()) { if (!isloggedin()) {
@ -168,7 +168,7 @@ function blog_rss_get_feed($context, $args) {
$type = clean_param($args[3], PARAM_ALPHA); $type = clean_param($args[3], PARAM_ALPHA);
$id = clean_param($args[4], PARAM_INT); // Could be groupid / courseid / userid depending on $type. $id = clean_param($args[4], PARAM_INT); // Could be groupid / courseid / userid depending on $type.
$tagid=0; $tagid = 0;
if ($args[5] != 'rss.xml') { if ($args[5] != 'rss.xml') {
$tagid = clean_param($args[5], PARAM_INT); $tagid = clean_param($args[5], PARAM_INT);
} else { } else {
@ -234,10 +234,10 @@ function blog_rss_get_feed($context, $args) {
switch ($type) { switch ($type) {
case 'user': case 'user':
$info = fullname($DB->get_record('user', array('id'=>$id), 'firstname,lastname')); $info = fullname($DB->get_record('user', array('id' => $id), 'firstname,lastname'));
break; break;
case 'course': case 'course':
$info = $DB->get_field('course', 'fullname', array('id'=>$id)); $info = $DB->get_field('course', 'fullname', array('id' => $id));
$info = format_string($info, true, array('context' => context_course::instance($id))); $info = format_string($info, true, array('context' => context_course::instance($id)));
break; break;
case 'site': case 'site':
@ -245,7 +245,7 @@ function blog_rss_get_feed($context, $args) {
break; break;
case 'group': case 'group':
$group = groups_get_group($id); $group = groups_get_group($id);
$info = $group->name; // TODO: $DB->get_field('groups', 'name', array('id'=>$id)). $info = $group->name; // TODO: $DB->get_field('groups', 'name', array('id' => $id)).
break; break;
default: default:
$info = ''; $info = '';
@ -253,7 +253,7 @@ function blog_rss_get_feed($context, $args) {
} }
if ($tagid) { if ($tagid) {
$info .= ': '.$DB->get_field('tags', 'text', array('id'=>$tagid)); $info .= ': '.$DB->get_field('tags', 'text', array('id' => $tagid));
} }
$header = rss_standard_header(get_string($type.'blog', 'blog', $info), $header = rss_standard_header(get_string($type.'blog', 'blog', $info),
@ -279,7 +279,7 @@ function blog_rss_get_feed($context, $args) {
* @param int $tagid The id of the row in the tag table that identifies the RSS Feed * @param int $tagid The id of the row in the tag table that identifies the RSS Feed
* @return string * @return string
*/ */
function blog_rss_file_name($type, $id, $tagid=0) { function blog_rss_file_name($type, $id, $tagid =0) {
global $CFG; global $CFG;
if ($tagid) { if ($tagid) {
@ -298,7 +298,7 @@ function blog_rss_file_name($type, $id, $tagid=0) {
* @param string $contents The contents of the RSS Feed file * @param string $contents The contents of the RSS Feed file
* @return bool whether the save was successful or not * @return bool whether the save was successful or not
*/ */
function blog_rss_save_file($type, $id, $tagid=0, $contents='') { function blog_rss_save_file($type, $id, $tagid =0, $contents='') {
global $CFG; global $CFG;
$status = true; $status = true;

View file

@ -46,9 +46,9 @@ class core_bloglib_testcase extends advanced_testcase {
$this->resetAfterTest(); $this->resetAfterTest();
// Create default course. // Create default course.
$course = $this->getDataGenerator()->create_course(array('category'=>1, 'shortname'=>'ANON')); $course = $this->getDataGenerator()->create_course(array('category' => 1, 'shortname' => 'ANON'));
$this->assertNotEmpty($course); $this->assertNotEmpty($course);
$page = $this->getDataGenerator()->create_module('page', array('course'=>$course->id)); $page = $this->getDataGenerator()->create_module('page', array('course' => $course->id));
$this->assertNotEmpty($page); $this->assertNotEmpty($page);
// Create default group. // Create default group.
@ -58,7 +58,7 @@ class core_bloglib_testcase extends advanced_testcase {
$group->id = $DB->insert_record('groups', $group); $group->id = $DB->insert_record('groups', $group);
// Create default user. // Create default user.
$user = $this->getDataGenerator()->create_user(array('username'=>'testuser', 'firstname'=>'Jimmy', 'lastname'=>'Kinnon')); $user = $this->getDataGenerator()->create_user(array('username' => 'testuser', 'firstname' => 'Jimmy', 'lastname' => 'Kinnon'));
// Create default tag. // Create default tag.
$tag = new stdClass(); $tag = new stdClass();
@ -91,35 +91,35 @@ class core_bloglib_testcase extends advanced_testcase {
// Try all the filters at once: Only the entry filter is active. // Try all the filters at once: Only the entry filter is active.
$filters = array('site' => $SITE->id, 'course' => $this->courseid, 'module' => $this->cmid, $filters = array('site' => $SITE->id, 'course' => $this->courseid, 'module' => $this->cmid,
'group' => $this->groupid, 'user' => $this->userid, 'tag' => $this->tagid, 'entry' => $this->postid); 'group' => $this->groupid, 'user' => $this->userid, 'tag' => $this->tagid, 'entry' => $this->postid);
$blog_listing = new blog_listing($filters); $bloglisting = new blog_listing($filters);
$this->assertFalse(array_key_exists('site', $blog_listing->filters)); $this->assertFalse(array_key_exists('site', $bloglisting->filters));
$this->assertFalse(array_key_exists('course', $blog_listing->filters)); $this->assertFalse(array_key_exists('course', $bloglisting->filters));
$this->assertFalse(array_key_exists('module', $blog_listing->filters)); $this->assertFalse(array_key_exists('module', $bloglisting->filters));
$this->assertFalse(array_key_exists('group', $blog_listing->filters)); $this->assertFalse(array_key_exists('group', $bloglisting->filters));
$this->assertFalse(array_key_exists('user', $blog_listing->filters)); $this->assertFalse(array_key_exists('user', $bloglisting->filters));
$this->assertFalse(array_key_exists('tag', $blog_listing->filters)); $this->assertFalse(array_key_exists('tag', $bloglisting->filters));
$this->assertTrue(array_key_exists('entry', $blog_listing->filters)); $this->assertTrue(array_key_exists('entry', $bloglisting->filters));
// Again, but without the entry filter: This time, the tag, user and module filters are active. // Again, but without the entry filter: This time, the tag, user and module filters are active.
$filters = array('site' => $SITE->id, 'course' => $this->courseid, 'module' => $this->cmid, $filters = array('site' => $SITE->id, 'course' => $this->courseid, 'module' => $this->cmid,
'group' => $this->groupid, 'user' => $this->userid, 'tag' => $this->postid); 'group' => $this->groupid, 'user' => $this->userid, 'tag' => $this->postid);
$blog_listing = new blog_listing($filters); $bloglisting = new blog_listing($filters);
$this->assertFalse(array_key_exists('site', $blog_listing->filters)); $this->assertFalse(array_key_exists('site', $bloglisting->filters));
$this->assertFalse(array_key_exists('course', $blog_listing->filters)); $this->assertFalse(array_key_exists('course', $bloglisting->filters));
$this->assertFalse(array_key_exists('group', $blog_listing->filters)); $this->assertFalse(array_key_exists('group', $bloglisting->filters));
$this->assertTrue(array_key_exists('module', $blog_listing->filters)); $this->assertTrue(array_key_exists('module', $bloglisting->filters));
$this->assertTrue(array_key_exists('user', $blog_listing->filters)); $this->assertTrue(array_key_exists('user', $bloglisting->filters));
$this->assertTrue(array_key_exists('tag', $blog_listing->filters)); $this->assertTrue(array_key_exists('tag', $bloglisting->filters));
// We should get the same result by removing the 3 inactive filters: site, course and group. // We should get the same result by removing the 3 inactive filters: site, course and group.
$filters = array('module' => $this->cmid, 'user' => $this->userid, 'tag' => $this->tagid); $filters = array('module' => $this->cmid, 'user' => $this->userid, 'tag' => $this->tagid);
$blog_listing = new blog_listing($filters); $bloglisting = new blog_listing($filters);
$this->assertFalse(array_key_exists('site', $blog_listing->filters)); $this->assertFalse(array_key_exists('site', $bloglisting->filters));
$this->assertFalse(array_key_exists('course', $blog_listing->filters)); $this->assertFalse(array_key_exists('course', $bloglisting->filters));
$this->assertFalse(array_key_exists('group', $blog_listing->filters)); $this->assertFalse(array_key_exists('group', $bloglisting->filters));
$this->assertTrue(array_key_exists('module', $blog_listing->filters)); $this->assertTrue(array_key_exists('module', $bloglisting->filters));
$this->assertTrue(array_key_exists('user', $blog_listing->filters)); $this->assertTrue(array_key_exists('user', $bloglisting->filters));
$this->assertTrue(array_key_exists('tag', $blog_listing->filters)); $this->assertTrue(array_key_exists('tag', $bloglisting->filters));
} }