Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
robingenz committed May 9, 2023
0 parents commit 85bd9a9
Show file tree
Hide file tree
Showing 28 changed files with 2,780 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
projectapproval module
======================

The projectapproval module is used for the registration and approval of project and bachelor theses.

Installation
------------
1. Load the module directory into your "mod" subdirectory.
2. Visit your admin page to create all of the necessary data tables

License
-------
Licensed under the [GNU GPL License v3](http://www.gnu.org/copyleft/gpl.html).
70 changes: 70 additions & 0 deletions backup/moodle2/backup_projectapproval_activity_task.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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/>.

/**
* Defines backup_projectapproval_activity_task class
*
* @package mod_projectapproval
* @category backup
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die;

require_once($CFG->dirroot . '/mod/projectapproval/backup/moodle2/backup_projectapproval_stepslib.php');

/**
* Provides the steps to perform one complete backup of the Page instance
*/
class backup_projectapproval_activity_task extends backup_activity_task {

/**
* Specific settings for this activity
*/
protected function define_my_settings() {
}

/**
* Defines a backup step to store the instance data in the projectapproval.xml file
*/
protected function define_my_steps() {
$this->add_step(new backup_projectapproval_activity_structure_step('projectapproval_structure', 'projectapproval.xml'));
}

/**
* Encodes URLs to the index.php and view.php scripts
*
* @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) {
global $CFG;

$base = preg_quote($CFG->wwwroot,"/");

// Link to the list of projectapprovals
$search="/(".$base."\/mod\/projectapproval\/index.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@PAGEINDEX*$2@$', $content);

// Link to projectapproval view by moduleid
$search="/(".$base."\/mod\/projectapproval\/view.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@PAGEVIEWBYID*$2@$', $content);

return $content;
}
}
61 changes: 61 additions & 0 deletions backup/moodle2/backup_projectapproval_stepslib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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/>.

/**
* @package mod_projectapproval
* @category backup
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die;

/**
* Define all the backup steps that will be used by the backup_projectapproval_activity_task
*/

/**
* Define the complete projectapproval structure for backup, with file and id annotations
*/
class backup_projectapproval_activity_structure_step extends backup_activity_structure_step {

protected function define_structure() {

// Define each element separated
$projectapproval = new backup_nested_element('projectapproval', array('id'), array(
'course', 'name', 'intro', 'introformat', 'manager', 'locknote', 'timemodified'));
$projectapp_project = new backup_nested_element('projectapp_project', array('id'), array(
'cmid', 'userid', 'company', 'company_attendant', 'company_email', 'attendant', 'title',
'content', 'comment', 'status', 'locknote', 'timemodified', 'timecreated'));

// Build the tree
$projectapproval->add_child($projectapp_project);

// Define sources
$projectapproval->set_source_table('projectapproval', array('id' => backup::VAR_ACTIVITYID));
$projectapp_project->set_source_table('projectapp_project', array('cmid' => backup::VAR_MODID));

// Define id annotations
// (none)

// Define file annotations
$projectapproval->annotate_files('mod_projectapproval', 'intro', null); // This file areas haven't itemid

// Return the root element (projectapproval), wrapped into standard activity structure
return $this->prepare_activity_structure($projectapproval);
}
}
100 changes: 100 additions & 0 deletions backup/moodle2/restore_projectapproval_activity_task.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?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/>.

/**
* @package mod_projectapproval
* @category backup
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

require_once($CFG->dirroot . '/mod/projectapproval/backup/moodle2/restore_projectapproval_stepslib.php'); // Because it exists (must)

/**
* projectapproval restore task that provides all the settings and steps to perform one
* complete restore of the activity
*/
class restore_projectapproval_activity_task extends restore_activity_task {

/**
* Define (add) particular settings this activity can have
*/
protected function define_my_settings() {
// No particular settings for this activity
}

/**
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
// label only has one structure step
$this->add_step(new restore_projectapproval_activity_structure_step('projectapproval_structure', 'projectapproval.xml'));
}

/**
* Define the contents in the activity that must be
* processed by the link decoder
*/
static public function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('projectapproval', array('intro'), 'projectapproval');
return $contents;
}

/**
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
static public function define_decode_rules() {
$rules = array();
$rules[] = new restore_decode_rule('PAGEVIEWBYID', '/mod/projectapproval/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('PAGEINDEX', '/mod/projectapproval/index.php?id=$1', 'course');
return $rules;
}

/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* projectapproval logs. It must return one array
* of {@link restore_log_rule} objects
*/
static public function define_restore_log_rules() {
$rules = array();
$rules[] = new restore_log_rule('projectapproval', 'add', 'view.php?id={course_module}', '{projectapproval}');
$rules[] = new restore_log_rule('projectapproval', 'update', 'view.php?id={course_module}', '{projectapproval}');
$rules[] = new restore_log_rule('projectapproval', 'view', 'view.php?id={course_module}', '{projectapproval}');
return $rules;
}

/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* course logs. It must return one array
* of {@link 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() {
$rules = array();
$rules[] = new restore_log_rule('projectapproval', 'view all', 'index.php?id={course}', null);
return $rules;
}
}
81 changes: 81 additions & 0 deletions backup/moodle2/restore_projectapproval_stepslib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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/>.

/**
* @package mod_projectapproval
* @category backup
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Define all the restore steps that will be used by the restore_projectapproval_activity_task
*/

/**
* Structure step to restore one projectapproval activity
*/
class restore_projectapproval_activity_structure_step extends restore_activity_structure_step {

protected function define_structure() {
$paths = array();
$paths[] = new restore_path_element('projectapproval', '/activity/projectapproval');
$paths[] = new restore_path_element('projectapp_project', '/activity/projectapproval/projectapp_project');

// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}

protected function process_projectapproval($data) {
global $DB;

$data = (object)$data;
$data->course = $this->get_courseid();

// Insert the projectapproval record.
$newitemid = $DB->insert_record('projectapproval', $data);
// Immediately after inserting "activity" record, call this.
$this->apply_activity_instance($newitemid);
}

protected function process_projectapp_project($data) {
global $DB;

// To know if we are including userinfo.
$userinfo = $this->get_setting_value('userinfo');
if (!$userinfo) {
retrun;
}
$data = (object)$data;
// Set new cmid.
$data->cmid = $this->task->get_moduleid();
if (!$this->task->is_samesite()) {
// Set new userid.
$data->userid = $this->get_mappingid('user', $data->userid);
}

// Insert the projectapp_project record.
$newitemid = $DB->insert_record('projectapp_project', $data);
// Immediately after inserting "activity" record, call this.
$this->apply_activity_instance($newitemid);
}

protected function after_execute() {
// Add projectapproval related files, no need to match by itemname (just internally handled context).
$this->add_related_files('mod_projectapproval', 'intro', null);
}
}
48 changes: 48 additions & 0 deletions classes/event/course_module_viewed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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/>.

/**
* The mod_projectapproval course module viewed event.
*
* @package mod_projectapproval
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_projectapproval\event;
defined('MOODLE_INTERNAL') || die();

/**
* The mod_projectapproval course module viewed event class.
*
* @package mod_projectapproval
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_module_viewed extends \core\event\course_module_viewed {

/**
* Init method.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'projectapproval';
}

public static function get_objectid_mapping() {
return array('db' => 'projectapproval', 'restore' => 'projectapproval');
}
}

Loading

0 comments on commit 85bd9a9

Please sign in to comment.