Browse Source

Initial commit

2021092200_STABLE
Sesostris Vieira 3 years ago
parent
commit
09a171ec1e
  1. 20
      README.md
  2. 54
      backup/moodle2/backup_palestra_activity_task.class.php
  3. 62
      backup/moodle2/backup_palestra_stepslib.php
  4. 39
      classes/event/course_module_viewed.php
  5. 71
      classes/task/grade_participation_task.php
  6. 52
      db/access.php
  7. 42
      db/install.xml
  8. 38
      db/tasks.php
  9. 28
      db/upgrade.php
  10. 115
      grade.php
  11. 95
      index.php
  12. 56
      lang/en/palestra.php
  13. 56
      lang/pt_br/palestra.php
  14. 365
      lib.php
  15. 79
      mod_form.php
  16. BIN
      pix/download.jpeg
  17. BIN
      pix/icon.png
  18. 36
      presence.php
  19. 81
      presences.php
  20. 40
      settings.php
  21. 30
      version.php
  22. 150
      view.php

20
README.md

@ -1 +1,19 @@
# moodle-mod_palestra # Palestra moodle plugin
This module allows creating **Youtube stream palestra** sessions fully integrated in Moodle. Youtube streams can embeded with or without youtube chat.
The time spended in palestra will be computed as grade in gradebook.
## Some module configuration options:
- **Youtube stream code**: Set the Youtube stream code be used here. This code
is the final characters in a Youtube URL.
e.g.: To the youtube url https://youtu.be/3ORsUGVNxGs the code is 3ORsUGVNxGs.
- **Include youtube chat**: Indicates whether Youtube chat should be included on
the page.
- **Chat disposition**: Choose how you want to display the Youtube chat. Options
are Side by side or stacked.
- **Start date**: The moment from which attendance must be registered.
- **Duration**: Attendance duration in minutes.
- **Grade after end of palestra**: Continue grading participation even after the
end of palestra transmission.
- **Check interval**: Indicates the time interval (in minutes) that the user's
browser sends a 'sign of life' to the moodle server.

54
backup/moodle2/backup_palestra_activity_task.class.php

@ -0,0 +1,54 @@
<?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 {@link backup_palestra_activity_task} class
*
* @package mod_palestra
* @category backup
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/palestra/backup/moodle2/backup_palestra_stepslib.php');
class backup_palestra_activity_task extends backup_activity_task {
protected function define_my_settings() {
}
protected function define_my_steps() {
$this->add_step(new backup_palestra_activity_structure_step('palestra_structure', 'palestra.xml'));
}
static public function encode_content_links($content) {
global $CFG;
$base = preg_quote($CFG->wwwroot,"/");
// Link to the list of palestras
$search = "/(" . $base . "\/mod\/palestra\/index.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@PALESTRAINDEX*$2@$', $content);
//Link to palestra view by moduleid
$search = "/(" . $base . "\/mod\/palestra\/view.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@PALESTRAVIEWBYID*$2@$', $content);
return $content;
}
}

62
backup/moodle2/backup_palestra_stepslib.php

@ -0,0 +1,62 @@
<?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 all the backup steps that will be used by {@link backup_palestra_activity_task}
*
* @package mod_palestra
* @category backup
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Defines the complete palestra structure for backup, with file and id annotations
*
*/
class backup_palestra_activity_structure_step extends backup_activity_structure_step {
/**
* Defines the structure of the 'palestra' element inside the palestra.xml file
*
* @return backup_nested_element
*/
protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');
$palestra = new backup_nested_element('palestra', array('id'), array(
'name', 'intro', 'introformat', 'youtubecode', 'includechat',
'grade', 'duration', 'checkinterval', 'timemodified'));
$presence = new backup_nested_element('palestra_presence', array('id'),
array('palestraid', 'userid', 'starttime', 'lastcheck'));
$palestra->add_child($presence);
$palestra->set_source_table('palestra', array('id' => backup::VAR_ACTIVITYID));
$presence->set_source_sql("
SELECT *
FROM {palestra_presence}
WHERE palestraid = ?",
array(backup::VAR_PARENTID));
$presence->annotate_ids('user', 'userid');
return $this->prepare_activity_structure($palestra);
}
}

39
classes/event/course_module_viewed.php

@ -0,0 +1,39 @@
<?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_palestra course module viewed event.
*
* @package mod_palestra
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_palestra\event;
defined('MOODLE_INTERNAL') || die();
class course_module_viewed extends \core\event\course_module_viewed {
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
$this->data['objecttable'] = 'palestra';
}
public static function get_objectid_mapping() {
return array('db' => 'palestra', 'restore' => 'palestra');
}
}

71
classes/task/grade_participation_task.php

@ -0,0 +1,71 @@
<?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/>.
/**
* A scheduled task for workshop cron.
*
* @package mod_workshop
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_palestra\task;
use stdClass;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/mod/palestra/lib.php');
require_once($CFG->dirroot.'/course/modlib.php');
class grade_participation_task extends \core\task\scheduled_task {
public function get_name() {
return get_string('grade_participation_task', 'mod_palestra');
}
public function execute() {
global $DB;
$now = time();
//#TODO: gradeafter
$palestras = $DB->get_records_sql("
select p.id, p.course, p.name, p.startdate, p.duration, p.checkinterval
from {palestra} p
inner join {palestra_presence} pp on pp.palestraid = p.id
inner join {course} c on c.id = p.course
where
(p.needsupdate = 1) and
(c.visible = 1) and
((c.startdate <= ?) and (c.enddate = 0 or c.enddate >= ?))
and ((p.startdate + (p.duration*60)) < ?)
group by p.id, p.course, p.name, p.startdate, p.duration, p.checkinterval
having max(pp.lastcheck) < ? - p.checkinterval*60
", [$now, $now, $now, $now]);
mtrace(count($palestras)." palestras to grade...");
foreach ($palestras as $palestra) {
mtrace("\tGrading participation on palestra {$palestra->name}...");
$grading_info = grade_get_grades($palestra->course, 'mod', 'palestra', $palestra->id);
$cm = get_coursemodule_from_instance('palestra', $palestra->id, $palestra->course, false, MUST_EXIST);
$palestra->grade = $grading_info->items[0]->grademax;
$palestra->cmidnumber = $cm->id;
palestra_update_grades($palestra);
mtrace("\tParticipation on palestra {$palestra->name} graded!");
}
}
}

52
db/access.php

@ -0,0 +1,52 @@
<?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/>.
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'mod/palestra:addinstance' => array(
'riskbitmask' => RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/course:manageactivities'
),
'mod/palestra:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
'mod/palestra:viewpresences' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'student' => CAP_PROHIBIT,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),
);

42
db/install.xml

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/palestra/db" VERSION="20210619" COMMENT="XMLDB file for Moodle mod/palestra"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="palestra" COMMENT="Defines palestras">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="intro" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="youtubecode" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="includechat" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="chatdisposition" TYPE="char" LENGTH="1" NOTNULL="true" DEFAULT="S" SEQUENCE="false"/>
<FIELD NAME="startdate" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="duration" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="gradeafter" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="checkinterval" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="10" SEQUENCE="false"/>
<FIELD NAME="needsupdate" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for palestra"/>
</KEYS>
</TABLE>
<TABLE NAME="palestra_presence" COMMENT="Info about presence in palestras">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="palestraid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="starttime" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="lastcheck" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for palestra_presence"/>
<KEY NAME="palestra" TYPE="foreign" FIELDS="palestraid" REFTABLE="palestra" REFFIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>

38
db/tasks.php

@ -0,0 +1,38 @@
<?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/>.
/**
* Definition of Forum scheduled tasks.
*
* @package mod_palestra
* @category task
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tasks = array(
array(
'classname' => 'mod_palestra\task\grade_participation_task',
'blocking' => 0,
'minute' => '*',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*'
)
);

28
db/upgrade.php

@ -0,0 +1,28 @@
<?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_palestra
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
function xmldb_palestra_upgrade($oldversion) {
global $CFG;
return true;
}

115
grade.php

@ -0,0 +1,115 @@
<?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/>.
/**
* This page is the entry page into the quiz UI. Displays information about the
* quiz to students and teachers, and lets students see their previous attempts.
*
* @package mod_palestra
* @category grade
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once("lib.php");
$id = required_param('id', PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);
$cm = get_coursemodule_from_id('palestra', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$palestra = $DB->get_record('palestra', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, false, $cm);
if (!$userid && !has_capability('mod/palestra:viewpresences', $PAGE->cm->context)) {
$userid = $USER->id;
}
if ($userid) {
$userlist = array($userid);
$where = 'p.userid = '.$userid;
} else {
$userlist = $DB->get_fieldset_sql('select distinct userid from {palestra_presence} where palestraid = ? and userid not in ('.$CFG->siteadmins.')', [$palestra->id]);
$where = 'p.userid not in ('.$CFG->siteadmins.')';
}
$presences = $DB->get_records_sql(
"
select p.*, ".get_all_user_name_fields(true,'u')."
from {palestra_presence} p
inner join {user} u on u.id = p.userid
where p.palestraid = ? and
".$where, [$palestra->id]
);
$grading_info = grade_get_grades($course->id, 'mod', 'palestra', $palestra->id, $userlist);
$PAGE->set_url('/mod/lesson/grade.php', array('id'=>$cm->id));
$PAGE->set_title($course->shortname.': '.$palestra->name);
$PAGE->set_heading($course->fullname);
$PAGE->requires->jquery();
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('presence_report_title', 'palestra', ['name'=>format_string($palestra->name)]), 2);
echo "
<table class=\"table table-striped table-condensed\">
<thead>
<tr>
<th>".get_string('start', 'palestra')."</th>
<th>".get_string('last_signal', 'palestra')."</th>
<th>".get_string('stay_time', 'palestra')."<th>
</tr>
</thead>
<tbody>
";
$lastuser = null;
$stay_total = 0;
foreach ($presences as $presence) {
if ($lastuser != $presence->userid) {
echo "</tbody>";
if ($lastuser) {
$total_row = get_string('total_row', 'palestra', ['name'=>$fullname, 'stay'=>$stay_total, 'grade'=>$grading_info->items[0]->grades[$lastuser]->str_long_grade]);
echo "<thead><tr><th colspan=\"3\">{$total_row}</th></tr></thead>";
}
$fullname = fullname($presence);
echo "
<thead><tr><th colspan=\"3\">{$fullname}</th></tr></thead>
<tbody>
";
$lastuser = $presence->userid;
$stay_total = 0;
}
$stay = round(($presence->lastcheck - $presence->starttime) / 60);
$stay_total = $stay_total + $stay;
echo "
<tr>
<td>".userdate($presence->starttime, '%d/%m/%Y %H:%M:%S')."</td>
<td>".userdate($presence->lastcheck, '%d/%m/%Y %H:%M:%S')."</td>
<td>{$stay}</td></tr>";
}
echo "</tbody>";
if ($lastuser) {
$total_row = get_string('total_row', 'palestra', ['name'=>$fullname, 'stay'=>$stay_total, 'grade'=>$grading_info->items[0]->grades[$lastuser]->str_long_grade]);
echo "<thead><tr><th colspan=\"3\">{$total_row}</th></tr></thead>";
}
echo "</table>";
echo $OUTPUT->footer();

95
index.php

@ -0,0 +1,95 @@
<?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/>.
/**
* List of all palestras in course
*
* @package mod_palestra
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
$id = required_param('id', PARAM_INT); // course id
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_course_login($course, true);
$PAGE->set_pagelayout('incourse');
$strpalestra = get_string('modulename', 'palestra');
$strpalestras = get_string('modulenameplural', 'palestra');
$strname = get_string('name');
$strintro = get_string('moduleintro');
$strlastmodified = get_string('lastmodified');
$PAGE->set_url('/mod/palestra/index.php', array('id' => $course->id));
$PAGE->set_title($course->shortname.': '.$strpalestras);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strpalestras);
echo $OUTPUT->header();
echo $OUTPUT->heading($strpalestras);
if (!$palestras = get_all_instances_in_course('palestra', $course)) {
notice(get_string('thereareno', 'moodle', $strpalestras), "$CFG->wwwroot/course/view.php?id=$course->id");
exit;
}
$usesections = course_format_uses_sections($course->format);
$table = new html_table();
$table->attributes['class'] = 'generaltable mod_index';
if ($usesections) {
$strsectionname = get_string('sectionname', 'format_'.$course->format);
$table->head = array ($strsectionname, $strname, $strintro);
$table->align = array ('center', 'left', 'left');
} else {
$table->head = array ($strlastmodified, $strname, $strintro);
$table->align = array ('left', 'left', 'left');
}
$modinfo = get_fast_modinfo($course);
$currentsection = '';
foreach ($palestras as $palestra) {
$cm = $modinfo->cms[$palestra->coursemodule];
if ($usesections) {
$printsection = '';
if ($palestra->section !== $currentsection) {
if ($palestra->section) {
$printsection = get_section_name($course, $palestra->section);
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $palestra->section;
}
} else {
$printsection = '<span class="smallinfo">'.userdate($palestra->timemodified)."</span>";
}
$class = $palestra->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
$table->data[] = array (
$printsection,
"<a $class href=\"view.php?id=$cm->id\">".format_string($palestra->name)."</a>",
format_module_intro('palestra', $palestra, $cm->id));
}
echo html_writer::table($table);
echo $OUTPUT->footer();

56
lang/en/palestra.php

@ -0,0 +1,56 @@
<?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/>.
/**
* Strings for component 'palestra', language 'en'
*
* @package mod_palestra
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Palestra';
$string['modulename'] = 'Palestra';
$string['modulenameplural'] = 'Palestras';
$string['pluginadministration'] = 'Palestra administration';
$string['crontask'] = 'Schedule for palestra participation grade calculation';
$string['contentheader'] = 'Palestra settings';
$string['youtubecode'] = 'Youtube stream code';
$string['startdate'] = 'Start date';
$string['startdate_help'] = 'The moment from which attendance must be registered';
$string['duration'] = 'Duration';
$string['duration_help'] = 'Attendance duration in minutes';
$string['checkinterval'] = 'Check interval';
$string['checkinterval_help'] = "Indicates the time interval (in minutes) that the user's browser sends a 'sign of life' to the moodle server. This is used to calculate the user's time spent on the 'palestra' and, consequently, their participation grade. A lower value promotes better accuracy, but can overload the server, especially if you have many concurrent users. A higher value can decrease precision, but it makes the server lighter. The default value is 10 minutes. Zero indicates that no live signals will be sent and simple access to the Palestra will correspond to 100% participation grade.";
$string['includechat'] = 'Include youtube chat';
$string['chatdisposition'] = 'Chat disposition';
$string['chatdisposition_sidebyside'] = 'Side by side';
$string['chatdisposition_stacked'] = 'Stacked';
$string['includechat_help'] = 'If checked, the associated youtube chat will be displayed together the video area';
$string['presence_unregistered'] = 'Your presence is not being registered. Try to leave the palestra and enter again.';
$string['grade_participation_task'] = 'Grades the Palestra Participacion';
$string['out_of_date_alert'] = 'Your presence is not being counted because the activity has already ended. You can continue watching the content.';
$string['gradeafter'] = 'Grade after end of palestra';
$string['gradeafter_help'] = 'Continue grading participation even after the end of palestra transmission.';
$string['presence_report_title'] = 'Attendance report at {$a->name}';
$string['start'] = 'Start time';
$string['last_signal'] = 'Last live signal';
$string['stay_time'] = 'Stay time (minutes)';
$string['total_row'] = 'Total for {$a->name}: stay {$a->stay} minutes, grading {$a->grade}.';
$string['view_presences'] = 'View present users';
$string['presence_list_title'] = 'List of present users';
$string['presence_total'] = '{$a} present users';

56
lang/pt_br/palestra.php

@ -0,0 +1,56 @@
<?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/>.
/**
* Strings for component 'palestra', language 'en'
*
* @package mod_palestra
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Palestra';
$string['modulename'] = 'Palestra';
$string['modulenameplural'] = 'Palestras';
$string['pluginadministration'] = 'Administração de palestra';
$string['crontask'] = 'Cronograma para cálculo da nota de participação da palestra';
$string['contentheader'] = 'Configurações da palestra';
$string['youtubecode'] = 'Código de stream do Youtube';
$string['startdate'] = 'Data de início';
$string['startdate_help'] = 'O momento em que a presença deve começar a ser registrada';
$string['duration'] = 'Duração';
$string['duration_help'] = 'Duração da palestra em minutos';
$string['checkinterval'] = 'Intervalo de verificação';
$string['checkinterval_help'] = "Indica o intervalo de tempo (em minutos) que o browser do usário envia um 'sinal de vida' para o servidor moodle. Isto é usado para calcular o tempo que o usuário permaneceu na palestra e, consequentemente, sua nota de participação. Um valor baixo promove melhor precisão, mas pode sobrecarregar o servidor, especialmente se há muitos usuários simultâneos. Um valor alto pode reduzir a precisão, mas deixa o servidor mais leve. O valor default é 10 minutos. Zero indica que nenhum sinal de vida será enviado e o simples accesso à Palestra corresponderá a 100% de nota de participação.";
$string['includechat'] = 'Incluir chat do youtube';
$string['chatdisposition'] = 'Posição do chat';
$string['chatdisposition_sidebyside'] = 'Lado a lado';
$string['chatdisposition_stacked'] = 'Empilhado';
$string['includechat_help'] = 'Se marcado, o chat do youtube associado será mostrado próximo à área do vídeo';
$string['presence_unregistered'] = 'Sua presença não estã sendo registrada. Tente sair da palestra e entrar novamente.';
$string['grade_participation_task'] = 'Pontua a participação na palestra';
$string['out_of_date_alert'] = 'Sua presença não está sendo computada porque a atividade já terminou. Você pode continuar assistindo ao conteúdo.';
$string['gradeafter'] = 'Pontuar após o término da palestra';
$string['gradeafter_help'] = 'Continua pontuando a participação mesmo após o término da transmissão da palestra.';
$string['presence_report_title'] = 'Relatório de presença em {$a->name}';
$string['start'] = 'Início';
$string['last_signal'] = 'Último sinal de vida';
$string['stay_time'] = 'Tempo de permanência (minutos)';
$string['total_row'] = 'Total para {$a->name}: Permanência de {$a->stay} minutos, {$a->grade} pontos alcançados.';
$string['view_presences'] = 'Visualizar usuários presentes';
$string['presence_list_title'] = 'Lista de usuários presentes';
$string['presence_total'] = '{$a} usuários presentes';

365
lib.php

@ -0,0 +1,365 @@
<?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_palestra
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
function palestra_supports($feature) {
switch($feature) {
case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_ASSIGNMENT;
case FEATURE_GROUPS: return false;
case FEATURE_GROUPINGS: return false;
case FEATURE_MOD_INTRO: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
case FEATURE_COMPLETION_HAS_RULES: return true;
case FEATURE_GRADE_HAS_GRADE: return true;
case FEATURE_BACKUP_MOODLE2: return true;
case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
}
function palestra_reset_userdata($data) {
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
// See MDL-9367.
return array();
}
function palestra_get_view_actions() {
return array('view','view all');
}
function palestra_get_post_actions() {
return array('update', 'add');
}
function palestra_add_instance($palestra, $mform = null) {
global $CFG, $DB;
require_once("$CFG->libdir/resourcelib.php");
$cmid = $palestra->coursemodule;
$palestra->timemodified = time();
$palestra->needsupdate = 1;
$palestra->id = $DB->insert_record('palestra', $palestra);
$DB->set_field('course_modules', 'instance', $palestra->id, array('id'=>$cmid));
$context = context_module::instance($cmid);
palestra_grade_item_update($palestra);
$completiontimeexpected = !empty($palestra->completionexpected) ? $palestra->completionexpected : null;
\core_completion\api::update_completion_date_event($cmid, 'palestra', $palestra->id, $completiontimeexpected);
return $palestra->id;
}
function palestra_update_instance($palestra, $mform) {
global $CFG, $DB;
require_once("$CFG->libdir/resourcelib.php");
$cmid = $palestra->coursemodule;
$palestra->timemodified = time();
$palestra->needsupdate = 1;
$palestra->id = $palestra->instance;
$DB->update_record('palestra', $palestra);
palestra_grade_item_update($palestra);
$completiontimeexpected = !empty($palestra->completionexpected) ? $palestra->completionexpected : null;
\core_completion\api::update_completion_date_event($cmid, 'palestra', $palestra->id, $completiontimeexpected);
return true;
}
function palestra_delete_instance($id) {
global $DB;
if (!$palestra = $DB->get_record('palestra', array('id'=>$id))) {
return false;
}
$cm = get_coursemodule_from_instance('palestra', $id);
\core_completion\api::update_completion_date_event($cm->id, 'palestra', $id, null);
$DB->delete_records('palestra', array('id'=>$palestra->id));
$DB->delete_records('palestra_presence', array('palestraid'=>$palestra->id));
return true;
}
function palestra_get_coursemodule_info($coursemodule) {
global $CFG, $DB;
require_once("$CFG->libdir/resourcelib.php");
if (!$palestra = $DB->get_record('palestra', array('id'=>$coursemodule->instance))) {
return NULL;
}
$info = new cached_cm_info();
$info->name = $palestra->name;
if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
$info->content = format_module_intro('palestra', $palestra, $coursemodule->id, false);
}
return $info;
}
function palestra_view($palestra, $course, $cm, $context) {
$params = array(
'context' => $context,
'objectid' => $palestra->id
);
$event = \mod_palestra\event\course_module_viewed::create($params);
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('palestra', $palestra);
$event->trigger();
// Completion.
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
}
function mod_palestra_core_calendar_provide_event_action(calendar_event $event,
\core_calendar\action_factory $factory, $userid = 0) {
global $USER;
if (empty($userid)) {
$userid = $USER->id;
}
$cm = get_fast_modinfo($event->courseid, $userid)->instances['palestra'][$event->instance];
$completion = new \completion_info($cm->get_course());
$completiondata = $completion->get_data($cm, false, $userid);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/palestra/view.php', ['id' => $cm->id]),
1,
true
);
}
function palestra_grade_item_update($palestra, $grades=NULL) {
global $CFG;
if (!function_exists('grade_update')) { //workaround for buggy PHP versions
require_once($CFG->libdir.'/gradelib.php');
}
$params = array('itemname'=>$palestra->name, 'idnumber'=>$palestra->cmidnumber, 'needsupdate'=>1);
if ($palestra->grade == 0) {
$params['gradetype'] = GRADE_TYPE_NONE;
} else if ($palestra->grade > 0) {
$params['gradetype'] = GRADE_TYPE_VALUE;
$params['grademax'] = $palestra->grade;
$params['grademin'] = 0;
} else if ($palestra->grade < 0) {
$params['gradetype'] = GRADE_TYPE_SCALE;
$params['scaleid'] = -$palestra->grade;
}
if ($grades === 'reset') {
$params['reset'] = true;
$grades = NULL;
}
return grade_update('mod/palestra', $palestra->course, 'mod', 'palestra', $palestra->id, 0, $grades, $params);
}
function palestra_update_grades($palestra, $userid=0, $nullifnone=true) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
if ($userid) {
$presences = $DB->get_records("palestra_presence", array("palestraid"=>$palestra->id, "userid"=>$userid), 'userid, starttime, lastcheck');
} else {
$presences = $DB->get_records("palestra_presence", array("palestraid"=>$palestra->id), 'userid, starttime, lastcheck');
}
$audiences = array();
$minimal = $palestra->checkinterval * 60;
$user = null;
foreach($presences as $presence) {
# Compute only after palestra starts
if ($presence->starttime < $palestra->startdate) {
$presence->starttime = $palestra->startdate;
}
if ($user != $presence->userid) {
if ($user) {
$audiences[$user] = (isset($audiences[$user])?$audiences[$user]:0) + (max($end - $start, $minimal)/60);
}
$user = $presence->userid;
$start = $presence->starttime;
$end = $presence->lastcheck;
continue;
}
if ($presence->starttime < ($start + $minimal)) {
$end = $presence->lastcheck;
} else {
$audiences[$user] = (isset($audiences[$user])?$audiences[$user]:0) + (max($end - $start, $minimal)/60);
$start = $presence->starttime;
$end = $presence->lastcheck;
}
}
if ($user) {
$audiences[$user] = (isset($audiences[$user])?$audiences[$user]:0) + (max($end - $start, $minimal)/60);
}
$grades = array();
foreach($audiences as $userid=>$presence_time) {
$presence_rate = $presence_time / $palestra->duration;
if ($presence_rate > 1.0) {
$presence_rate = 1.0;
}
$grade = new stdclass();
$grade->userid = $userid;
$grade->rawgrade = grade_floatval($palestra->grade * $presence_rate);
$grade->datesubmitted = $palestra->startdate;
$grade->dategraded = $palestra->startdate;
$grades[$userid] = $grade;
}
palestra_grade_item_update($palestra, $grades);
$DB->set_field('palestra', 'needsupdate', 0, array('id'=>$palestra->id));
}
function palestra_reset_gradebook($courseid, $type='') {
global $CFG, $DB;
$wheresql = '';
$params = array($courseid);
if ($type) {
$wheresql = "AND p.type=?";
$params[] = $type;
}
$sql = "SELECT p.*, cm.idnumber as cmidnumber, p.course as courseid
FROM {palestra} p, {course_modules} cm, {modules} m
WHERE m.name='palestra' AND m.id=cm.module AND cm.instance=p.id AND p.course=? $wheresql";
if ($palestras = $DB->get_records_sql($sql, $params)) {
foreach ($palestras as $palestra) {
palestra_grade_item_update($palestra, 'reset');
}
}
}
function palestra_get_user_grades($palestra, $userid = 0) {
global $CFG;
require_once($CFG->dirroot.'/rating/lib.php');
$ratingoptions = new stdClass;
$ratingoptions->component = 'mod_palestra';
$ratingoptions->ratingarea = 'post';
//need these to work backwards to get a context id. Is there a better way to get contextid from a module instance?
$ratingoptions->modulename = 'palestra';
$ratingoptions->moduleid = $palestra->id;
$ratingoptions->userid = $userid;
$ratingoptions->aggregationmethod = $palestra->assessed;
$ratingoptions->scaleid = $palestra->scale;
$ratingoptions->itemtable = 'palestra_posts';
$ratingoptions->itemtableusercolumn = 'userid';
$rm = new rating_manager();
return $rm->get_user_grades($ratingoptions);
}
function palestra_extend_settings_navigation($settings, $palestranode) {
global $PAGE, $CFG;
// We want to add these new nodes after the Edit settings node, and before the
// Locally assigned roles node. Of course, both of those are controlled by capabilities.
$keys = $palestranode->get_children_key_list();
$beforekey = null;
$i = array_search('modedit', $keys);
if ($i === false and array_key_exists(0, $keys)) {
$beforekey = $keys[0];
} else if (array_key_exists($i + 1, $keys)) {
$beforekey = $keys[$i + 1];
}
if (has_capability('mod/palestra:viewpresences', $PAGE->cm->context)) {
$url = new moodle_url('/mod/palestra/presences.php', array('cmid'=>$PAGE->cm->id));
$node = navigation_node::create(get_string('view_presences', 'palestra'),
$url,
navigation_node::TYPE_SETTING, null, 'mod_palestra_viewpresences');
$palestranode->add_node($node, $beforekey);
}
// if (has_capability('mod/quiz:manage', $PAGE->cm->context)) {
// $node = navigation_node::create(get_string('editquiz', 'quiz'),
// new moodle_url('/mod/quiz/edit.php', array('cmid'=>$PAGE->cm->id)),
// navigation_node::TYPE_SETTING, null, 'mod_quiz_edit',
// new pix_icon('t/edit', ''));
// $quiznode->add_node($node, $beforekey);
// }
// if (has_capability('mod/quiz:preview', $PAGE->cm->context)) {
// $url = new moodle_url('/mod/quiz/startattempt.php',
// array('cmid'=>$PAGE->cm->id, 'sesskey'=>sesskey()));
// $node = navigation_node::create(get_string('preview', 'quiz'), $url,
// navigation_node::TYPE_SETTING, null, 'mod_quiz_preview',
// new pix_icon('i/preview', ''));
// $quiznode->add_node($node, $beforekey);
// }
// if (has_any_capability(array('mod/quiz:viewreports', 'mod/quiz:grade'), $PAGE->cm->context)) {
// require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
// $reportlist = quiz_report_list($PAGE->cm->context);
// $url = new moodle_url('/mod/quiz/report.php',
// array('id' => $PAGE->cm->id, 'mode' => reset($reportlist)));
// $reportnode = $quiznode->add_node(navigation_node::create(get_string('results', 'quiz'), $url,
// navigation_node::TYPE_SETTING,
// null, null, new pix_icon('i/report', '')), $beforekey);
// foreach ($reportlist as $report) {
// $url = new moodle_url('/mod/quiz/report.php',
// array('id' => $PAGE->cm->id, 'mode' => $report));
// $reportnode->add_node(navigation_node::create(get_string($report, 'quiz_'.$report), $url,
// navigation_node::TYPE_SETTING,
// null, 'quiz_report_' . $report, new pix_icon('i/item', '')));
// }
// }
// question_extend_settings_navigation($quiznode, $PAGE->cm->context)->trim_if_empty();
}

79
mod_form.php

@ -0,0 +1,79 @@
<?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/>.
/**
* palestra configuration form
*
* @package mod_palestra
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/course/moodleform_mod.php');
require_once($CFG->libdir.'/filelib.php');
class mod_palestra_mod_form extends moodleform_mod {
function definition() {
global $CFG, $DB;
$mform = $this->_form;
$config = get_config('palestra');
$mform->addElement('header', 'general', get_string('general', 'form'));
$mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEANHTML);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$this->standard_intro_elements();
$mform->addElement('header', 'contentsection', get_string('contentheader', 'palestra'));
$mform->addElement('text', 'youtubecode', get_string('youtubecode', 'palestra'), array('size'=>'48'));
$mform->setType('youtubecode', PARAM_TEXT);
$mform->addRule('youtubecode', null, 'required', null, 'client');
$mform->addRule('youtubecode', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addElement('advcheckbox', 'includechat', get_string('includechat', 'palestra'));
$mform->addElement('select', 'chatdisposition', get_string('chatdisposition', 'palestra'), array('S'=>get_string('chatdisposition_sidebyside', 'palestra'), 'T'=>get_string('chatdisposition_stacked', 'palestra')));
$mform->disabledIf('chatdisposition', 'includechat', 'notchecked', '1');
$mform->setDefault('includechat', $config->includechat);
$mform->addHelpButton('includechat', 'includechat', 'palestra');
$mform->addElement('date_time_selector', 'startdate', get_string('startdate', 'palestra'), array('size'=>'10'));
$mform->setType('startdate', PARAM_INT);
$mform->addRule('startdate', null, 'required', null, 'client');
$mform->addHelpButton('startdate', 'startdate', 'palestra');
$mform->addElement('text', 'duration', get_string('duration', 'palestra'), array('size'=>'10'));
$mform->setType('duration', PARAM_INT);
$mform->addRule('duration', null, 'required', null, 'client');
$mform->addHelpButton('duration', 'duration', 'palestra');
$mform->addElement('checkbox', 'gradeafter', get_string('gradeafter', 'palestra'));
$mform->setDefault('gradeafter', $config->gradeafter);
$mform->addHelpButton('gradeafter', 'gradeafter', 'palestra');
$mform->addElement('text', 'checkinterval', get_string('checkinterval', 'palestra'), array('size'=>'10'));
$mform->setType('checkinterval', PARAM_INT);
$mform->addRule('checkinterval', null, 'required', null, 'client');
$mform->setDefault('checkinterval', $config->checkinterval);
$mform->addHelpButton('checkinterval', 'checkinterval', 'palestra');
$this->standard_grading_coursemodule_elements();
$this->standard_coursemodule_elements();
$this->add_action_buttons();
}
}

BIN
pix/download.jpeg

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

BIN
pix/icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

36
presence.php

@ -0,0 +1,36 @@
<?php
header('content-type: application/json');
// 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/>.
/**
* Page module version information
*
* @package mod_palestra
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require_once($CFG->dirroot.'/mod/palestra/lib.php');
$id = optional_param('id', null, PARAM_INT);
if (!$id) {
echo get_string('presence_unregistered', 'palestra');
} else {
$DB->set_field('palestra_presence', 'lastcheck', time(), array('id'=>$id));
echo "done";
}

81
presences.php

@ -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/>.
/**
* This page is the entry page into the quiz UI. Displays information about the
* quiz to students and teachers, and lets students see their previous attempts.
*
* @package mod_palestra
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once("lib.php");
$cmid = required_param('cmid', PARAM_INT);
$cm = get_coursemodule_from_id('palestra', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$palestra = $DB->get_record('palestra', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, false, $cm);
if (!has_capability('mod/palestra:viewpresences', $PAGE->cm->context)) {
redirect("view.php?id=$cm->id");
}
$presences = $DB->get_records_sql(
"
select distinct u.*
from {palestra_presence} p
inner join {user} u on u.id = p.userid
where
p.palestraid = ? and
p.userid not in (".$CFG->siteadmins.")
", [$palestra->id]
);
$PAGE->set_url('/mod/palestra/presences.php', array('id'=>$cm->id));
$PAGE->set_title($course->shortname.': '.$palestra->name);
$PAGE->set_heading($course->fullname);
$PAGE->requires->jquery();
$pagetitle = get_string('presence_list_title', 'palestra', ['name'=>format_string($palestra->name)]);
echo $OUTPUT->header();
echo $OUTPUT->heading($pagetitle, 2);
echo "
<table class=\"table table-striped table-condensed\">
<thead>
<tr>
<th>".get_string('presence_total', 'palestra', count($presences))."</th>
</tr>
<tr>
<th>".get_string('fullname')."</th>
</tr>
</thead>
<tbody>
";
foreach ($presences as $presence) {
echo "<tr><td>".fullname($presence)."</td></tr>";
}
echo "</tbody></table>";
echo $OUTPUT->footer();

40
settings.php

@ -0,0 +1,40 @@
<?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/>.
/**
* Page module admin settings and defaults
*
* @package mod_palestra
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
require_once("$CFG->libdir/resourcelib.php");
$displayoptions = resourcelib_get_displayoptions(array(RESOURCELIB_DISPLAY_OPEN, RESOURCELIB_DISPLAY_POPUP));
$defaultdisplayoptions = array(RESOURCELIB_DISPLAY_OPEN);
$settings->add(new admin_setting_configcheckbox('palestra/includechat',
get_string('includechat', 'palestra'), get_string('includechat_help', 'palestra'), 1));
$settings->add(new admin_setting_configtext('palestra/checkinterval',
get_string('checkinterval', 'palestra'), get_string('checkinterval_help', 'palestra'), 10, PARAM_INT));
$settings->add(new admin_setting_configcheckbox('palestra/gradeafter',
get_string('gradeafter', 'palestra'), get_string('gradeafter_help', 'palestra'), 0));
}

30
version.php

@ -0,0 +1,30 @@
<?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/>.
/**
* Palestra module version information
*
* @package mod_palestra
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2021092200;// The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2019051100;// Requires this Moodle version
$plugin->component = 'mod_palestra';// Full name of the plugin (used for diagnostics)
$plugin->cron = 0;

150
view.php

@ -0,0 +1,150 @@
<?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/>.
/**
* Page module version information
*
* @package mod_palestra
* @copyright 2021 Interlegis (https://www.interlegis.leg.br)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require_once($CFG->dirroot.'/mod/palestra/lib.php');
require_once($CFG->libdir.'/completionlib.php');
$id = optional_param('id', 0, PARAM_INT); // Course Module ID
$p = optional_param('p', 0, PARAM_INT); // Palestra instance ID
if ($p) {
if (!$palestra = $DB->get_record('palestra', array('id'=>$p))) {
print_error('invalidaccessparameter');
}
$cm = get_coursemodule_from_instance('palestra', $palestra->id, $palestra->course, false, MUST_EXIST);
} else {
if (!$cm = get_coursemodule_from_id('palestra', $id)) {
print_error('invalidcoursemodule');
}
$palestra = $DB->get_record('palestra', array('id'=>$cm->instance), '*', MUST_EXIST);
}
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
require_course_login($course, true, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/palestra:view', $context);
// Completion and trigger events.
palestra_view($palestra, $course, $cm, $context);
$PAGE->set_url('/mod/palestra/view.php', array('id' => $cm->id));
$PAGE->set_title($course->shortname.': '.$palestra->name);
$PAGE->set_heading($course->fullname);
$PAGE->set_activity_record($palestra);
$PAGE->requires->jquery();
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($palestra->name), 2);
if (trim(strip_tags($palestra->intro))) {
echo $OUTPUT->box_start('mod_introbox', 'pageintro');
echo format_module_intro('palestra', $palestra, $cm->id);
echo $OUTPUT->box_end();
}
echo $OUTPUT->box("<span id='presence_alert'></span>", "generalbox center clearfix text-center");
$stream = "<iframe width=\"100%\" height=\"450\" src=\"https://www.youtube.com/embed/{$palestra->youtubecode}\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\"></iframe>";
if ($palestra->includechat) {
$parse = parse_url($CFG->wwwroot);
$domain = $parse['host'];
$chat = "<iframe width=\"100%\" height=\"450\" src=\"https://www.youtube.com/live_chat?v={$palestra->youtubecode}&embed_domain={$domain}\" title=\"YouTube live chat\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\"></iframe>";
if ($palestra->chatdisposition =='S') {
echo '<div class="container"><div class="row">';
echo $OUTPUT->box($stream, "col-8");
echo $OUTPUT->box($chat, "col-4");
echo "</div></div>";
} else {
echo $OUTPUT->box($stream, "generalbox center clearfix");
echo $OUTPUT->box($chat, "generalbox center clearfix");
}
}
$now = time();
// Presence will only be registered if user accessed before the end
// of palestra (startdate+duration), plus a lag margin (duration*1.5)
// or if gradeafter is checked as True
if (($now < ($palestra->startdate + ($palestra->duration*1.5*60)))
or ($palestra->gradeafter == 1)) {
$presence = array('palestraid'=>$palestra->id, 'userid'=>$USER->id, 'starttime'=>$now, 'lastcheck'=>$now);
if ($palestra->checkinterval == 0) {
// Just accessing the palestra grants 100% of grade
$presence['lastcheck'] += $palestra->duration * 60;
}
$presence['id'] = $DB->insert_record('palestra_presence', $presence);
$DB->set_field('palestra', 'needsupdate', '1', ['id'=>$palestra->id]);
$interval = $palestra->checkinterval * 60 * 1000;
$alert = get_string('presence_unregistered', 'palestra');
if ($interval > 0) {
echo "
<script type='text/javascript'>
$(document).ready(function() {
var ajaxdata = {id: {$presence['id']}};
$(window).on('unload', function(){
presenceSet();
});
var lsi = setInterval(presenceSet, {$interval});
function presenceSet() {
$.ajax({
type: 'GET',
url: '/mod/palestra/presence.php',
data: ajaxdata,
dataType: 'text',
success: function(result) {
if (result == 'stoped') {
clearInterval(lsi);
} else if (result != 'done') {
$('#presence_alert').text(result).parent().addClass('bg-warning');
} else {
$('#presence_alert').text('').parent().removeClass('bg-warning');
}
},
error: function(response, errcode) {
$('#presence_alert').text('{$alert}').addClass('bg-warning');
}
});
}
})
</script>";
}
} else {
$out_of_date_alert = get_string('out_of_date_alert', 'palestra');
echo "
<script type='text/javascript'>
$(document).ready(function() {
$('#presence_alert').text('{$out_of_date_alert}').addClass('bg-warning');
})
</script>";
}
echo $OUTPUT->footer();
Loading…
Cancel
Save