<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace qbank_comment;
use core_question\local\bank\column_base;
use question_bank;
/**
* A column to show the number of comments.
*
* @package qbank_comment
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Safat Shahin <safatshahin@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class comment_count_column extends column_base {
/**
> * @var bool Comments enabled or not from config.
* Get the name of the column, used internally.
> */
*
> protected $commentsenabled = true;
* @return string
>
*/
> /**
public function get_name(): string {
> * Load javascript module if enabled.
return 'commentcount';
> *
}
> * @return void
> */
/**
> public function init(): void {
* Get the title of the column that will be displayed.
> parent::init();
*
> $this->check_comments_status();
* @return string
> if ($this->commentsenabled) {
*/
> global $PAGE;
public function get_title(): string {
> $PAGE->requires->js_call_amd('qbank_comment/comment', 'init');
return get_string('commentplural', 'qbank_comment');
> }
}
> }
>
/**
> /**
* Generate the content to be displayed.
> * Check if comments is turned on in the system or not.
*
> */
* @param object $question The question object.
> protected function check_comments_status(): void {
* @param string $rowclasses Classes that can be added.
> global $CFG;
*/
> if (!$CFG->usecomments) {
protected function display_content($question, $rowclasses): void {
> $this->commentsenabled = false;
global $DB, $PAGE;
> }
$syscontext = \context_system::instance();
> }
$args = [
>
'component' => 'qbank_comment',
> /**
< global $DB, $PAGE;
> global $DB;
'itemid' => $question->id,
'contextid' => $syscontext->id,
];
$commentcount = $DB->count_records('comments', $args);
$attributes = [];
if (question_has_capability_on($question, 'comment')) {
$target = 'questioncommentpreview_' . $question->id;
< $datatarget = '[data-target="' . $target . '"]';
< $PAGE->requires->js_call_amd('qbank_comment/comment', 'init', [$datatarget]);
$attributes = [
'href' => '#',
'data-target' => $target,
'data-questionid' => $question->id,
'data-courseid' => $this->qbank->course->id,
'data-contextid' => $syscontext->id,
];
}
echo \html_writer::tag('a', $commentcount, $attributes);
}
public function get_extra_classes(): array {
return ['pr-3'];
}
> public function get_default_width(): int {
}
> return 150;
> }