mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-51239 core_blog: coding style fixes
This commit is contained in:
parent
c18acb8997
commit
0e32a56591
8 changed files with 88 additions and 84 deletions
|
@ -132,7 +132,11 @@ 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,
|
||||||
|
'action' => 'delete',
|
||||||
|
'confirm' => 1,
|
||||||
|
'sesskey' => sesskey(),
|
||||||
|
'courseid' => $courseid);
|
||||||
$optionsno = array('userid' => $entry->userid, '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);
|
||||||
|
|
|
@ -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)) {
|
||||||
|
|
20
blog/lib.php
20
blog/lib.php
|
@ -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 {
|
||||||
|
|
|
@ -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));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue