Skip to content

Commit

Permalink
New Feature: Restriction implemented GH-7
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderJacob committed Jan 8, 2024
1 parent 9b943aa commit f09d6eb
Show file tree
Hide file tree
Showing 26 changed files with 833 additions and 102 deletions.
2 changes: 1 addition & 1 deletion amd/build/app-lazy.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/app-lazy.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/src/app-lazy.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace local_adele\restriction\conditions;

namespace local_adele\course_restriction\conditions;

use local_adele\course_restriction\course_restriction;

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

Expand All @@ -41,12 +41,12 @@
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manually {
class manual implements course_restriction {

/** @var int $id Standard Conditions have hardcoded ids. */
public $id = COURSES_COND_MANUALLY;
/** @var string $type of the redered condition in frontend. */
public $type = 'checkbox';
/** @var string $label of the redered condition in frontend. */
public $label = 'manual';
/**
* Obtains a string describing this restriction (whether or not
* it actually applies). Used to obtain information that is displayed to
Expand All @@ -63,14 +63,13 @@ class manually {
public function get_description():array {
$description = $this->get_description_string();
$name = $this->get_name_string();
$label = $this->get_label_string();
$label = $this->label;

return [
'id' => $this->id,
'name' => $name,
'description' => $description,
'label' => $label,
'type' => $this->type,
];
}

Expand All @@ -96,11 +95,15 @@ private function get_name_string() {

/**
* Helper function to return localized description strings.
*
* @return string
* @param array $node
* @param int $userid
* @return boolean
*/
private function get_label_string() {
$label = get_string('course_label_condition_manually', 'local_adele');
return $label;
public function get_restriction_status($node, $userid) {
if (isset($node['data']['manual'] ) && $node['data']['manual']
&& $node['data']['value']) {
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace local_adele\restriction\conditions;
namespace local_adele\course_restriction\conditions;

use local_adele\course_restriction\course_restriction;

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

Expand All @@ -40,12 +41,12 @@
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class timed {
class timed implements course_restriction {

/** @var int $id Standard Conditions have hardcoded ids. */
public $id = COURSES_COND_TIMED;
/** @var string $type of the redered condition in frontend. */
public $type = 'date';
public $label = 'timed';

/**
* Obtains a string describing this restriction (whether or not
Expand All @@ -63,14 +64,13 @@ class timed {
public function get_description():array {
$description = $this->get_description_string();
$name = $this->get_name_string();
$label = $this->get_label_string();
$label = $this->label;

return [
'id' => $this->id,
'name' => $name,
'description' => $description,
'label' => $label,
'type' => $this->type,
];
}

Expand All @@ -96,11 +96,12 @@ private function get_name_string() {

/**
* Helper function to return localized description strings.
*
* @return string
* @param array $node
* @param int $userid
* @return boolean
*/
private function get_label_string() {
$label = get_string('course_label_condition_timed', 'local_adele');
return $label;
public function get_restriction_status($node, $userid) {

return true;
}
}
74 changes: 74 additions & 0 deletions classes/course_restriction/course_completion_status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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 local_adele\course_completion;

/**
*
* @package local_adele
* @author Jacob Viertel
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* class for conditional availability information of a condition
*
* @package local_adele
* @author Jacob Viertel
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_completion_status {

/** @var int userid for a given user */
protected $userid;

/**
* Constructs with item details.
*
*/
public function __construct() {
global $USER;
$this->userid = $USER->id;
}

/**
* Returns conditions depending on the conditions param.
*
* @param array $node
* @param int $userid
* @return array
*/
public static function get_restriction_status($node, $userid): array {
global $CFG;
// First, we get all the available conditions from our directory.
$path = $CFG->dirroot . '/local/adele/classes/course_restriction/conditions/*.php';
$filelist = glob($path);
$completionstatus = [];
// We just want filenames, as they are also the classnames.
foreach ($filelist as $filepath) {
$path = pathinfo($filepath);
$filename = 'local_adele\\course_restriction\\conditions\\' . $path['filename'];
// We instantiate all the classes, because we need some information.
if (class_exists($filename)) {
$conditionclass = new $filename();
$completionstatus[$path['filename']] = $conditionclass->get_restriction_status($node, $userid);
}
}
return $completionstatus;
}
}
77 changes: 77 additions & 0 deletions classes/course_restriction/course_restriction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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/>.

/**
* Base class for a single booking option availability condition.
*
* All bo condition types must extend this class.
*
* @package local_adele
* @author Jacob Viertel
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace local_adele\course_restriction;

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

require_once($CFG->dirroot . '/local/adele/lib.php');

/**
* Interface for a learning path course conditions.
*
* @package local_adele
* @author Jacob Viertel
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

interface course_restriction {

/**
* Obtains a string describing this restriction (whether or not
* it actually applies). Used to obtain information that is displayed to
* students if the activity is not available to them, and for staff to see
* what conditions are.
*
* The $full parameter can be used to distinguish between 'staff' cases
* (when displaying all information about the activity) and 'student' cases
* (when displaying only conditions they don't meet).
*
* @return array Information string (for admin) about all restrictions on
* this item
*/
public function get_description();

/**
* Obtains a string describing this restriction (whether or not
* it actually applies). Used to obtain information that is displayed to
* students if the activity is not available to them, and for staff to see
* what conditions are.
*
* The $full parameter can be used to distinguish between 'staff' cases
* (when displaying all information about the activity) and 'student' cases
* (when displaying only conditions they don't meet).
*
* @param array $node
* @param int $userid
* @return array Information string (for admin) about all restrictions on
* this item
*/
public function get_restriction_status($node, $userid);

}
75 changes: 75 additions & 0 deletions classes/course_restriction/course_restriction_info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?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 local_adele\course_restriction;

/**
*
* @package local_adele
* @author Jacob Viertel
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* class for conditional availability information of a condition
*
* @package local_adele
* @author Jacob Viertel
* @copyright 2023 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_restriction_info {

/** @var int userid for a given user */
protected $userid;

/**
* Constructs with item details.
*
*/
public function __construct() {
global $USER;
$this->userid = $USER->id;
}

/**
* Returns conditions depending on the conditions param.
*
* @return array
*/
public static function get_restrictions(): array {

global $CFG;
// First, we get all the available conditions from our directory.
$path = $CFG->dirroot . '/local/adele/classes/course_restriction/conditions/*.php';
$filelist = glob($path);

$conditions = [];

// We just want filenames, as they are also the classnames.
foreach ($filelist as $filepath) {
$path = pathinfo($filepath);
$filename = 'local_adele\\course_restriction\\conditions\\' . $path['filename'];
// We instantiate all the classes, because we need some information.
if (class_exists($filename)) {
$conditionclass = new $filename();
$conditions[] = $conditionclass->get_description();
}
}
return $conditions;
}
}
Loading

0 comments on commit f09d6eb

Please sign in to comment.