Skip to content

Commit

Permalink
Comments development
Browse files Browse the repository at this point in the history
  • Loading branch information
drachels committed Apr 10, 2022
1 parent e0bcef8 commit 2805f53
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 353 deletions.
6 changes: 3 additions & 3 deletions classes/event/comment_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @copyright 2013 Rajesh Taneja <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comment_deleted extends \core\event\comment_deleted {
class comment_created extends \core\event\comment_created {
/**
* Get URL related to the action.
*
Expand All @@ -49,7 +49,7 @@ public function get_url() {
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' created the comment with id '$this->objectid' from the hotquestion activity with " .
"course module id '$this->contextinstanceid'.";
return "The user with id '$this->userid' created the comment with id '$this->objectid' from the hotquestion " .
"activity with course module id '$this->contextinstanceid'.";
}
}
68 changes: 4 additions & 64 deletions classes/local/results.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,35 +277,11 @@ public static function hotquestion_get_question_comment_count($question, $cm, $c
// 20210313 Not in use yet. Part of future development.
global $DB;

$debug['In results.php CP8a entering function hotquestion_get_question_comment_count $question: '] = $question;
$debug['In results.php CP8b showing $cm: '] = $cm;
$debug['In results.php CP8c showing $course: '] = $course;

//$context = context_module::instance($cm->id);

//$debug['In results.php CP8d showing $context: '] = $context;
$debug['In results.php CP8d showing itemid: '] = $question->id;
$debug['In results.php CP8d showing commentarea: '] = 'hotquestion_questions';
//$debug['In results.php CP8d showing $context->id: '] = $context->id;


$debug['In results.php CP8DB showing $DB->count_records: '] = ($DB->count_records('comments', array('itemid' => $question->id,
'commentarea' => 'hotquestion_questions',
'contextid' => $cm->id))) ;


if ($count = $DB->count_records('comments', array('itemid' => $question->id,
'commentarea' => 'hotquestion_questions',
'contextid' => $cm->id))) {
$debug['In results.php CP8e showing $count: '] = $count;
print_object($debug);

return $count;
} else {
$debug['In results.php CP8f showing $count: '] = $count;

print_object($debug);

return 0;
}
}
Expand All @@ -322,11 +298,9 @@ public static function hotquestion_display_question_comments($question, $cm, $co
// 20210313 Not in use yet. Part of future development.
global $CFG, $USER, $OUTPUT, $DB;
$html = '';

if ($question->approved) {
if (($question->approved) || (has_capability('mod/hotquestion:manageentries', $context))) {
// Get question comments and display the comment box.
$context = context_module::instance($cm->id);
//require_once($CFG->dirroot.'/comment/lib.php');
$cmt = new stdClass();
$cmt->component = 'mod_hotquestion';
$cmt->context = $context;
Expand All @@ -336,44 +310,11 @@ public static function hotquestion_display_question_comments($question, $cm, $co
$cmt->itemid = $question->id;
$cmt->showcount = true;
$comment = new comment($cmt);

$debug['In results.php tracking comments dev cp 6data showing $course->id: '] = $course->id;
$debug['In results.php tracking comments dev cp 6data showing $cmt->component: '] = $cmt->component;
$debug['In results.php tracking comments dev cp 6data showing $cmt->context: '] = $cmt->context;
$debug['In results.php tracking comments dev cp 6data showing $cmt->course: '] = $cmt->course;
$debug['In results.php tracking comments dev cp 6data showing $cmt->cm: '] = $cmt->cm;
$debug['In results.php tracking comments dev cp 6data showing $cmt->area: '] = $cmt->area;
$debug['In results.php tracking comments dev cp 6data showing $cmt->itemid: '] = $cmt->itemid;

// 20220215 All three of these show the comment interface, but it is non-responsive, at the moment.
//$html = html_writer::tag('div', $comment->output(true), array('class' => 'hotquestion-comments'));
$html = $comment->output(true);
// This third one, shows the comment in the wrong place. Still non-responsive.
//$html = $comment->output(false);


//$debug['In results.php tracking comments dev cp 6A showing $cmt: '] = $cmt;
//$debug['In results.php tracking comments dev cp 6A showing $html: '] = $html;


// 20220216 Thought about putting comments_viewed event here, but changed my mind.
// When this is excuted you are NOT viewing the comments.
// The interface is on the page, but it is closed and you cannot read any comments.


} else {
//$html = html_writer::tag('div', get_string("nocommentuntilapproved", "pcast"), array('class' => 'pcast-episode-notice'));
$html = html_writer::tag('div', get_string("nocommentuntilapproved", "hotquestion"));
//print_object('///////////////////////////////////////////////////////////////////////////////////////');

$debug['In results.php tracking comments dev cp 6B showing $html: '] = $html;

}

$debug['In results.php tracking comments dev cp 6C showing $html: '] = $html;
//print_object($debug);
$html = html_writer::tag('div', get_string("nocommentuntilapproved", "hotquestion"));
}
return $html;
//return $comment;
}

/**
Expand All @@ -397,7 +338,7 @@ public static function hotquestion_comment_permissions($commentparam) {
return array('ask' => true, 'view' => true);
}

/**
/**
* Return the editor and attachment options when creating a Hot Question question.
*
* @param stdClass $course Course object.
Expand Down Expand Up @@ -456,7 +397,6 @@ public static function add_new_question($fromform) {
// If approval is required, then mark as not approved so only teachers can see it.
$data->approved = 0;
}
// ...$context = context_module::instance($this->cm->id);...
$context = context_module::instance($fromform->cm->id);
// If marked anonymous and anonymous is allowed then change from actual userid to guest.
if (isset($fromform->anonymous) && $fromform->anonymous && $fromform->instance->anonymouspost) {
Expand Down
5 changes: 0 additions & 5 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,6 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
$DB->delete_records_select('hotquestion_votes', "id $isql AND userid = :userid", $params);
$params = ['instanceid' => $cm->instance, 'userid' => $userid];
$DB->delete_records_select('hotquestion_questions', 'hotquestion = :instanceid AND userid = :userid', $params);



//$DB->delete_records('hotquestion_questions', ['hotquestion' => $instanceid, 'userid' => $userid]);
//$DB->delete_records('hotquestion_votes', ['voter' => $userid]);
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
$capabilities = array(

'mod/hotquestion:manageentries' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
Expand Down Expand Up @@ -115,7 +114,6 @@
)
),
'mod/hotquestion:rate' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
Expand All @@ -127,7 +125,6 @@
'mod/hotquestion:comment' => array(

'riskbitmask' => RISK_SPAM,

'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
Expand Down
4 changes: 2 additions & 2 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function xmldb_hotquestion_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2020121700, 'hotquestion');
}

if ($oldversion < 2022021500) {
if ($oldversion < 2022041000) {

// Define field scale to be added to hotquestion.
$table = new xmldb_table('hotquestion');
Expand Down Expand Up @@ -339,7 +339,7 @@ function xmldb_hotquestion_upgrade($oldversion=0) {
}

// Hotquestion savepoint reached.
upgrade_mod_savepoint(true, 2022021500, 'hotquestion');
upgrade_mod_savepoint(true, 2022041000, 'hotquestion');
}
return $result;
}
12 changes: 2 additions & 10 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ function hotquestion_comment_validate($commentparam) {
}
$context = context_module::instance($cm->id);

if ($hotquestion->approval and !$record->approved and !has_capability('mod/hotquestion:approve', $context)) {
if ($hotquestion->approval and !$record->approved and !has_capability('mod/hotquestion:manageentries', $context)) {
throw new comment_exception('notapproved', 'hotquestion');
}
// Validate context id.
Expand All @@ -501,7 +501,7 @@ function hotquestion_comment_validate($commentparam) {
// Validation for comment deletion.
if (!empty($commentparam->commentid)) {
if ($comment = $DB->get_record('comments', array('id' => $commentparam->commentid))) {
if ($comment->commentarea != 'hotquestion_episode') {
if ($comment->commentarea != 'hotquestion_questions') {
throw new comment_exception('invalidcommentarea');
}
if ($comment->contextid != $commentparam->context->id) {
Expand All @@ -514,10 +514,6 @@ function hotquestion_comment_validate($commentparam) {
throw new comment_exception('invalidcommentid');
}
}
$debug['lib.php Tracking hotquestion_comment_validate exit: '] = 'Returning true validation in function in HQ lib.php file!';

//print_object($debug);

return true;
}

Expand All @@ -539,10 +535,6 @@ function hotquestion_comment_validate($commentparam) {
* @return array
*/
function hotquestion_comment_permissions($commentparam) {
//print_object('///////////////////////////////////////////////////////////////////////');
//print_object('In Hot Question lib.php file at line 504 checking comment permissions.');
//print_object(array('post' => true, 'view' => true));
//print_object('///////////////////////////////////////////////////////////////////////');
return array('post' => true, 'view' => true);
}

Expand Down
13 changes: 2 additions & 11 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,14 @@ public function definition() {
$mform->addHelpButton('removelabel', 'inputapprovallabel', 'hotquestion');
$mform->addRule('removelabel', null, 'required', null, 'client');
$mform->addRule('removelabel', get_string('maximumchars', '', 20), 'maxlength', 20, 'client');
/*
$mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'hotquestion'));
$mform->setDefault('allowcomments', $hotquestionconfig->allowcomments);
$mform->addHelpButton('allowcomments', 'allowcomments', 'hotquestion');
if (empty($CFG->usecomments)) {
$mform->hardFreeze('comments');
$mform->setConstant('comments', 0);
}
*/
// Allow comments.

// 20220410 Allow comments.
if ($hotquestionconfig->allowcomments) {
$mform->addElement('selectyesno', 'comments', get_string('allowcomments', 'hotquestion'));
$mform->addHelpButton('comments', 'allowcomments', 'hotquestion');
$mform->setDefault('comments', 0);
}


// Availability.
$mform->addElement('header', 'availabilityhdr', get_string('availability'));

Expand Down
Loading

0 comments on commit 2805f53

Please sign in to comment.