Skip to content

Commit

Permalink
TW17197591 - Added class constants. (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayChurchward authored and mchurchward committed Jul 8, 2021
1 parent 55bc8a4 commit ea767fb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
48 changes: 33 additions & 15 deletions classes/board.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,35 @@

defined('MOODLE_INTERNAL') || die;

define('ACCEPTED_FILE_EXTENSIONS', 'jpg,jpeg,png,bmp,gif');
define('ACCEPTED_FILE_MIN_SIZE', 100); // 100 bites
define('ACCEPTED_FILE_MAX_SIZE', 1024 * 1024 * 10); // 10Mb
define('RATINGDISABLED', 0);
define('RATINGBYSTUDENTS', 1);
define('RATINGBYTEACHERS', 2);
define('RATINGBYALL', 3);
define('SORTBYDATE', 1);
define('SORTBYRATING', 2);

class board {

/** @var string String of accepted file types. */
const ACCEPTED_FILE_EXTENSIONS = 'jpg,jpeg,png,bmp,gif';

/** @var int Minumum file size of 100 bytes. */
const ACCEPTED_FILE_MIN_SIZE = 100;

/** @var int Maximum file size of 10Mb. */
const ACCEPTED_FILE_MAX_SIZE = 1024 * 1024 * 10;

/** @var int Value for disabling rating. */
const RATINGDISABLED = 0;

/** @var int Value for allowing students to rate posts. */
const RATINGBYSTUDENTS = 1;

/** @var int Value for allowing teachers to rate posts */
const RATINGBYTEACHERS = 2;

/** @var int Value for allowing all roles to rate posts */
const RATINGBYALL = 3;

/** @var int Value for sorting all posts by date */
const SORTBYDATE = 1;

/** @var int Value for sorting all posts by rating */
const SORTBYRATING = 2;

/**
* Retrieves the course module for the board
*
Expand Down Expand Up @@ -542,15 +560,15 @@ public static function store_note_file($noteid, $attachment) {
*/
public static function valid_for_upload($attachment) {
$fileextension = strtolower(array_pop(explode('.', basename($attachment['filename']))));
if (!in_array($fileextension, explode(',', ACCEPTED_FILE_EXTENSIONS))) {
if (!in_array($fileextension, explode(',', self::ACCEPTED_FILE_EXTENSIONS))) {
return false;
}
$filelength = strlen($attachment['filecontents']);

if ($filelength < ACCEPTED_FILE_MIN_SIZE) {
if ($filelength < self::ACCEPTED_FILE_MIN_SIZE) {
return false;
}
if ($filelength > ACCEPTED_FILE_MAX_SIZE) {
if ($filelength > self::ACCEPTED_FILE_MAX_SIZE) {
return false;
}

Expand Down Expand Up @@ -915,11 +933,11 @@ public static function board_can_rate_note($noteid) {

$iseditor = has_capability('mod/board:manageboard', $context);

if ($board->addrating == RATINGBYSTUDENTS && $iseditor) {
if ($board->addrating == self::RATINGBYSTUDENTS && $iseditor) {
return false;
}

if ($board->addrating == RATINGBYTEACHERS && !$iseditor) {
if ($board->addrating == self::RATINGBYTEACHERS && !$iseditor) {
return false;
}

Expand Down
14 changes: 8 additions & 6 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

require_once($CFG->dirroot.'/course/moodleform_mod.php');

use mod_board\board;

class mod_board_mod_form extends moodleform_mod {
public function definition() {
global $CFG, $DB;
Expand Down Expand Up @@ -60,10 +62,10 @@ public function definition() {

$mform->addElement('select', 'addrating', get_string('addrating', 'mod_board'),
array(
RATINGDISABLED => get_string('addrating_none', 'mod_board'),
RATINGBYSTUDENTS => get_string('addrating_students', 'mod_board'),
RATINGBYTEACHERS => get_string('addrating_teachers', 'mod_board'),
RATINGBYALL => get_string('addrating_all', 'mod_board')
board::RATINGDISABLED => get_string('addrating_none', 'mod_board'),
board::RATINGBYSTUDENTS => get_string('addrating_students', 'mod_board'),
board::RATINGBYTEACHERS => get_string('addrating_teachers', 'mod_board'),
board::RATINGBYALL => get_string('addrating_all', 'mod_board')
)
);
$mform->setType('addrating', PARAM_INT);
Expand All @@ -73,8 +75,8 @@ public function definition() {

$mform->addElement('select', 'sortby', get_string('sortby', 'mod_board'),
array(
SORTBYDATE => get_string('sortbydate', 'mod_board'),
SORTBYRATING => get_string('sortbyrating', 'mod_board')
board::SORTBYDATE => get_string('sortbydate', 'mod_board'),
board::SORTBYRATING => get_string('sortbyrating', 'mod_board')
)
);
$mform->setType('sortby', PARAM_INT);
Expand Down
6 changes: 3 additions & 3 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
'post_max_length' => $config->post_max_length,
'history_refresh' => $config->history_refresh,
'file' => array(
'extensions' => explode(',', ACCEPTED_FILE_EXTENSIONS),
'size_min' => ACCEPTED_FILE_MIN_SIZE,
'size_max' => ACCEPTED_FILE_MAX_SIZE
'extensions' => explode(',', board::ACCEPTED_FILE_EXTENSIONS),
'size_min' => board::ACCEPTED_FILE_MIN_SIZE,
'size_max' => board::ACCEPTED_FILE_MAX_SIZE
),
'ratingenabled' => board::board_rating_enabled($board->id),
'hideheaders' => board::board_hide_headers($board->id),
Expand Down

0 comments on commit ea767fb

Please sign in to comment.