Skip to content

Commit

Permalink
Begin develop subscription like forum.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaboesch committed Nov 2, 2021
1 parent bfe5038 commit 98d642c
Show file tree
Hide file tree
Showing 22 changed files with 1,758 additions and 105 deletions.
2 changes: 1 addition & 1 deletion backup/moodle2/backup_pdfannotator_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function define_structure() {
// 2. Define each element separately.
$pdfannotator = new backup_nested_element('pdfannotator', array('id'), array(
'name', 'intro', 'introformat', 'usevotes', 'useprint', 'useprintcomments', 'use_studenttextbox', 'use_studentdrawing',
'useprivatecomments', 'useprotectedcomments', 'timecreated', 'timemodified'));
'useprotectedcomments', 'useprivatecomments', 'forcesubscribe', 'timecreated', 'timemodified'));

$annotations = new backup_nested_element('annotations');
$annotation = new backup_nested_element('annotation', array('id'), array('page', 'userid', 'annotationtypeid',
Expand Down
69 changes: 69 additions & 0 deletions classes/existing_subscriber_selector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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/>.

/**
* A type of pdfannotator.
*
* @package mod_pdfannotator
* @copyright 2021 Luca Bösch <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot.'/user/selector/lib.php');

/**
* User selector control for removing subscribed users
* @package mod_pdfannotator
* @copyright 2021 Luca Bösch <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_pdfannotator_existing_subscriber_selector extends mod_pdfannotator_subscriber_selector_base {

/**
* Finds all subscribed users
*
* @param string $search
* @return array
*/
public function find_users($search) {
global $DB;
list($wherecondition, $params) = $this->search_sql($search, 'u');
$params['pdfannotatorid'] = $this->pdfannotatorid;

// Only active enrolled or everybody on the frontpage.
list($esql, $eparams) = get_enrolled_sql($this->context, '', $this->currentgroup, true);
$fields = $this->required_fields_sql('u');
list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
$params = array_merge($params, $eparams, $sortparams);

$subscribers = $DB->get_records_sql("SELECT $fields
FROM {user} u
JOIN ($esql) je ON je.id = u.id
JOIN {pdfannotator_subscriptions} s ON s.userid = u.id
WHERE $wherecondition AND s.pdfannotator = :pdfannotatorid
ORDER BY $sort", $params);

$cm = get_coursemodule_from_instance('pdfannotator', $this->pdfannotatorid);
$modinfo = get_fast_modinfo($cm->course);
$info = new \core_availability\info_module($modinfo->get_cm($cm->id));
$subscribers = $info->filter_user_list($subscribers);

return array(get_string("existingsubscribers", 'pdfannotator') => $subscribers);
}

}
130 changes: 94 additions & 36 deletions classes/output/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,29 @@
*/
class comment implements \renderable, \templatable {

/**
* @var array An array of comments
*/
private $comments = [];

/**
* @var bool Visibility of a question
*/
private $questionvisibility;

/**
* Constructor of renderable for comments.
*
* @param object $data Comment or array of comments
* @param object $cm Course module
* @param stdClass $data Comment or array of comments
* @param stdClass $cm course module object
* @param object $context Context
* @return type
*/
public function __construct($data, $cm, $context) {
global $USER;

if (!is_array($data)) {
$data = [$data];
}

$report = has_capability('mod/pdfannotator:report', $context);
$closequestion = has_capability('mod/pdfannotator:closequestion', $context);
$closeanyquestion = has_capability('mod/pdfannotator:closeanyquestion', $context);
Expand Down Expand Up @@ -83,7 +88,7 @@ public function __construct($data, $cm, $context) {
$this->addeditbutton($comment, $editanypost);
$this->addhidebutton($comment, $seehiddencomments, $hidecomments);
$this->adddeletebutton($comment, $deleteown, $deleteany);
$this->addsubscribebutton($comment, $subscribe);
$this->addsubscribebutton($comment, $subscribe, $cm);
$this->addforwardbutton($comment, $forwardquestions, $cm);
$this->addmarksolvedbutton($comment, $solve);

Expand All @@ -94,8 +99,8 @@ public function __construct($data, $cm, $context) {
}

if (!empty($comment->modifiedby) && ($comment->modifiedby != $comment->userid) && ($comment->userid != 0)) {
$comment->modifiedby = get_string('modifiedby', 'pdfannotator') . ' '.
pdfannotator_get_username($comment->modifiedby);
$comment->modifiedby = get_string('modifiedby', 'pdfannotator') . ' ' .
pdfannotator_get_username($comment->modifiedby);
} else {
$comment->modifiedby = null;
}
Expand All @@ -112,15 +117,22 @@ public function __construct($data, $cm, $context) {
/**
* This function is required by any renderer to retrieve the data structure
* passed into the template.
*
* @param \renderer_base $output
* @return type
* @return stdClass
*/
public function export_for_template(\renderer_base $output) {
$data = [];
$data['comments'] = $this->comments;
return $data;
}

/**
* Add css class to a comment
*
* @param object $comment
* @param bool $owner
*/
private function addcssclasses($comment, $owner) {
$comment->wrapperClass = 'chat-message comment-list-item';
if ($comment->isquestion) {
Expand All @@ -136,6 +148,12 @@ private function addcssclasses($comment, $owner) {
}
}

/**
* Set votes to a comment
*
* @param object $comment
* @throws \coding_exception
*/
public function setvotes($comment) {
if ($comment->usevotes && !$comment->isdeleted) {
if ($comment->owner) {
Expand Down Expand Up @@ -163,7 +181,8 @@ public function setvotes($comment) {

/**
* Add check icon if comment is marked as correct.
* @param type $comment
*
* @param object $comment
*/
public function addsolvedicon($comment) {
if ($comment->solved) {
Expand All @@ -179,9 +198,10 @@ public function addsolvedicon($comment) {

/**
* Report comment if user is not the owner.
* @param type $comment
* @param type $owner
* @param type $report
*
* @param object $comment
* @param bool $report
* @param stdClass $cm course module object
*/
private function addreportbutton($comment, $report, $cm) {
if (!$comment->isdeleted && $report && !$comment->owner && !isset($comment->type)) {
Expand All @@ -193,10 +213,11 @@ private function addreportbutton($comment, $report, $cm) {

/**
* Open/close question if user is owner of the question or manager.
* @param type $comment
* @param type $owner
* @param type $closequestion
* @param type $closeanyquestion
*
* @param object $comment
* @param bool $closequestion
* @param bool $closeanyquestion
* @throws \coding_exception
*/
private function addcloseopenbutton($comment, $closequestion, $closeanyquestion) {

Expand All @@ -215,9 +236,10 @@ private function addcloseopenbutton($comment, $closequestion, $closeanyquestion)

/**
* Button for editing comment if user is owner of the comment or manager.
* @param type $comment
* @param type $owner
* @param type $editanypost
*
* @param object $comment
* @param bool $editanypost
* @throws \coding_exception
*/
private function addeditbutton($comment, $editanypost) {
if (!$comment->isdeleted && !isset($comment->type) && ($comment->owner || $editanypost)) {
Expand All @@ -228,6 +250,14 @@ private function addeditbutton($comment, $editanypost) {
}
}

/**
* Add a hide button
*
* @param object $comment
* @param bool $seehiddencomments
* @param bool $hidecomments
* @throws \coding_exception
*/
private function addhidebutton($comment, $seehiddencomments, $hidecomments) {
// Don't need to hide personal notes.
if ($this->questionvisibility == 'private') {
Expand Down Expand Up @@ -257,32 +287,53 @@ private function addhidebutton($comment, $seehiddencomments, $hidecomments) {

/**
* Delete comment if user is owner of the comment or manager.
* @param type $comment
* @param type $owner
* @param type $deleteown
* @param type $deleteany
*
* @param object $comment
* @param bool $deleteown
* @param bool $deleteany
* @throws \coding_exception
*/
private function adddeletebutton($comment, $deleteown, $deleteany) {
if (!$comment->isdeleted && ($deleteany || ($deleteown && $comment->owner))) {
$comment->buttons[] = ["classes" => "comment-delete-a", "text" => get_string('delete', 'pdfannotator'),
"moodleicon" => ["key" => "delete", "component" => "pdfannotator",
"title" => get_string('delete', 'pdfannotator')]];
"title" => get_string('delete', 'pdfannotator')]];
}
}

private function addsubscribebutton($comment, $subscribe) {
/**
* Add a subscribe button
*
* @param object $comment
* @param bool $subscribe
* @param stdClass $cm course module object
* @throws \coding_exception
*/
private function addsubscribebutton($comment, $subscribe, $cm) {
if (!isset($comment->type) && $comment->isquestion && $subscribe && $comment->visibility != 'private') {
// Only set for textbox and drawing.
if (!empty($comment->issubscribed)) {
$comment->buttons[] = ["classes" => "comment-subscribe-a", "faicon" => ["class" => "fa-bell-slash"],
"text" => get_string('unsubscribeQuestion', 'pdfannotator')];
} else {
$comment->buttons[] = ["classes" => "comment-subscribe-a", "faicon" => ["class" => "fa-bell"],
"text" => get_string('subscribeQuestion', 'pdfannotator')];
// Only set for textbox and drawing, and only if subscription mode is not disabled or forced.
if ((pdfannotator_get_subscriptionmode($cm->instance) == PDFANNOTATOR_CHOOSESUBSCRIBE) ||
(pdfannotator_get_subscriptionmode($cm->instance) == PDFANNOTATOR_INITIALSUBSCRIBE)) {
if (!empty($comment->issubscribed)) {
$comment->buttons[] = ["classes" => "comment-subscribe-a", "faicon" => ["class" => "fa-bell-slash"],
"text" => get_string('unsubscribeQuestion', 'pdfannotator')];
} else {
$comment->buttons[] = ["classes" => "comment-subscribe-a", "faicon" => ["class" => "fa-bell"],
"text" => get_string('subscribeQuestion', 'pdfannotator')];
}
}
}
}

/**
* Add a forward button
*
* @param object $comment
* @param bool $forwardquestions
* @param stdClass $cm course module object
* @throws \coding_exception
* @throws \moodle_exception
*/
private function addforwardbutton($comment, $forwardquestions, $cm) {
if (!isset($comment->type) && $comment->isquestion && !$comment->isdeleted && $forwardquestions &&
$comment->visibility != 'private') {
Expand All @@ -291,22 +342,29 @@ private function addforwardbutton($comment, $forwardquestions, $cm) {
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);

$comment->buttons[] = ["classes" => "comment-forward-a", "attributes" => ["name" => "onclick",
"value" => "window.location.href = '$url';"], "faicon" => ["class" => "fa-share"],
"text" => get_string('forward', 'pdfannotator')];
"value" => "window.location.href = '$url';"],
"faicon" => ["class" => "fa-share"], "text" => get_string('forward', 'pdfannotator')];
}
}

/**
* Add a Mark as correct or a Remove mark as correct button
*
* @param object $comment
* @param bool $solve
* @throws \coding_exception
*/
private function addmarksolvedbutton($comment, $solve) {
if ($solve && !$comment->isquestion && !$comment->isdeleted && !isset($comment->type) &&
$this->questionvisibility != 'private') {
if ($comment->solved) {
$comment->buttons[] = ["classes" => "comment-solve-a", "text" => get_string('removeCorrect', 'pdfannotator'),
"moodleicon" => ["key" => "i/completion-manual-n", "component" => "core",
"title" => get_string('removeCorrect', 'pdfannotator')]];
"title" => get_string('removeCorrect', 'pdfannotator')]];
} else {
$comment->buttons[] = ["classes" => "comment-solve-a", "text" => get_string('markCorrect', 'pdfannotator'),
"moodleicon" => ["key" => "i/completion-manual-enabled", "component" => "core",
"title" => get_string('markCorrect', 'pdfannotator')]];
"title" => get_string('markCorrect', 'pdfannotator')]];
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions classes/output/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class index implements \renderable, \templatable { // Class should be placed els
private $printurl;
private $useprivatecomments;
private $useprotectedcomments;
private $forcesubscribe;

public function __construct($pdfannotator, $capabilities, $file) {

Expand All @@ -55,6 +56,7 @@ public function __construct($pdfannotator, $capabilities, $file) {
$this->useprintcomments = ($pdfannotator->useprintcomments || $capabilities->useprintcomments);
$this->useprivatecomments = $pdfannotator->useprivatecomments;
$this->useprotectedcomments = $pdfannotator->useprotectedcomments;
$this->forcesubscribe = $pdfannotator->forcesubscribe;

$contextid = $file->get_contextid();
$component = $file->get_component();
Expand Down Expand Up @@ -85,6 +87,7 @@ public function export_for_template(\renderer_base $output) {
if ($data->useprivatecomments) {
$data->privatehelpicon = $OUTPUT->help_icon('private_comments', 'mod_pdfannotator');
}
$data->forcesubscribe = $this->forcesubscribe;
$data->printlink = $this->printurl;
$data->pixprintdoc = $OUTPUT->image_url('download', 'mod_pdfannotator');
$data->pixprintcomments = $OUTPUT->image_url('print_comments', 'mod_pdfannotator');
Expand Down
Loading

0 comments on commit 98d642c

Please sign in to comment.