Skip to content

Commit 03cae40

Browse files
committed
Módulo para feedback (journal)
1 parent 81dc45b commit 03cae40

36 files changed

+3682
-0
lines changed

mod/journal/.travis.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
notifications:
2+
email:
3+
recipients:
4+
5+
on_success: never
6+
on_failure: always
7+
language: php
8+
php:
9+
- "5.4"
10+
env:
11+
- DB=pgsql
12+
before_script:
13+
- git clone git://github.com/moodle/moodle ../moodle && cd ../moodle
14+
- git checkout $TRAVIS_BRANCH
15+
- sudo apt-get update > /dev/null
16+
- composer self-update
17+
- mv ../moodle-mod_journal mod/journal
18+
- cp config-dist.php config.php
19+
- sh -c "psql -c 'create database moodle;' -U postgres"
20+
- sh -c "sed -i -e s/'password'/''/ -e s%/home/example%$HOME% -e 's%\(\$CFG.*bht\)%\n\1%' -e 's%\(\$CFG.*behat_wwwroot.*http://127\)%\n\1%' -e s/\'username\'/\'postgres\'/ -e s%127.0.0.1/moodle%localhost:8000% config.php"
21+
- cat config.php
22+
- mkdir -m777 $HOME/bht_moodledata
23+
- php admin/tool/behat/cli/init.php
24+
- "(php -S localhost:8000 &) 2> /dev/null > /dev/null"
25+
script:
26+
- vendor/bin/behat --config /home/travis/bht_moodledata/behat/behat.yml --tags @mod_journal

mod/journal/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
[![Build Status](https://travis-ci.org/dmonllao/moodle-mod_journal.svg?branch=master)](https://travis-ci.org/dmonllao/moodle-mod_journal)
3+
4+
# Moodle Journal module
5+
- Moodle tracker component: http://tracker.moodle.org/browse/CONTRIB/component/10880
6+
- Documentation: http://docs.moodle.org/dev/en/Journal_module
7+
- Source Code: https://github.com/dmonllao/moodle-mod_journal
8+
- License: http://www.gnu.org/licenses/gpl-2.0.txt
9+
10+
## Install from git
11+
- Navigate to Moodle root folder
12+
- **git clone git://github.com/dmonllao/moodle-mod_journal.git mod/journal**
13+
14+
## Install from a compressed file
15+
- Extract the compressed file data
16+
- Rename the main folder to journal
17+
- Copy to the Moodle mod/ folder
18+
- Click the 'Notifications' link on the frontpage administration block
19+

mod/journal/backup/moodle1/lib.php

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
defined('MOODLE_INTERNAL') || die();
4+
5+
/**
6+
* Journal conversion handler
7+
*/
8+
class moodle1_mod_journal_handler extends moodle1_mod_handler {
9+
10+
/**
11+
* Declare the paths in moodle.xml we are able to convert
12+
*
13+
* The method returns list of {@link convert_path} instances.
14+
* For each path returned, the corresponding conversion method must be
15+
* defined.
16+
*
17+
* @return array of {@link convert_path} instances
18+
*/
19+
public function get_paths() {
20+
return array(
21+
new convert_path(
22+
'journal', '/MOODLE_BACKUP/COURSE/MODULES/MOD/JOURNAL',
23+
array(
24+
'renamefields' => array(
25+
'assessed' => 'grade'
26+
)
27+
)
28+
),
29+
new convert_path('entries', '/MOODLE_BACKUP/COURSE/MODULES/MOD/JOURNAL/ENTRIES'),
30+
new convert_path('entry', '/MOODLE_BACKUP/COURSE/MODULES/MOD/JOURNAL/ENTRIES/ENTRY'),
31+
);
32+
}
33+
34+
public function process_journal($data) {
35+
36+
// get the course module id and context id
37+
$instanceid = $data['id'];
38+
$cminfo = $this->get_cminfo($instanceid);
39+
$moduleid = $cminfo['id'];
40+
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
41+
42+
// we now have all information needed to start writing into the file
43+
$this->open_xml_writer("activities/journal_{$moduleid}/journal.xml");
44+
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
45+
'modulename' => 'journal', 'contextid' => $contextid));
46+
$this->xmlwriter->begin_tag('journal', array('id' => $instanceid));
47+
48+
unset($data['id']);
49+
foreach ($data as $field => $value) {
50+
$this->xmlwriter->full_tag($field, $value);
51+
}
52+
53+
return $data;
54+
}
55+
56+
/**
57+
* This is executed when the parser reaches the <ENTRIES> opening element
58+
*/
59+
public function on_entries_start() {
60+
$this->xmlwriter->begin_tag('entries');
61+
}
62+
63+
/**
64+
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/JOURNAL/ENTRIES/ENTRY
65+
* data available
66+
*/
67+
public function process_entry($data) {
68+
$this->write_xml('entry', $data, array('/entry/id'));
69+
}
70+
71+
/**
72+
* This is executed when the parser reaches the closing </ENTRIES> element
73+
*/
74+
public function on_entries_end() {
75+
$this->xmlwriter->end_tag('entries');
76+
}
77+
78+
/**
79+
* This is executed when we reach the closing </MOD> tag of our 'journal' path
80+
*/
81+
public function on_journal_end() {
82+
83+
$this->xmlwriter->end_tag('journal');
84+
$this->xmlwriter->end_tag('activity');
85+
$this->close_xml_writer();
86+
}
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
require_once($CFG->dirroot.'/mod/journal/backup/moodle2/backup_journal_stepslib.php');
4+
5+
class backup_journal_activity_task extends backup_activity_task {
6+
7+
protected function define_my_settings() {}
8+
9+
protected function define_my_steps() {
10+
$this->add_step(new backup_journal_activity_structure_step('journal_structure', 'journal.xml'));
11+
}
12+
13+
static public function encode_content_links($content) {
14+
global $CFG;
15+
16+
$base = preg_quote($CFG->wwwroot.'/mod/journal','#');
17+
18+
$pattern = "#(".$base."\/index.php\?id\=)([0-9]+)#";
19+
$content = preg_replace($pattern, '$@JOURNALINDEX*$2@$', $content);
20+
21+
$pattern = "#(".$base."\/view.php\?id\=)([0-9]+)#";
22+
$content = preg_replace($pattern, '$@JOURNALVIEWBYID*$2@$', $content);
23+
24+
$pattern = "#(".$base."\/report.php\?id\=)([0-9]+)#";
25+
$content = preg_replace($pattern, '$@JOURNALREPORT*$2@$', $content);
26+
27+
$pattern = "#(".$base."\/edit.php\?id\=)([0-9]+)#";
28+
$content = preg_replace($pattern, '$@JOURNALEDIT*$2@$', $content);
29+
30+
return $content;
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
class backup_journal_activity_structure_step extends backup_activity_structure_step {
4+
5+
protected function define_structure() {
6+
7+
$journal = new backup_nested_element('journal', array('id'), array(
8+
'name', 'intro', 'introformat', 'days', 'grade', 'timemodified'));
9+
10+
$entries = new backup_nested_element('entries');
11+
12+
$entry = new backup_nested_element('entry', array('id'), array(
13+
'userid', 'modified', 'text', 'format', 'rating',
14+
'entrycomment', 'teacher', 'timemarked', 'mailed'));
15+
16+
// journal -> entries -> entry
17+
$journal->add_child($entries);
18+
$entries->add_child($entry);
19+
20+
// Sources
21+
$journal->set_source_table('journal', array('id' => backup::VAR_ACTIVITYID));
22+
23+
if ($this->get_setting_value('userinfo')) {
24+
$entry->set_source_table('journal_entries', array('journal' => backup::VAR_PARENTID));
25+
}
26+
27+
// Define id annotations
28+
$entry->annotate_ids('user', 'userid');
29+
$entry->annotate_ids('user', 'teacher');
30+
31+
// Define file annotations
32+
$journal->annotate_files('mod_journal', 'intro', null); // This file areas haven't itemid
33+
$entry->annotate_files('mod_journal_entries', 'text', null); // This file areas haven't itemid
34+
$entry->annotate_files('mod_journal_entries', 'entrycomment', null); // This file areas haven't itemid
35+
36+
return $this->prepare_activity_structure($journal);
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
defined('MOODLE_INTERNAL') || die();
4+
5+
require_once($CFG->dirroot.'/mod/journal/backup/moodle2/restore_journal_stepslib.php');
6+
7+
class restore_journal_activity_task extends restore_activity_task {
8+
9+
protected function define_my_settings() {}
10+
11+
protected function define_my_steps() {
12+
$this->add_step(new restore_journal_activity_structure_step('journal_structure', 'journal.xml'));
13+
}
14+
15+
static public function define_decode_contents() {
16+
17+
$contents = array();
18+
$contents[] = new restore_decode_content('journal', array('intro'), 'journal');
19+
$contents[] = new restore_decode_content('journal_entries', array('text', 'entrycomment'), 'journal_entry');
20+
21+
return $contents;
22+
}
23+
24+
static public function define_decode_rules() {
25+
26+
$rules = array();
27+
$rules[] = new restore_decode_rule('JOURNALINDEX', '/mod/journal/index.php?id=$1', 'course');
28+
$rules[] = new restore_decode_rule('JOURNALVIEWBYID', '/mod/journal/view.php?id=$1', 'course_module');
29+
$rules[] = new restore_decode_rule('JOURNALREPORT', '/mod/journal/report.php?id=$1', 'course_module');
30+
$rules[] = new restore_decode_rule('JOURNALEDIT', '/mod/journal/edit.php?id=$1', 'course_module');
31+
32+
return $rules;
33+
34+
}
35+
36+
public static function define_restore_log_rules() {
37+
38+
$rules = array();
39+
$rules[] = new restore_log_rule('journal', 'view', 'view.php?id={course_module}', '{journal}');
40+
$rules[] = new restore_log_rule('journal', 'view responses', 'report.php?id={course_module}', '{journal}');
41+
$rules[] = new restore_log_rule('journal', 'add entry', 'edit.php?id={course_module}', '{journal}');
42+
$rules[] = new restore_log_rule('journal', 'update entry', 'edit.php?id={course_module}', '{journal}');
43+
$rules[] = new restore_log_rule('journal', 'update feedback', 'report.php?id={course_module}', '{journal}');
44+
45+
return $rules;
46+
}
47+
48+
public static function define_restore_log_rules_for_course() {
49+
50+
$rules = array();
51+
$rules[] = new restore_log_rule('journal', 'view all', 'index.php?id={course}', null);
52+
53+
return $rules;
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
class restore_journal_activity_structure_step extends restore_activity_structure_step {
4+
5+
protected function define_structure() {
6+
7+
$paths = array();
8+
$paths[] = new restore_path_element('journal', '/activity/journal');
9+
10+
if ($this->get_setting_value('userinfo')) {
11+
$paths[] = new restore_path_element('journal_entry', '/activity/journal/entries/entry');
12+
}
13+
14+
return $this->prepare_activity_structure($paths);
15+
}
16+
17+
protected function process_journal($data) {
18+
19+
global $DB;
20+
21+
$data = (Object)$data;
22+
23+
$oldid = $data->id;
24+
unset($data->id);
25+
26+
$data->course = $this->get_courseid();
27+
$data->timemodified = $this->apply_date_offset($data->timemodified);
28+
29+
$newid = $DB->insert_record('journal', $data);
30+
$this->apply_activity_instance($newid);
31+
}
32+
33+
protected function process_journal_entry($data) {
34+
35+
global $DB;
36+
37+
$data = (Object)$data;
38+
39+
$oldid = $data->id;
40+
unset($data->id);
41+
42+
$data->journal = $this->get_new_parentid('journal');
43+
$data->modified = $this->apply_date_offset($data->modified);
44+
$data->timemarked = $this->apply_date_offset($data->timemarked);
45+
$data->userid = $this->get_mappingid('user', $data->userid);
46+
$data->teacher = $this->get_mappingid('user', $data->teacher);
47+
48+
$newid = $DB->insert_record('journal_entries', $data);
49+
$this->set_mapping('journal_entry', $oldid, $newid);
50+
}
51+
52+
protected function after_execute() {
53+
$this->add_related_files('mod_journal', 'intro', null);
54+
$this->add_related_files('mod_journal_entries', 'text', null);
55+
$this->add_related_files('mod_journal_entries', 'entrycomment', null);
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* The mod_journal instance list viewed event.
19+
*
20+
* @package mod_journal
21+
* @copyright 2014 [email protected]
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
namespace mod_journal\event;
26+
27+
defined('MOODLE_INTERNAL') || die();
28+
29+
/**
30+
* The mod_journal instance list viewed event class.
31+
*
32+
* @package mod_journal
33+
* @since Moodle 2.7
34+
* @copyright 2014 [email protected]
35+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36+
*/
37+
class course_module_instance_list_viewed extends \core\event\course_module_instance_list_viewed {
38+
// No need for any code here as everything is handled by the parent class.
39+
}

0 commit comments

Comments
 (0)