Skip to content

Commit

Permalink
Merge branch 'MDL-73483-master' of https://github.com/dmitriim/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Feb 23, 2024
2 parents f6a22d3 + 95eea30 commit b4f0a03
Show file tree
Hide file tree
Showing 8 changed files with 461 additions and 1 deletion.
94 changes: 94 additions & 0 deletions course/classes/hook/after_form_definition.php
@@ -0,0 +1,94 @@
<?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 core_course\hook;

use core\hook\described_hook;
use course_edit_form;
use MoodleQuickForm;

/**
* Allows plugins to extend course form definition and add/remove/update form elements.
*
* @see course_edit_form::definition()
*
* @package core
* @copyright 2023 Dmitrii Metelkin <dmitriim@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class after_form_definition implements described_hook {

/**
* Course form wrapper.
*
* @var course_edit_form
*/
protected $formwrapper;

/**
* Form to be extended.
*
* @var \MoodleQuickForm
*/
protected $mform;

/**
* Creates new hook.
*
* @param course_edit_form $formwrapper Course form wrapper.
* @param MoodleQuickForm $mform Form to be extended.
*/
public function __construct(course_edit_form $formwrapper, MoodleQuickForm $mform) {
$this->formwrapper = $formwrapper;
$this->mform = $mform;
}

/**
* Returns form.
*
* @return MoodleQuickForm
*/
public function get_mform(): MoodleQuickForm {
return $this->mform;
}

/**
* Returns form wrapper instance.
*
* @return course_edit_form
*/
public function get_formwrapper(): course_edit_form {
return $this->formwrapper;
}

/**
* Describes the hook purpose.
*
* @return string
*/
public static function get_hook_description(): string {
return 'Allows plugins to extend course editing form';
}

/**
* List of tags that describe this hook.
*
* @return string[]
*/
public static function get_hook_tags(): array {
return ['course'];
}
}
94 changes: 94 additions & 0 deletions course/classes/hook/after_form_definition_after_data.php
@@ -0,0 +1,94 @@
<?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 core_course\hook;

use core\hook\described_hook;
use course_edit_form;
use MoodleQuickForm;

/**
* Allows plugins to extend course form after data is set.
*
* @see course_edit_form::definition_after_data()
*
* @package core
* @copyright 2023 Dmitrii Metelkin <dmitriim@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class after_form_definition_after_data implements described_hook {

/**
* Course form wrapper.
*
* @var course_edit_form
*/
protected $formwrapper;

/**
* Form to be extended.
*
* @var \MoodleQuickForm
*/
protected $mform;

/**
* Creates new hook.
*
* @param course_edit_form $formwrapper Course form wrapper..
* @param MoodleQuickForm $mform Form to be extended.
*/
public function __construct(course_edit_form $formwrapper, MoodleQuickForm $mform) {
$this->formwrapper = $formwrapper;
$this->mform = $mform;
}

/**
* Returns form.
*
* @return MoodleQuickForm
*/
public function get_mform(): MoodleQuickForm {
return $this->mform;
}

/**
* Returns form wrapper instance.
*
* @return course_edit_form
*/
public function get_formwrapper(): course_edit_form {
return $this->formwrapper;
}

/**
* Describes the hook purpose.
*
* @return string
*/
public static function get_hook_description(): string {
return 'Allows plugins to extend course editing form after data is set';
}

/**
* List of tags that describe this hook.
*
* @return string[]
*/
public static function get_hook_tags(): array {
return ['course'];
}
}
94 changes: 94 additions & 0 deletions course/classes/hook/after_form_submission.php
@@ -0,0 +1,94 @@
<?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 core_course\hook;

use core\hook\described_hook;
use stdClass;

/**
* Allows plugins to extend course form submission.
*
* @see create_course()
* @see update_course()
*
* @package core
* @copyright 2023 Dmitrii Metelkin <dmitriim@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class after_form_submission implements described_hook {

/**
* Submitted data.
*
* @var stdClass
*/
protected $data;

/**
* Is it a new course ?
*
* @var bool
*/
protected $isnewcourse = false;

/**
* Creates new hook.
*
* @param stdClass $data Submitted data.
* @param bool $isnewcourse Is it a new course?
*/
public function __construct(stdClass $data, bool $isnewcourse = false) {
$this->data = $data;
$this->isnewcourse = $isnewcourse;
}

/**
* Returns submitted data.
*
* @return stdClass
*/
public function get_data(): stdClass {
return $this->data;
}

/**
* Informs callbacks if a hook called for a new course.
*
* @return bool
*/
public function is_new_course(): bool {
return $this->isnewcourse;
}

/**
* Describes the hook purpose.
*
* @return string
*/
public static function get_hook_description(): string {
return 'Allows plugins to extend saving of the course editing form';
}

/**
* List of tags that describe this hook.
*
* @return string[]
*/
public static function get_hook_tags(): array {
return ['course'];
}
}

0 comments on commit b4f0a03

Please sign in to comment.