diff --git a/attendance.php b/attendance.php
index 92f8e2e..091628a 100644
--- a/attendance.php
+++ b/attendance.php
@@ -17,8 +17,8 @@
/**
* Prints attendance info for particular user
*
- * @package mod
- * @subpackage attendance
+ * @package mod_attendance
+ * @copyright 2014 Dan Marsden
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
diff --git a/db/install.php b/db/install.php
index 5a5ae48..4bcb19a 100644
--- a/db/install.php
+++ b/db/install.php
@@ -13,7 +13,6 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-defined('MOODLE_INTERNAL') || die();
/**
* post installation hook for adding data.
@@ -23,6 +22,8 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+defined('MOODLE_INTERNAL') || die();
+
/**
* Post installation procedure
*/
diff --git a/db/services.php b/db/services.php
index ffbabdb..274f023 100644
--- a/db/services.php
+++ b/db/services.php
@@ -17,7 +17,7 @@
/**
* Web service local plugin attendance external functions and service definitions.
*
- * @package localwsattendance
+ * @package mod_attendance
* @copyright 2015 Caio Bressan Doneda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
diff --git a/db/upgrade.php b/db/upgrade.php
index 71690f4..89388a8 100644
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -14,9 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-defined('MOODLE_INTERNAL') || die();
-require_once(dirname(__FILE__) . '/upgradelib.php');
-
/**
* upgrade processes for this module.
*
@@ -25,6 +22,9 @@ require_once(dirname(__FILE__) . '/upgradelib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+defined('MOODLE_INTERNAL') || die();
+require_once(dirname(__FILE__) . '/upgradelib.php');
+
/**
* upgrade this attendance instance - this function could be skipped but it will be needed later
* @param int $oldversion The old version of the attendance module
diff --git a/db/upgradelib.php b/db/upgradelib.php
index 1b12984..e2ba9ca 100644
--- a/db/upgradelib.php
+++ b/db/upgradelib.php
@@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-defined('MOODLE_INTERNAL') || die();
-
/**
* Helper functions to keep upgrade.php clean.
*
@@ -24,6 +22,11 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Function to help upgrade old attendance records and create calendar events.
+ */
function attendance_upgrade_create_calendar_events() {
global $DB;
diff --git a/locallib.php b/locallib.php
index d3265bf..660687b 100644
--- a/locallib.php
+++ b/locallib.php
@@ -480,4 +480,123 @@ function attendance_exporttocsv($data, $filename) {
foreach ($data->table as $row) {
echo implode("\t", $row)."\n";
}
-}
\ No newline at end of file
+}
+
+/**
+ * @param $formdata moodleform - attendance form.
+ * @return array.
+ */
+function attendance_construct_sessions_data_for_add($formdata) {
+ global $CFG;
+
+ $sesstarttime = $formdata->sestime['starthour'] * HOURSECS + $formdata->sestime['startminute'] * MINSECS;
+ $sesendtime = $formdata->sestime['endhour'] * HOURSECS + $formdata->sestime['endminute'] * MINSECS;
+ $sessiondate = $formdata->sessiondate + $sesstarttime;
+ $duration = $sesendtime - $sesstarttime;
+ $now = time();
+
+ if (empty(get_config('attendance', 'studentscanmark'))) {
+ $formdata->studentscanmark = 0;
+ }
+
+ $sessions = array();
+ if (isset($formdata->addmultiply)) {
+ $startdate = $sessiondate;
+ $enddate = $formdata->sessionenddate + DAYSECS; // Because enddate in 0:0am.
+
+ if ($enddate < $startdate) {
+ return null;
+ }
+
+ // Getting first day of week.
+ $sdate = $startdate;
+ $dinfo = usergetdate($sdate);
+ if ($CFG->calendar_startwday === '0') { // Week start from sunday.
+ $startweek = $startdate - $dinfo['wday'] * DAYSECS; // Call new variable.
+ } else {
+ $wday = $dinfo['wday'] === 0 ? 7 : $dinfo['wday'];
+ $startweek = $startdate - ($wday - 1) * DAYSECS;
+ }
+
+ $wdaydesc = array(0 => 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
+
+ while ($sdate < $enddate) {
+ if ($sdate < $startweek + WEEKSECS) {
+ $dinfo = usergetdate($sdate);
+ if (isset($formdata->sdays) && array_key_exists($wdaydesc[$dinfo['wday']], $formdata->sdays)) {
+ $sess = new stdClass();
+ $sess->sessdate = make_timestamp($dinfo['year'], $dinfo['mon'], $dinfo['mday'],
+ $formdata->sestime['starthour'], $formdata->sestime['startminute']);
+ $sess->duration = $duration;
+ $sess->descriptionitemid = $formdata->sdescription['itemid'];
+ $sess->description = $formdata->sdescription['text'];
+ $sess->descriptionformat = $formdata->sdescription['format'];
+ $sess->timemodified = $now;
+ if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance.
+ $sess->studentscanmark = 1;
+ if (!empty($formdata->randompassword)) {
+ $sess->studentpassword = attendance_random_string();
+ } else {
+ $sess->studentpassword = $formdata->studentpassword;
+ }
+ } else {
+ $sess->studentpassword = '';
+ }
+ $sess->statusset = $formdata->statusset;
+
+ attendance_fill_groupid($formdata, $sessions, $sess);
+ }
+ $sdate += DAYSECS;
+ } else {
+ $startweek += WEEKSECS * $formdata->period;
+ $sdate = $startweek;
+ }
+ }
+ } else {
+ $sess = new stdClass();
+ $sess->sessdate = $sessiondate;
+ $sess->duration = $duration;
+ $sess->descriptionitemid = $formdata->sdescription['itemid'];
+ $sess->description = $formdata->sdescription['text'];
+ $sess->descriptionformat = $formdata->sdescription['format'];
+ $sess->timemodified = $now;
+ $sess->studentscanmark = 0;
+ $sess->studentpassword = '';
+
+ if (isset($formdata->studentscanmark) && !empty($formdata->studentscanmark)) {
+ // Students will be able to mark their own attendance.
+ $sess->studentscanmark = 1;
+ if (!empty($formdata->randompassword)) {
+ $sess->studentpassword = attendance_random_string();
+ } else {
+ $sess->studentpassword = $formdata->studentpassword;
+ }
+ }
+ $sess->statusset = $formdata->statusset;
+
+ attendance_fill_groupid($formdata, $sessions, $sess);
+ }
+
+ return $sessions;
+}
+
+/**
+ * Helper function for attendance_construct_sessions_data_for_add().
+ *
+ * @param $formdata
+ * @param $sessions
+ * @param $sess
+ */
+function attendance_fill_groupid($formdata, &$sessions, $sess) {
+ if ($formdata->sessiontype == mod_attendance_structure::SESSION_COMMON) {
+ $sess = clone $sess;
+ $sess->groupid = 0;
+ $sessions[] = $sess;
+ } else {
+ foreach ($formdata->groups as $groupid) {
+ $sess = clone $sess;
+ $sess->groupid = $groupid;
+ $sessions[] = $sess;
+ }
+ }
+}
diff --git a/sessions.php b/sessions.php
index 836dc50..61369b8 100644
--- a/sessions.php
+++ b/sessions.php
@@ -73,7 +73,7 @@ switch ($att->pageparams->action) {
}
if ($formdata = $mform->get_data()) {
- $sessions = construct_sessions_data_for_add($formdata);
+ $sessions = attendance_construct_sessions_data_for_add($formdata);
$att->add_sessions($sessions);
if (count($sessions) == 1) {
$message = get_string('sessiongenerated', 'attendance');
@@ -222,112 +222,4 @@ echo $output->render($tabs);
$mform->display();
-echo $OUTPUT->footer();
-
-function construct_sessions_data_for_add($formdata) {
- global $CFG;
-
- $sesstarttime = $formdata->sestime['starthour'] * HOURSECS + $formdata->sestime['startminute'] * MINSECS;
- $sesendtime = $formdata->sestime['endhour'] * HOURSECS + $formdata->sestime['endminute'] * MINSECS;
- $sessiondate = $formdata->sessiondate + $sesstarttime;
- $duration = $sesendtime - $sesstarttime;
- $now = time();
-
- if (empty(get_config('attendance', 'studentscanmark'))) {
- $formdata->studentscanmark = 0;
- }
-
- $sessions = array();
- if (isset($formdata->addmultiply)) {
- $startdate = $sessiondate;
- $enddate = $formdata->sessionenddate + DAYSECS; // Because enddate in 0:0am.
-
- if ($enddate < $startdate) {
- return null;
- }
-
- // Getting first day of week.
- $sdate = $startdate;
- $dinfo = usergetdate($sdate);
- if ($CFG->calendar_startwday === '0') { // Week start from sunday.
- $startweek = $startdate - $dinfo['wday'] * DAYSECS; // Call new variable.
- } else {
- $wday = $dinfo['wday'] === 0 ? 7 : $dinfo['wday'];
- $startweek = $startdate - ($wday - 1) * DAYSECS;
- }
-
- $wdaydesc = array(0 => 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
-
- while ($sdate < $enddate) {
- if ($sdate < $startweek + WEEKSECS) {
- $dinfo = usergetdate($sdate);
- if (isset($formdata->sdays) && array_key_exists($wdaydesc[$dinfo['wday']], $formdata->sdays)) {
- $sess = new stdClass();
- $sess->sessdate = make_timestamp($dinfo['year'], $dinfo['mon'], $dinfo['mday'],
- $formdata->sestime['starthour'], $formdata->sestime['startminute']);
- $sess->duration = $duration;
- $sess->descriptionitemid = $formdata->sdescription['itemid'];
- $sess->description = $formdata->sdescription['text'];
- $sess->descriptionformat = $formdata->sdescription['format'];
- $sess->timemodified = $now;
- if (isset($formdata->studentscanmark)) { // Students will be able to mark their own attendance.
- $sess->studentscanmark = 1;
- if (!empty($formdata->randompassword)) {
- $sess->studentpassword = attendance_random_string();
- } else {
- $sess->studentpassword = $formdata->studentpassword;
- }
- } else {
- $sess->studentpassword = '';
- }
- $sess->statusset = $formdata->statusset;
-
- fill_groupid($formdata, $sessions, $sess);
- }
- $sdate += DAYSECS;
- } else {
- $startweek += WEEKSECS * $formdata->period;
- $sdate = $startweek;
- }
- }
- } else {
- $sess = new stdClass();
- $sess->sessdate = $sessiondate;
- $sess->duration = $duration;
- $sess->descriptionitemid = $formdata->sdescription['itemid'];
- $sess->description = $formdata->sdescription['text'];
- $sess->descriptionformat = $formdata->sdescription['format'];
- $sess->timemodified = $now;
- $sess->studentscanmark = 0;
- $sess->studentpassword = '';
-
- if (isset($formdata->studentscanmark) && !empty($formdata->studentscanmark)) {
- // Students will be able to mark their own attendance.
- $sess->studentscanmark = 1;
- if (!empty($formdata->randompassword)) {
- $sess->studentpassword = attendance_random_string();
- } else {
- $sess->studentpassword = $formdata->studentpassword;
- }
- }
- $sess->statusset = $formdata->statusset;
-
- fill_groupid($formdata, $sessions, $sess);
- }
-
- return $sessions;
-}
-
-function fill_groupid($formdata, &$sessions, $sess) {
- if ($formdata->sessiontype == mod_attendance_structure::SESSION_COMMON) {
- $sess = clone $sess;
- $sess->groupid = 0;
- $sessions[] = $sess;
- } else {
- foreach ($formdata->groups as $groupid) {
- $sess = clone $sess;
- $sess->groupid = $groupid;
- $sessions[] = $sess;
- }
- }
-}
+echo $OUTPUT->footer();
\ No newline at end of file
diff --git a/student_attendance_form.php b/student_attendance_form.php
index 56b7986..888507f 100644
--- a/student_attendance_form.php
+++ b/student_attendance_form.php
@@ -14,10 +14,29 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+/**
+ * Student form class.
+ *
+ * @package mod_attendance
+ * @copyright 2011 Artem Andreev
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php');
+/**
+ * Class mod_attendance_student_attendance_form
+ *
+ * @copyright 2011 Artem Andreev
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
class mod_attendance_student_attendance_form extends moodleform {
+ /**
+ * Called to define this moodle form
+ *
+ * @return void
+ */
public function definition() {
global $USER;
diff --git a/tempmerge_form.php b/tempmerge_form.php
index c5e5510..d25c4f8 100644
--- a/tempmerge_form.php
+++ b/tempmerge_form.php
@@ -14,13 +14,32 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+/**
+ * Temp merge form class.
+ *
+ * @package mod_attendance
+ * @copyright 2013 Davo Smith, Synergy Learning
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir.'/formslib.php');
+/**
+ * Temp merge form class.
+ *
+ * @package mod_attendance
+ * @copyright 2013 Davo Smith, Synergy Learning
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
class tempmerge_form extends moodleform {
-
+ /**
+ * Called to define this moodle form
+ *
+ * @return void
+ */
public function definition() {
global $COURSE;
diff --git a/tests/generator/lib.php b/tests/generator/lib.php
index 4c1d7cb..7a3dfb8 100644
--- a/tests/generator/lib.php
+++ b/tests/generator/lib.php
@@ -25,7 +25,14 @@
defined('MOODLE_INTERNAL') || die();
-
+/**
+ * mod_attendance data generator
+ *
+ * @package mod_attendance
+ * @category test
+ * @copyright 2013 Davo Smith, Synergy Learning
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
class mod_attendance_generator extends testing_module_generator {
/**