Skip to content

Commit

Permalink
Merge pull request #60 from lucaboesch/codingstyle
Browse files Browse the repository at this point in the history
Coding style
  • Loading branch information
Friederike-cil authored Nov 2, 2021
2 parents d1afe6d + c1000c1 commit bfe5038
Show file tree
Hide file tree
Showing 36 changed files with 527 additions and 375 deletions.
20 changes: 11 additions & 9 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @package mod_pdfannotator
* @copyright 2018 RWTH Aachen (see README.md)
* @authors Rabea de Groot, Anna Heynkes, Friederike Schwager
* @author Rabea de Groot, Anna Heynkes, Friederike Schwager
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

Expand Down Expand Up @@ -151,7 +151,8 @@
$data['height'] = $annotation['height'];
break;
case 'drawing':
$studentdrawingsallowed = $DB->get_field('pdfannotator', 'use_studentdrawing', ['id' => $documentid], $strictness = MUST_EXIST);
$studentdrawingsallowed = $DB->get_field('pdfannotator', 'use_studentdrawing', ['id' => $documentid],
$strictness = MUST_EXIST);
$alwaysdrawingallowed = has_capability('mod/pdfannotator:usedrawing', $context);
if ($studentdrawingsallowed != 1 && !$alwaysdrawingallowed) {
echo json_encode(['status' => 'error', 'reason' => get_string('studentdrawingforbidden', 'pdfannotator')]);
Expand All @@ -174,7 +175,8 @@
$data['rectangles'] = $annotation['rectangles'];
break;
case 'textbox':
$studenttextboxesallowed = $DB->get_field('pdfannotator', 'use_studenttextbox', array('id' => $documentid), $strictness = MUST_EXIST);
$studenttextboxesallowed = $DB->get_field('pdfannotator', 'use_studenttextbox', array('id' => $documentid),
$strictness = MUST_EXIST);
$alwaystextboxallowed = has_capability('mod/pdfannotator:usetextbox', $context);
if ($studenttextboxesallowed != 1 && !$alwaystextboxallowed) {
echo json_encode(['status' => 'error', 'reason' => get_string('studenttextboxforbidden', 'pdfannotator')]);
Expand Down Expand Up @@ -386,8 +388,6 @@

$comments = pdfannotator_comment::read($documentid, $annotationid, $context);

// require_once($CFG->dirroot . '/mod/pdfannotator/classes/output/comment.php');

$myrenderer = $PAGE->get_renderer('mod_pdfannotator');
$templatable = new comment($comments, $cm, $context);

Expand Down Expand Up @@ -453,7 +453,7 @@

$commentid = required_param('commentId', PARAM_INT);
$content = required_param('content', PARAM_RAW);

$data = pdfannotator_comment::update($commentid, $content, $editanypost);
echo json_encode($data);
}
Expand Down Expand Up @@ -497,7 +497,8 @@
$thiscourse = $pdfannotator->course;
$cmid = get_coursemodule_from_instance('pdfannotator', $thisannotator, $thiscourse, false, MUST_EXIST)->id;

$urlparams = array('action' => 'overviewanswers', 'id' => $cmid, 'page' => 0, 'itemsperpage' => $itemsperpage, 'answerfilter' => 0);
$urlparams = array('action' => 'overviewanswers', 'id' => $cmid, 'page' => 0, 'itemsperpage' => $itemsperpage,
'answerfilter' => 0);
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
redirect($url->out());
return;
Expand Down Expand Up @@ -537,13 +538,14 @@
}

if ($subscriptionid) {
echo json_encode(['status' => 'success', 'annotationid' => $annotationid, 'subscriptionid' => $subscriptionid, 'annotatorid' => $annotatorid]);
echo json_encode(['status' => 'success', 'annotationid' => $annotationid, 'subscriptionid' => $subscriptionid,
'annotatorid' => $annotatorid]);
} else {
echo json_encode(['status' => 'error']);
}
}

/* * ****************************************** Mark a question as closed or an answer as correct ****************************************** */
/* * ****************************************** Mark a question as closed or an answer as correct ******************************* */

if ($action === 'markSolved') {
global $DB;
Expand Down
2 changes: 1 addition & 1 deletion backup/moodle2/backup_pdfannotator_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function define_my_steps() {
* @param string $content some HTML text that eventually contains URLs to the activity instance scripts
* @return string the content with the URLs encoded
*/
static public function encode_content_links($content) {
public static function encode_content_links($content) {

global $CFG, $DB;

Expand Down
15 changes: 10 additions & 5 deletions backup/moodle2/backup_pdfannotator_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,27 @@ 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'));
'name', 'intro', 'introformat', 'usevotes', 'useprint', 'useprintcomments', 'use_studenttextbox', 'use_studentdrawing',
'useprivatecomments', 'useprotectedcomments', 'timecreated', 'timemodified'));

$annotations = new backup_nested_element('annotations');
$annotation = new backup_nested_element('annotation', array('id'), array('page', 'userid', 'annotationtypeid', 'data', 'timecreated', 'timemodified', 'modifiedby'));
$annotation = new backup_nested_element('annotation', array('id'), array('page', 'userid', 'annotationtypeid',
'data', 'timecreated', 'timemodified', 'modifiedby'));

$subscriptions = new backup_nested_element('subscriptions');
$subscription = new backup_nested_element('subscription', array('id'), array('userid'));

$comments = new backup_nested_element('comments');
$c = array('pdfannotatorid', 'userid', 'content', 'timecreated', 'timemodified', 'modifiedby', 'visibility', 'isquestion', 'isdeleted', 'ishidden', 'solved');
$c = array('pdfannotatorid', 'userid', 'content', 'timecreated', 'timemodified', 'modifiedby', 'visibility',
'isquestion', 'isdeleted', 'ishidden', 'solved');
$comment = new backup_nested_element('comment', array('id'), $c);

$votes = new backup_nested_element('votes');
$vote = new backup_nested_element('vote', array('id'), array('userid', 'annotationid'));

$reports = new backup_nested_element('reports');
$report = new backup_nested_element('report', array('id'), array('courseid', 'pdfannotatorid', 'message', 'userid', 'timecreated', 'seen'));
$report = new backup_nested_element('report', array('id'), array('courseid', 'pdfannotatorid', 'message',
'userid', 'timecreated', 'seen'));

// 3. Build the tree (mind the right order!)
$pdfannotator->add_child($annotations);
Expand All @@ -97,7 +101,8 @@ protected function define_structure() {
// Add all annotations specific to this annotator instance.
$annotation->set_source_sql('SELECT a.* FROM {pdfannotator_annotations} a '
. 'JOIN {pdfannotator_comments} c ON a.id = c.annotationid '
. "WHERE a.pdfannotatorid = ? AND c.isquestion = 1 AND (c.visibility = 'public' OR c.visibility = 'anonymous') ",
. "WHERE a.pdfannotatorid = ? AND c.isquestion = 1 AND "
. "(c.visibility = 'public' OR c.visibility = 'anonymous') ",
array('pdfannotatorid' => backup::VAR_PARENTID));

// Add any subscriptions to this annotation.
Expand Down
16 changes: 8 additions & 8 deletions backup/moodle2/restore_pdfannotator_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function define_my_steps() {
* Define the contents in the activity that must be
* processed by the link decoder.
*/
static public function define_decode_contents() {
public static function define_decode_contents() {
$contents = array();

$contents[] = new restore_decode_content('pdfannotator', array('intro'), 'pdfannotator');
Expand All @@ -69,7 +69,7 @@ static public function define_decode_contents() {
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
static public function define_decode_rules() {
public static function define_decode_rules() {
$rules = array();

$rules[] = new restore_decode_rule('PDFANNOTATORVIEWBYID', '/mod/pdfannotator/view.php?id=$1', 'course_module');
Expand All @@ -81,11 +81,11 @@ static public function define_decode_rules() {

/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* by the {@see restore_logs_processor} when restoring
* pdfannotator logs. It must return one array
* of {@link restore_log_rule} objects
* of {@see restore_log_rule} objects
*/
static public function define_restore_log_rules() {
public static function define_restore_log_rules() {
$rules = array();

$rules[] = new restore_log_rule('pdfannotator', 'add', 'view.php?id={course_module}', '{pdfannotator}');
Expand All @@ -97,15 +97,15 @@ static public function define_restore_log_rules() {

/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* by the {@see restore_logs_processor} when restoring
* course logs. It must return one array
* of {@link restore_log_rule} objects
* of {@see restore_log_rule} objects
*
* Note this rules are applied when restoring course logs
* by the restore final task, but are defined here at
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
static public function define_restore_log_rules_for_course() {
public static function define_restore_log_rules_for_course() {
$rules = array();

$rules[] = new restore_log_rule('pdfannotator', 'view all', 'index.php?id={course}', null);
Expand Down
23 changes: 15 additions & 8 deletions backup/moodle2/restore_pdfannotator_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,21 @@ protected function define_structure() {

$userinfo = $this->get_setting_value('userinfo'); // Is 0 //TODO is not used.

$paths[] = new restore_path_element('pdfannotator', '/activity/pdfannotator');
$paths[] = new restore_path_element('pdfannotator',
'/activity/pdfannotator');

$paths[] = new restore_path_element('pdfannotator_annotation', '/activity/pdfannotator/annotations/annotation');
$paths[] = new restore_path_element('pdfannotator_annotation',
'/activity/pdfannotator/annotations/annotation');

$paths[] = new restore_path_element('pdfannotator_subscription', '/activity/pdfannotator/annotations/annotation/subscriptions/subscription');
$paths[] = new restore_path_element('pdfannotator_comment', '/activity/pdfannotator/annotations/annotation/comments/comment');
$paths[] = new restore_path_element('pdfannotator_subscription',
'/activity/pdfannotator/annotations/annotation/subscriptions/subscription');
$paths[] = new restore_path_element('pdfannotator_comment',
'/activity/pdfannotator/annotations/annotation/comments/comment');

$paths[] = new restore_path_element('pdfannotator_vote', '/activity/pdfannotator/annotations/annotation/comments/comment/votes/vote');
$paths[] = new restore_path_element('pdfannotator_report', '/activity/pdfannotator/annotations/annotation/comments/comment/reports/report');
$paths[] = new restore_path_element('pdfannotator_vote',
'/activity/pdfannotator/annotations/annotation/comments/comment/votes/vote');
$paths[] = new restore_path_element('pdfannotator_report',
'/activity/pdfannotator/annotations/annotation/comments/comment/reports/report');

// Return the paths wrapped into standard activity structure.
return $this->prepare_activity_structure($paths);
Expand Down Expand Up @@ -143,8 +149,9 @@ protected function process_pdfannotator_report($data) {
$data->commentid = $this->get_new_parentid('pdfannotator_comment');
$data->userid = $this->get_mappingid('user', $data->userid);

// $data->timecreated = $this->apply_date_offset($data->timecreated);
$data->pdfannotatorid = $this->get_mappingid('pdfannotator', $data->pdfannotatorid); // Params: 1. Object class as defined in structure, 2. attribute&/column name.
// $data->timecreated = $this->apply_date_offset($data->timecreated);
$data->pdfannotatorid = $this->get_mappingid('pdfannotator', $data->pdfannotatorid);
// Params: 1. Object class as defined in structure, 2. attribute&/column name.

$newitemid = $DB->insert_record('pdfannotator_reports', $data);
$this->set_mapping('pdfannotator_report', $oldid, $newitemid);
Expand Down
2 changes: 1 addition & 1 deletion classes/event/report_added.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ public function get_description() {
public function get_url() {
return new \moodle_url('/mod/pdfannotator/view.php', array('id' => $this->other['cmid'], 'action' => 'overview'));
}
}
}
1 change: 0 additions & 1 deletion classes/output/answermenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class answermenu implements \renderable, \templatable {

/**
* Constructor of renderable for dropdown menu in answerstable.
* @global type $CFG
* @param int $annotationid Id of the annotation the answer belongs to
* @param bool $issubscribed Is the user subscribed to the question?
* @param int $cmid Course module id
Expand Down
Loading

0 comments on commit bfe5038

Please sign in to comment.