+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$capabilities = array(
+
+ 'block/workflow_diagram:myaddinstance' => array(
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_SYSTEM,
+ 'archetypes' => array(
+ 'user' => CAP_ALLOW
+ ),
+
+ 'clonepermissionsfrom' => 'moodle/my:manageblocks'
+ ),
+
+ 'block/workflow_diagram:addinstance' => array(
+ 'riskbitmask' => RISK_SPAM | RISK_XSS,
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_BLOCK,
+ 'archetypes' => array(
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW
+ ),
+
+ 'clonepermissionsfrom' => 'moodle/site:manageblocks'
+ ),
+);
diff --git a/blocks/workflow_diagram/db/install.xml b/blocks/workflow_diagram/db/install.xml
new file mode 100644
index 0000000..eed6ff5
--- /dev/null
+++ b/blocks/workflow_diagram/db/install.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/blocks/workflow_diagram/db/upgrade.php b/blocks/workflow_diagram/db/upgrade.php
new file mode 100644
index 0000000..f16ce8e
--- /dev/null
+++ b/blocks/workflow_diagram/db/upgrade.php
@@ -0,0 +1,53 @@
+.
+
+/**
+ * This file keeps track of upgrades to the workflow diagram block
+ *
+ * Sometimes, changes between versions involve alterations to database structures
+ * and other major things that may break installations.
+ *
+ * The upgrade function in this file will attempt to perform all the necessary
+ * actions to upgrade your older installation to the current version.
+ *
+ * If there's something it cannot do itself, it will tell you what you need to do.
+ *
+ * The commands in here will all be database-neutral, using the methods of
+ * database_manager class
+ *
+ * Please do not forget to use upgrade_set_timeout()
+ * before any action that may take longer time to finish.
+ *
+ * @since 2.0
+ * @package blocks
+ * @copyright 2010 Jerome Mouneyrac
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ *
+ * @param int $oldversion
+ * @param object $block
+ */
+function xmldb_block_workflow_diagram_upgrade($oldversion) {
+ global $CFG, $DB;
+
+ // Moodle v2.4.0 release upgrade line
+ // Put any upgrade step following this
+
+ return true;
+}
diff --git a/blocks/workflow_diagram/graphview.php b/blocks/workflow_diagram/graphview.php
new file mode 100644
index 0000000..fe99c79
--- /dev/null
+++ b/blocks/workflow_diagram/graphview.php
@@ -0,0 +1,98 @@
+.
+
+/**
+ * Shows information and the diagram
+ *
+ * @package blocks
+ * @subpackage workflow_diagram
+ * @author Sergi Rodríguez
+ * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once('../../config.php');
+require_once($CFG->dirroot . '/blocks/workflow_diagram/datalib.php');
+$wdmanager = new block_workflow_diagram_manager();
+
+global $DB, $OUTPUT, $PAGE;
+
+// Check for all required variables.
+$courseid = required_param('courseid', PARAM_INT);
+$blockid = required_param('blockid', PARAM_INT);
+
+// Next look for optional variables.
+$id = optional_param('id', 0, PARAM_INT);
+
+if (!$course = $DB->get_record('course', array('id' => $courseid))) {
+ print_error('invalidcourse', 'block_workflow_diagram', $courseid);
+}
+
+require_login($course);
+$PAGE->set_url('/blocks/workflow_diagram/graphview.php', array('id' => $courseid));
+$PAGE->set_title(get_string("pluginname", "block_workflow_diagram"));
+$PAGE->set_pagelayout('incourse');
+$PAGE->set_heading($course->fullname);
+
+$settingsnode = $PAGE->settingsnav->add(get_string('wfsettings', 'block_workflow_diagram'));
+$wfurl = new moodle_url('/blocks/workflow_diagram/graphview.php', array('id' => $id, 'courseid' => $courseid, 'blockid' => $blockid));
+$editnode = $settingsnode->add(get_string('graphview', 'block_workflow_diagram'), $wfurl);
+$editnode->make_active();
+
+//Printar header
+echo $OUTPUT->header();
+
+$i = 0;
+if (optional_param('nextweek', false, PARAM_BOOL) || optional_param('lastweek', false, PARAM_BOOL) && confirm_sesskey()) {
+ $i = optional_param('counter', false, PARAM_INTEGER);
+ if (optional_param('nextweek', false, PARAM_BOOL))
+ $i++;
+ elseif (optional_param('lastweek', false, PARAM_BOOL))
+ $i--;
+}
+ $formstart = '';
+ $formhiddennext = '';
+ $formhiddenlast = '';
+ $button1 = $formstart . $formhiddennext. '' . $formend;
+ $button2 = $formstart . $formhiddenlast. '' . $formend;
+
+//Print page
+if (ajaxenabled()) {
+
+ $result = $wdmanager->get_hoursperday_by_course_date($courseid, time());
+ echo html_writer::tag('div', get_string('todayworkload', 'block_workflow_diagram').$result.'
', array('id' => 'daylyhours'));
+
+ $time = time() + ($i * WEEKSECS);
+ $jsondata = $wdmanager->block_workflow_diagram_get_json_array_for_chart($courseid, $time);
+ echo html_writer::tag('div', get_string('weekdiagram', 'block_workflow_diagram'), array('id' => 'mychart')); //Equival a echo '';
+ $PAGE->requires->js_init_call('M.block_workflow_diagram.printgraph', array($jsondata));
+}
+else {
+ echo html_writer::tag('div', get_string('jsdisabled', 'block_workflow_diagram'), array('id' => 'mychart')); //Div que conté la gràfica
+}
+
+ echo html_writer::tag('div', '
'.$button2.'
'.$button1, array('id' => 'buttons'));
+ //echo html_writer::tag('div', $button2, array('id' => 'buttons'));
+
+
+//Print moodle elements
+echo $OUTPUT->footer();
\ No newline at end of file
diff --git a/blocks/workflow_diagram/index.php b/blocks/workflow_diagram/index.php
new file mode 100644
index 0000000..ae06b3e
--- /dev/null
+++ b/blocks/workflow_diagram/index.php
@@ -0,0 +1,238 @@
+.
+
+/**
+ * Edition page for the workflow block
+ *
+ * @package blocks
+ * @subpackage workflow_diagram
+ * @author Ivan Latorre Negrell
+ * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+require_once("../../config.php");
+
+$id = required_param('id', PARAM_INT); // Course ID
+
+$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
+require_login($course);
+$PAGE->set_url('/mod/assign/index.php', array('id' => $id));
+$PAGE->set_pagelayout('incourse');
+
+// You need moodle/course:manageactivities in addition to question capabilities to access this page.
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
+require_capability('moodle/course:manageactivities', $context);
+
+// Print the header
+$strworkflow = get_string("pluginname", "block_workflow_diagram");
+$PAGE->navbar->add($strworkflow);
+$PAGE->set_title($strworkflow);
+$PAGE->set_heading($course->fullname);
+echo $OUTPUT->header();
+
+require_once($CFG->dirroot . '/blocks/workflow_diagram/datalib.php');
+$wdmanager = new block_workflow_diagram_manager();
+
+// Look if the buttons create, update or delete have been pressed.
+if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
+ $cmid = optional_param('cmid', false, PARAM_INT);
+ $inidateday = optional_param('initialdateday', false, PARAM_RAW);
+ $inidatemonth = optional_param('initialdatemonth', false, PARAM_RAW);
+ $inidateyear = optional_param('initialdateyear', false, PARAM_RAW);
+ $enddateday = optional_param('finaldateday', false, PARAM_RAW);
+ $enddatemonth = optional_param('finaldatemonth', false, PARAM_RAW);
+ $enddateyear = optional_param('finaldateyear', false, PARAM_RAW);
+ $hours = optional_param('hours', 0, PARAM_INT);
+
+ $inidate = make_timestamp($inidateyear, $inidatemonth, $inidateday);
+ $enddate = make_timestamp($enddateyear, $enddatemonth, $enddateday);
+
+ if ($hours === "" || ($enddate-$inidate)<0) {
+ echo get_string('editerror', 'block_workflow_diagram');
+ } else {
+ $period = abs($enddate - $inidate);
+ if ($period = floor($period / DAYSECS)) {
+ $hoursperday = round($hours / $period, 2);
+ } else {
+ $hoursperday = 0;
+ }
+ $wdmanager->add_modify_workflow_diagram_add_or_modify_instance($cmid, $inidate, $enddate, $hours, $hoursperday);
+ }
+} else if (optional_param('delete', false, PARAM_BOOL) && confirm_sesskey()) {
+ $cmid = optional_param('cmid', false, PARAM_INT);
+ $wdmanager->block_workflow_diagram_remove_instance($cmid);
+}
+
+$formstart = '';
+$formhiddensave = '
+ ';
+$formhiddendelete = '
+ ';
+
+//Array with all the activities
+$activitiesarray = array('assign', 'chat', 'choice', 'data', 'forum', 'glossary', 'lesson',
+ 'lti', 'quiz', 'scorm', 'survey', 'wiki', 'workshop');
+
+$noactivities = true;
+
+//Print a table for each activity
+for ($i = 0; $i < 13; $i++) {
+ $stractivities = get_string("modulenameplural", $activitiesarray[$i]);
+ $activities = get_all_instances_in_course($activitiesarray[$i], $course);
+ if ($activities) {
+ $nodatefields = false;
+ $strtime1 = 'nothing';
+ $strtime2 = 'nothing';
+ $time1 = 'nothing';
+ $time2 = 'nothing';
+ if($activitiesarray[$i] === 'quiz'){
+ $strtime1 = 'quizopens';
+ $strtime2 = 'quizcloses';
+ $time1 = 'timeopen';
+ $time2 = 'timeclose';
+ }else if($activitiesarray[$i] === 'assign'){
+ $strtime1 = 'allowsubmissionsfromdate';
+ $strtime2 = 'duedate';
+ $time1 = 'allowsubmissionsfromdate';
+ $time2 = 'duedate';
+ }else if($activitiesarray[$i] === 'forum'){
+ $nodatefields = true;
+ }else if($activitiesarray[$i] === 'data'){
+ $strtime1 = 'availablefromdate';
+ $strtime2 = 'availabletodate';
+ $time1 = 'timeavailablefrom';
+ $time2 = 'timeavailableto';
+ }else if($activitiesarray[$i] === 'lti'){
+ $nodatefields = true;
+ }else if($activitiesarray[$i] === 'chat'){
+ $nodatefields = true;
+ }else if($activitiesarray[$i] === 'choice'){
+ $strtime1 = 'choiceopen';
+ $strtime2 = 'choiceclose';
+ $time1 = 'timeopen';
+ $time2 = 'timeclose';
+ }else if($activitiesarray[$i] === 'survey'){
+ $nodatefields = true;
+ }else if($activitiesarray[$i] === 'glossary'){
+ $nodatefields = true;
+ }else if($activitiesarray[$i] === 'lesson'){
+ $strtime1 = 'lessonopens';
+ $strtime2 = 'lessoncloses';
+ $time1 = 'available';
+ $time2 = 'deadline';
+ }else if($activitiesarray[$i] === 'workshop'){
+ $nodatefields = true;
+ }else if($activitiesarray[$i] === 'wiki'){
+ $nodatefields = true;
+ }else if($activitiesarray[$i] === 'scorm'){
+ $strtime1 = 'scormopen';
+ $strtime2 = 'duedate';
+ $time1 = 'timeopen';
+ $time2 = 'timeclose';
+ }
+
+ $table = new html_table();
+ if($nodatefields){
+ $table->head = array($stractivities, get_string('startdate', 'block_workflow_diagram'),
+ get_string('enddate', 'block_workflow_diagram'), get_string('hoursofwork', 'block_workflow_diagram'),
+ get_string('save', 'block_workflow_diagram') . " " . get_string('workflow', 'block_workflow_diagram'),
+ get_string('delete', 'block_workflow_diagram') . " " . get_string('workflow', 'block_workflow_diagram'));
+ $table->align = array('left', 'left', 'left', 'left', 'center', 'center');
+ }else{
+ $table->head = array($stractivities, get_string($strtime1, $activitiesarray[$i]),
+ get_string($strtime2, $activitiesarray[$i]), get_string('startdate', 'block_workflow_diagram'),
+ get_string('enddate', 'block_workflow_diagram'), get_string('hoursofwork', 'block_workflow_diagram'),
+ get_string('save', 'block_workflow_diagram') . " " . get_string('workflow', 'block_workflow_diagram'),
+ get_string('delete', 'block_workflow_diagram') . " " . get_string('workflow', 'block_workflow_diagram'));
+ $table->align = array('left', 'left', 'left', 'left', 'left', 'left', 'center', 'center');
+ }
+ $table->data = array();
+ foreach ($activities as $activity) {
+ $cm = get_coursemodule_from_instance($activitiesarray[$i], $activity->id, 0, false, MUST_EXIST);
+ $formhiddencm = '';
+
+ $link = $formstart . html_writer::link(new moodle_url('/mod/'.$activitiesarray[$i].'/view.php', array('id' => $cm->id)), $activity->name);
+ if(!$nodatefields){
+ $date1 = '-';
+ if ($activity->$time1) {
+ $date1 = userdate($activity->$time1);
+ }
+ $date2 = '-';
+ if ($activity->$time2) {
+ $date2 = userdate($activity->$time2);
+ }
+ }
+
+ if (!$wf = $wdmanager->block_workflow_diagram_get_instance($cm->id)) {
+ $inidate = html_writer::select_time('days', 'initialdateday').
+ html_writer::select_time('months', 'initialdatemonth').
+ html_writer::select_time('years', 'initialdateyear');
+ $enddate = html_writer::select_time('days', 'finaldateday').
+ html_writer::select_time('months', 'finaldatemonth').
+ html_writer::select_time('years', 'finaldateyear');
+ if(!$nodatefields){
+ if ($activity->$time1) {
+ $inidate = html_writer::select_time('days', 'initialdateday', $activity->$time1).
+ html_writer::select_time('months', 'initialdatemonth', $activity->$time1).
+ html_writer::select_time('years', 'initialdateyear', $activity->$time1);
+ }
+ if ($activity->$time2) {
+ $enddate = html_writer::select_time('days', 'finaldateday', $activity->$time2).
+ html_writer::select_time('months', 'finaldatemonth', $activity->$time2).
+ html_writer::select_time('years', 'finaldateyear', $activity->$time2);
+ }
+ }
+
+ $hours = '';
+
+ $boton = $formhiddensave . $formhiddencm . '' . $formend;
+ $delete = '';
+ } else {
+ $inidate = html_writer::select_time('days', 'initialdateday', $wf->startdate).
+ html_writer::select_time('months', 'initialdatemonth', $wf->startdate).
+ html_writer::select_time('years', 'initialdateyear', $wf->startdate);
+ $enddate = html_writer::select_time('days', 'finaldateday', $wf->finishdate).
+ html_writer::select_time('months', 'finaldatemonth', $wf->finishdate).
+ html_writer::select_time('years', 'finaldateyear', $wf->finishdate);
+ $hours = '';
+ $boton = $formhiddensave . $formhiddencm . '' . $formend;
+ $delete = $formstart . $formhiddendelete . $formhiddencm . '' . $formend;
+ }
+
+ if ($nodatefields)
+ $row = array($link, $inidate, $enddate, $hours, $boton, $delete);
+ else
+ $row = array($link, $date1, $date2, $inidate, $enddate, $hours, $boton, $delete);
+
+ $table->data[] = $row;
+ }
+
+ echo html_writer::table($table);
+
+ $noactivities = false;
+ }
+}
+
+//If there isn't any activity
+if ($noactivities) {
+ notice(get_string('thereareno', 'moodle', $stractivities), "../../course/view.php?id=$course->id");
+ die;
+}
+
+echo $OUTPUT->footer();
+
diff --git a/blocks/workflow_diagram/lang/en/block_workflow_diagram.php b/blocks/workflow_diagram/lang/en/block_workflow_diagram.php
new file mode 100644
index 0000000..5293304
--- /dev/null
+++ b/blocks/workflow_diagram/lang/en/block_workflow_diagram.php
@@ -0,0 +1,47 @@
+.
+
+/**
+ * Strings for component 'block_news_items', language 'en', branch 'MOODLE_20_STABLE'
+ *
+ * @package block_news_items
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['news_items:addinstance'] = 'Add a new workflow diagram block';
+$string['news_items:myaddinstance'] = 'Add a new navigation block to the My Moodle page';
+$string['pluginname'] = 'Workflow Diagram';
+$string['save'] = 'Save';
+$string['create'] = 'Create';
+$string['update'] = 'Update';
+$string['delete'] = 'Delete';
+$string['startdate'] = 'Start date';
+$string['enddate'] = 'End date';
+$string['hoursofwork'] = 'Hours of work';
+$string['workflow'] = 'workflow';
+$string['editwf'] = 'Edit workflow';
+$string['viewgraphic'] = 'View diagram';
+$string['wfsettings'] = 'WfD Settings';
+$string['graphview'] = 'WfD: Diagram view';
+$string['invalidcourse'] = 'Invalid course';
+$string['jsdisabled'] = 'Error: Javascript is disabled';
+$string['todayworkload'] = 'Today\'s workload: ';
+$string['weekdiagram'] = 'Workload distribution:';
+$string['next'] = 'Next week';
+$string['last'] = 'Last week';
+$string['editerror'] = 'Hours fild empty or start date bigger than finish date.';
diff --git a/blocks/workflow_diagram/lang/es/block_workflow_diagram.php b/blocks/workflow_diagram/lang/es/block_workflow_diagram.php
new file mode 100644
index 0000000..5a08928
--- /dev/null
+++ b/blocks/workflow_diagram/lang/es/block_workflow_diagram.php
@@ -0,0 +1,47 @@
+.
+
+/**
+ * Strings for component 'block_news_items', language 'es', branch 'MOODLE_20_STABLE'
+ *
+ * @package block_news_items
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['news_items:addinstance'] = 'Añadir un nuevo bloque de diagrama de flujo de trabajo';
+$string['news_items:myaddinstance'] = 'Add a new navigation block to the My Moodle page';
+$string['pluginname'] = 'Diagrama del flujo de trabajo';
+$string['save'] = 'Guardar';
+$string['create'] = 'Crear';
+$string['update'] = 'Actualizar';
+$string['delete'] = 'Eliminar';
+$string['startdate'] = 'Fecha de inicio';
+$string['enddate'] = 'Fecha final';
+$string['hoursofwork'] = 'Horas de trabajo';
+$string['workflow'] = 'Flujo de trabajo';
+$string['editwf'] = 'Editar carga de trabajo';
+$string['viewgraphic'] = 'Ver diagrama';
+$string['wfsettings'] = 'Ajustes de WfD';
+$string['graphview'] = 'WfD: Diagrama';
+$string['invalidcourse'] = 'Curso no adecuado';
+$string['jsdisabled'] = 'Error: Javascript está desactivado';
+$string['todayworkload'] = 'Carga de trabajo para hoy: ';
+$string['weekdiagram'] = 'Distribución de carga de trabajo: ';
+$string['next'] = 'Siguiente semana';
+$string['last'] = 'Anterior semana';
+$string['editerror'] = 'Campo de horas vacío o fecha de inicio mayor a la de final.';
\ No newline at end of file
diff --git a/blocks/workflow_diagram/module.js b/blocks/workflow_diagram/module.js
new file mode 100644
index 0000000..7f9db53
--- /dev/null
+++ b/blocks/workflow_diagram/module.js
@@ -0,0 +1,41 @@
+
+M.block_workflow_diagram = {
+
+ Y : null,
+ transaction : [],
+
+ printgraph : function(Y, params){
+ this.Y = Y;
+
+ YUI().use('charts', function (Y) {
+
+ //Get data from JSON string parameter
+ var data = eval('(' + params + ')');
+
+ var mychart = new Y.Chart({
+ dataProvider:data,
+ render:"#mychart", //Indica el on es mostrarà
+ type:"column", //Tipus de gràfica, es pot canviar
+ title: "Workflow Diagram",
+ stacked:true,
+ categoryKey:"date",
+ //categoryType:"time",
+
+ horizontalGridlines: {
+ styles: {
+ line: {
+ color: "#dad8c9"
+ }
+ }
+ },
+ verticalGridlines: {
+ styles: {
+ line: {
+ color: "#dad8c9"
+ }
+ }
+ }
+ });
+ });
+ }
+}
\ No newline at end of file
diff --git a/blocks/workflow_diagram/styles.css b/blocks/workflow_diagram/styles.css
new file mode 100644
index 0000000..d948cf1
--- /dev/null
+++ b/blocks/workflow_diagram/styles.css
@@ -0,0 +1,5 @@
+
+#mychart {
+ width: 600px;
+ height: 400px;
+}
\ No newline at end of file
diff --git a/blocks/workflow_diagram/version.php b/blocks/workflow_diagram/version.php
new file mode 100644
index 0000000..1d009c3
--- /dev/null
+++ b/blocks/workflow_diagram/version.php
@@ -0,0 +1,30 @@
+.
+
+/**
+ * Version details
+ *
+ * @package block
+ * @subpackage news_items
+ * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$plugin->version = 2012112100; // The current plugin version (Date: YYYYMMDDXX)
+$plugin->requires = 2012061700; // Requires this Moodle version
+$plugin->component = 'block_workflow_diagram'; // Full name of the plugin (used for diagnostics)