Skip to content
Snippets Groups Projects
Commit 0116a0bf authored by Sergio Vergata's avatar Sergio Vergata
Browse files

added

parent ef78de5a
No related branches found
No related tags found
No related merge requests found
Showing
with 3458 additions and 0 deletions
<?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/>.
/**
* Attendance Block
*
* @package block_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Displays information about Attendance Module in this course.
*
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_attendance extends block_base {
/**
* Set the initial properties for the block
*/
public function init() {
$this->title = get_string('blockname', 'block_attendance');
}
/**
* Gets the content for this block
*
* @return object $this->content
*/
public function get_content() {
global $CFG, $USER, $COURSE;
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass;
$this->content->footer = '';
$this->content->text = '';
$attendances = get_all_instances_in_course('attendance', $COURSE, null, true);
if (count($attendances) == 0) {
$this->content->text = get_string('needactivity', 'block_attendance');;
return $this->content;
}
require_once($CFG->dirroot.'/mod/attendance/locallib.php');
require_once($CFG->dirroot.'/mod/attendance/renderhelpers.php');
foreach ($attendances as $attinst) {
$cmid = $attinst->coursemodule;
$cm = get_coursemodule_from_id('attendance', $cmid, $COURSE->id, false, MUST_EXIST);
if (!empty($cm->deletioninprogress)) {
// Don't display if this attendance is in recycle bin.
continue;
}
$context = context_module::instance($cmid, MUST_EXIST);
$divided = $this->divide_databasetable_and_coursemodule_data($attinst);
$att = new mod_attendance_structure($divided->atttable, $divided->cm, $COURSE, $context);
$this->content->text .= html_writer::link($att->url_view(), html_writer::tag('b', format_string($att->name)));
$this->content->text .= html_writer::empty_tag('br');
// Link to attendance.
if (has_capability('mod/attendance:takeattendances', $context) or
has_capability('mod/attendance:changeattendances', $context)) {
$this->content->text .= html_writer::link($att->url_manage(array('from' => 'block')),
get_string('takeattendance', 'attendance'));
$this->content->text .= html_writer::empty_tag('br');
}
if (has_capability('mod/attendance:manageattendances', $context)) {
$url = $att->url_sessions(array('action' => mod_attendance_sessions_page_params::ACTION_ADD));
$this->content->text .= html_writer::link($url, get_string('add', 'attendance'));
$this->content->text .= html_writer::empty_tag('br');
}
if (has_capability('mod/attendance:viewreports', $context)) {
$this->content->text .= html_writer::link($att->url_report(), get_string('report', 'attendance'));
$this->content->text .= html_writer::empty_tag('br');
}
if (has_capability('mod/attendance:canbelisted', $context, null, false) &&
has_capability('mod/attendance:view', $context)) {
$this->content->text .= construct_full_user_stat_html_table($attinst, $USER);
}
$this->content->text .= "<br />";
}
$categorycontext = context_coursecat::instance($COURSE->category);
if (has_capability('mod/attendance:viewsummaryreports', $categorycontext)) {
$url = new moodle_url('/mod/attendance/coursesummary.php',
array('category' => $COURSE->category, 'fromcourse' => $COURSE->id));
$this->content->text .= html_writer::link($url, get_string('categoryreport', 'attendance'));
$this->content->text .= html_writer::empty_tag('br');
}
return $this->content;
}
/**
* parses data to pass into construct.
* @param object $alldata
* @return array
*/
private function divide_databasetable_and_coursemodule_data($alldata) {
static $cmfields;
if (!isset($cmfields)) {
$cmfields = array(
'coursemodule' => 'id',
'section' => 'section',
'visible' => 'visible',
'groupmode' => 'groupmode',
'groupingid' => 'groupingid',
'groupmembersonly' => 'groupmembersonly');
}
$atttable = new stdClass();
$cm = new stdClass();
foreach ($alldata as $field => $value) {
if (array_key_exists($field, $cmfields)) {
$cm->{$cmfields[$field]} = $value;
} else {
$atttable->{$field} = $value;
}
}
$ret = new stdClass();
$ret->atttable = $atttable;
$ret->cm = $cm;
return $ret;
}
/**
* Set the applicable formats for this block
* @return array
*/
public function applicable_formats() {
return array('all' => true, 'my' => false, 'admin' => false, 'tag' => false);
}
}
<?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/>.
/**
* Privacy Subsystem implementation for block_attendance.
*
* @package block_attendance
* @copyright 2018 Dan Marsden <dan@danmarsden.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_attendance\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for block_attendance implementing null_provider.
*
* @copyright 2018 Dan Marsden <dan@danmarsden.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason() : string {
return 'privacy:metadata';
}
}
{
"name": "danmarsden/moodle-block_attendance",
"type": "moodle-block",
"require": {
"composer/installers": "~1.0"
},
"extra": {
"installer-name": "attendance"
}
}
<?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/>.
/**
* Attendance block caps.
*
* @package block_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'block/attendance:addinstance' => array(
'riskbitmask' => RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/course:manageactivities'
),
);
<?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/>.
/**
* Language file for block "attendance"
*
* @package block_attendance
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['attendance:addinstance'] = 'Add a new attendance block';
$string['blockname'] = 'Attendance';
$string['needactivity'] = 'This block can work only with an attendance activity. Please add the activity to this course.';
$string['pluginname'] = 'Attendance';
$string['privacy:metadata'] = 'The Attendance block only displays existing attendance data.';
\ No newline at end of file
@block @block_attendance @javascript
Feature: Test that teachers can add the attendance block and students can view reports.
Background:
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist:
| course | user | role |
| C1 | teacher1 | editingteacher |
| C1 | student1 | student |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| attendance | AttendanceTest1 | attendance description | C1 | attendance1 |
Scenario: Teachers can add the attendance block
When I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Attendance" block
Then I should see "Take attendance"
Scenario: Students can view their reports.
When I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Attendance" block
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
Then I should see "Taken sessions"
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
define(["jquery"],function(a){"use strict";function b(b){void 0!==b&&b.preventDefault();var c=a("#coc-filterterm").val();"all"===c?a(".termdiv").removeClass("coc-hidden"):(a(".termdiv").addClass("coc-hidden"),a(".coc-term-"+c).removeClass("coc-hidden")),M.util.set_user_preference("block_course_overview_campus-selectedterm",c)}function c(b){void 0!==b&&b.preventDefault();var c=a("#coc-filterteacher").val();"all"===c?a(".teacherdiv").removeClass("coc-hidden"):(a(".teacherdiv").addClass("coc-hidden"),a(".coc-teacher-"+c).removeClass("coc-hidden")),M.util.set_user_preference("block_course_overview_campus-selectedteacher",c)}function d(b){void 0!==b&&b.preventDefault();var c=a("#coc-filtercategory").val();"all"===c?a(".categorydiv").removeClass("coc-hidden"):(a(".categorydiv").addClass("coc-hidden"),a(".coc-category-"+c).removeClass("coc-hidden")),M.util.set_user_preference("block_course_overview_campus-selectedcategory",c)}function e(b){void 0!==b&&b.preventDefault();var c=a("#coc-filtertoplevelcategory").val();"all"===c?a(".toplevelcategorydiv").removeClass("coc-hidden"):(a(".toplevelcategorydiv").addClass("coc-hidden"),a(".coc-toplevelcategory-"+c).removeClass("coc-hidden")),M.util.set_user_preference("block_course_overview_campus-selectedtoplevelcategory",c)}function f(f){var g,h,i,j;for(g in f)if(f.hasOwnProperty(g)&&(h=f[g],i=a("#coc-filter"+g),i.length&&(j=i.val(),j!==h)))switch(g){case"term":b();break;case"teacher":c();break;case"category":d();break;case"toplevelcategory":e()}}function g(){var b=new Array;a(".coc-course").each(function(c,d){0==a(d).height()&&b.push(d.id.slice(11))});var c=JSON.stringify(b);M.util.set_user_preference("local_boostcoc-notshowncourses",c)}function h(){var b=new Array;a("#coc-filterterm, #coc-filtercategory, #coc-filtertoplevelcategory, #coc-filterteacher").each(function(c,d){"all"!==a(d).val()&&b.push(d.id.slice(4))});var c=parseInt(a("#coc-hiddencoursescount").html(),10);c>0&&b.push("hidecourses");var d=JSON.stringify(b);M.util.set_user_preference("local_boostcoc-activefilters",d)}return{initFilter:function(i){a("#coc-filterterm").on("change",b),a("#coc-filterteacher").on("change",c),a("#coc-filtercategory").on("change",d),a("#coc-filtertoplevelcategory").on("change",e),1==i.local_boostcoc&&a("#coc-filterterm, #coc-filterteacher, #coc-filtercategory, #coc-filtertoplevelcategory").on("change",g).on("change",h),f(i.initialsettings)}}});
\ No newline at end of file
define(["jquery"],function(a){"use strict";function b(b){var c;if(void 0!==b&&b.preventDefault(),1===b.data.manage&&(a("#coc-hidecourseicon-"+b.data.course).addClass("coc-hidden"),a("#coc-showcourseicon-"+b.data.course).removeClass("coc-hidden")),0===b.data.manage){a("#coc-hidecourseicon-"+b.data.course).addClass("coc-hidden"),a("#coc-showcourseicon-"+b.data.course).removeClass("coc-hidden");var d=b.data.course;a(".coc-hidecourse-"+b.data.course).slideUp(function(){a(".coc-hidecourse-"+d).addClass("coc-hidden"),c=parseInt(a("#coc-hiddencoursescount").html(),10),a("#coc-hiddencoursescount").html(c+1),a("#coc-hiddencoursesmanagement-bottom .row").removeClass("coc-hidden")})}M.util.set_user_preference("block_course_overview_campus-hidecourse-"+b.data.course,1)}function c(b){void 0!==b&&b.preventDefault(),1===b.data.manage&&(a("#coc-showcourseicon-"+b.data.course).addClass("coc-hidden"),a("#coc-hidecourseicon-"+b.data.course).removeClass("coc-hidden")),M.util.set_user_preference("block_course_overview_campus-hidecourse-"+b.data.course,0)}function d(){var b=new Array;a(".coc-course").each(function(c,d){0==a(d).height()&&b.push(d.id.slice(11))});var c=JSON.stringify(b);M.util.set_user_preference("local_boostcoc-notshowncourses",c)}function e(){var b=new Array;a("#coc-filterterm, #coc-filtercategory, #coc-filtertoplevelcategory, #coc-filterteacher").each(function(c,d){"all"!==a(d).val()&&b.push(d.id.slice(4))});var c=parseInt(a("#coc-hiddencoursescount").html(),10);c>0&&b.push("hidecourses");var d=JSON.stringify(b);M.util.set_user_preference("local_boostcoc-activefilters",d)}return{initHideCourse:function(f){var g,h=f.courses.split(" ");for(g=0;g<h.length;g++)a("#coc-hidecourseicon-"+h[g]).on("click",{course:h[g],manage:f.manage},b),a("#coc-showcourseicon-"+h[g]).on("click",{course:h[g],manage:f.manage},c),1==f.local_boostcoc&&0==f.manage&&a("#coc-hidecourseicon-"+h[g]).on("click",d).on("click",e)}}});
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment