Set var before use.
fix some coding guideline issues.
language: php
-sudo: false
+sudo: true
addons:
firefox: "47.0.1"
//
// 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
+// 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/>.
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains an event for when an attendance sessions is imported.
* @copyright 2017 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class sessions_imported extends \core\event\base
-{
+class sessions_imported extends \core\event\base {
/**
* Init method.
*/
- protected function init()
- {
+ protected function init() {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'attendance_sessions';
*
* @return string
*/
- public function get_description()
- {
+ public function get_description() {
return 'User with id ' . $this->userid . ' imported ' . $this->other['count'] . ' sessions';
}
*
* @return string
*/
- public static function get_name()
- {
+ public static function get_name() {
return get_string('eventsessionsimported', 'mod_attendance');
}
*
* @return \moodle_url
*/
- public function get_url()
- {
+ public function get_url() {
return new \moodle_url('/mod/attendance/import/sessions.php');
}
*
* @return array of parameters for object mapping.
*/
- public static function get_objectid_mapping()
- {
+ public static function get_objectid_mapping() {
return array(
'db' => 'attendance',
'restore' => 'attendance'
//
// 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
+// 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/>.
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the form for importing sessions from a file.
*/
namespace mod_attendance\form\import;
+defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
+
use core_text;
use csv_import_reader;
use moodleform;
-require_once ($CFG->libdir . '/formslib.php');
-require_once ($CFG->libdir . '/csvlib.class.php');
+require_once($CFG->libdir . '/formslib.php');
+require_once($CFG->libdir . '/csvlib.class.php');
/**
* Import attendance sessions.
* @copyright 2017 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class sessions extends moodleform
-{
+class sessions extends moodleform {
/**
* Define the form - called by parent constructor
*/
- public function definition()
- {
+ public function definition() {
global $CFG;
$mform = $this->_form;
*
* @param string $msg
*/
- public function set_import_error($msg)
- {
+ public function set_import_error($msg) {
$mform = $this->_form;
$mform->setElementError('importfile', $msg);
//
// 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
+// 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/>.
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Import attendance sessions.
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
use moodleform;
-require_once ($CFG->libdir . '/formslib.php');
+require_once($CFG->libdir . '/formslib.php');
/**
* Import attendance sessions.
* @copyright 2017 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class sessions_confirm extends moodleform
-{
+class sessions_confirm extends moodleform {
/**
* Define the form - called by parent constructor
*/
- public function definition()
- {
+ public function definition() {
$importer = $this->_customdata;
$mform = $this->_form;
//
// 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
+// 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/>.
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
namespace mod_attendance\import;
+defined('MOODLE_INTERNAL') || die();
+
use csv_import_reader;
use mod_attendance_notifyqueue;
use mod_attendance_structure;
* @copyright 2017 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class sessions
-{
+class sessions {
/** @var string $error The errors message from reading the xml */
protected $error = '';
*
* @param string $msg
*/
- public function fail($msg)
- {
+ public function fail($msg) {
$this->error = $msg;
return false;
}
*
* @return string The import id.
*/
- public function get_importid()
- {
+ public function get_importid() {
return $this->importid;
}
*
* @return array The headers (lang strings)
*/
- public static function list_required_headers()
- {
+ public static function list_required_headers() {
return array(
get_string('course', 'attendance'),
get_string('groups', 'attendance'),
*
* @return array The found headers (names from import)
*/
- public function list_found_headers()
- {
+ public function list_found_headers() {
return $this->foundheaders;
}
* @param
* data array The mapping data.
*/
- protected function read_mapping_data($data)
- {
+ protected function read_mapping_data($data) {
if ($data) {
return array(
'course' => $data->header0,
* index The column index we want
* @return string The column data.
*/
- protected function get_column_data($row, $index)
- {
+ protected function get_column_data($row, $index) {
if ($index < 0) {
return '';
}
* @param bool $useprogressbar
* Whether progress bar should be displayed, to avoid html output on CLI.
*/
- public function __construct($text = null, $encoding = null, $delimiter = null, $importid = 0, $mappingdata = null, $useprogressbar = false)
- {
+ public function __construct($text = null, $encoding = null, $delimiter = null, $importid = 0,
+ $mappingdata = null, $useprogressbar = false) {
global $CFG;
- require_once ($CFG->libdir . '/csvlib.class.php');
+ require_once($CFG->libdir . '/csvlib.class.php');
$type = 'sessions';
*
* @return array of errors from parsing the xml.
*/
- public function get_error()
- {
+ public function get_error() {
return $this->error;
}
*
* @return void
*/
- public function import()
- {
+ public function import() {
global $DB;
// Count of sessions added.
$okcount = 0;
+ $groupids = array();
foreach ($this->sessions as $session) {
// Check course shortname matches.
foreach ($session->groups as $groupname) {
$gid = groups_get_group_by_name($course->id, $groupname);
if ($gid === false) {
- \mod_attendance_notifyqueue::notify_problem(get_string('sessionunknowngroup', 'attendance', $groupname));
+ \mod_attendance_notifyqueue::notify_problem(get_string('sessionunknowngroup',
+ 'attendance', $groupname));
} else {
$groupids[] = $gid;
}
), 'id', 'id');
foreach ($activities as $activity) {
- // Build the session data
+ // Build the session data.
$cm = get_coursemodule_from_instance('attendance', $activity->id, $course->id);
$att = new mod_attendance_structure($activity, $cm, $course);
$sessions = attendance_construct_sessions_data_for_add($session, $att);
}
$activities->close();
} else {
- mod_attendance_notifyqueue::notify_problem(get_string('error:coursehasnoattendance', 'attendance', $session->course));
+ mod_attendance_notifyqueue::notify_problem(get_string('error:coursehasnoattendance',
+ 'attendance', $session->course));
}
} else {
mod_attendance_notifyqueue::notify_problem(get_string('error:coursenotfound', 'attendance', $session->course));
* @param stdClass $session
* @return boolean
*/
- private function session_exists(stdClass $session)
- {
+ private function session_exists(stdClass $session) {
global $DB;
$check = clone $session;
return false;
}
}
-
//
// 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
+// 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/>.
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Import attendance sessions.
* @copyright 2017 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-require_once (__DIR__ . '/../../../config.php');
-require_once ($CFG->libdir . '/adminlib.php');
-require_once ($CFG->dirroot . '/mod/attendance/lib.php');
-require_once ($CFG->dirroot . '/mod/attendance/locallib.php');
+
+define('NO_OUTPUT_BUFFERING', true);
+
+require_once(__DIR__ . '/../../../config.php');
+require_once($CFG->libdir . '/adminlib.php');
+require_once($CFG->dirroot . '/mod/attendance/lib.php');
+require_once($CFG->dirroot . '/mod/attendance/locallib.php');
admin_externalpage_setup('managemodules');
$pagetitle = get_string('importsessions', 'attendance');