Browse Source

Add output buffering level for progress bar.

Set var before use.

fix some coding guideline issues.
MOODLE_33_STABLE
Dan Marsden 7 years ago
parent
commit
d06e216f9c
  1. 2
      .travis.yml
  2. 22
      classes/event/sessions_imported.php
  3. 19
      classes/form/import/sessions.php
  4. 12
      classes/form/import/sessions_confirm.php
  5. 53
      classes/import/sessions.php
  6. 15
      import/sessions.php

2
.travis.yml

@ -1,6 +1,6 @@
language: php language: php
sudo: false sudo: true
addons: addons:
postgresql: "9.3" postgresql: "9.3"

22
classes/event/sessions_imported.php

@ -8,11 +8,11 @@
// //
// Moodle is distributed in the hope that it will be useful, // Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // 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. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // 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. * This file contains an event for when an attendance sessions is imported.
@ -40,14 +40,12 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2017 Catalyst IT * @copyright 2017 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @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. * Init method.
*/ */
protected function init() protected function init() {
{
$this->data['crud'] = 'c'; $this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_OTHER; $this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'attendance_sessions'; $this->data['objecttable'] = 'attendance_sessions';
@ -58,8 +56,7 @@ class sessions_imported extends \core\event\base
* *
* @return string * @return string
*/ */
public function get_description() public function get_description() {
{
return 'User with id ' . $this->userid . ' imported ' . $this->other['count'] . ' sessions'; return 'User with id ' . $this->userid . ' imported ' . $this->other['count'] . ' sessions';
} }
@ -68,8 +65,7 @@ class sessions_imported extends \core\event\base
* *
* @return string * @return string
*/ */
public static function get_name() public static function get_name() {
{
return get_string('eventsessionsimported', 'mod_attendance'); return get_string('eventsessionsimported', 'mod_attendance');
} }
@ -78,8 +74,7 @@ class sessions_imported extends \core\event\base
* *
* @return \moodle_url * @return \moodle_url
*/ */
public function get_url() public function get_url() {
{
return new \moodle_url('/mod/attendance/import/sessions.php'); return new \moodle_url('/mod/attendance/import/sessions.php');
} }
@ -88,8 +83,7 @@ class sessions_imported extends \core\event\base
* *
* @return array of parameters for object mapping. * @return array of parameters for object mapping.
*/ */
public static function get_objectid_mapping() public static function get_objectid_mapping() {
{
return array( return array(
'db' => 'attendance', 'db' => 'attendance',
'restore' => 'attendance' 'restore' => 'attendance'

19
classes/form/import/sessions.php

@ -8,11 +8,11 @@
// //
// Moodle is distributed in the hope that it will be useful, // Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // 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. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // 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. * This file contains the form for importing sessions from a file.
@ -24,11 +24,13 @@
*/ */
namespace mod_attendance\form\import; namespace mod_attendance\form\import;
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
use core_text; use core_text;
use csv_import_reader; use csv_import_reader;
use moodleform; use moodleform;
require_once ($CFG->libdir . '/formslib.php'); require_once($CFG->libdir . '/formslib.php');
require_once ($CFG->libdir . '/csvlib.class.php'); require_once($CFG->libdir . '/csvlib.class.php');
/** /**
* Import attendance sessions. * Import attendance sessions.
@ -38,14 +40,12 @@ require_once ($CFG->libdir . '/csvlib.class.php');
* @copyright 2017 Catalyst IT * @copyright 2017 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @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 * Define the form - called by parent constructor
*/ */
public function definition() public function definition() {
{
global $CFG; global $CFG;
$mform = $this->_form; $mform = $this->_form;
@ -78,8 +78,7 @@ class sessions extends moodleform
* *
* @param string $msg * @param string $msg
*/ */
public function set_import_error($msg) public function set_import_error($msg) {
{
$mform = $this->_form; $mform = $this->_form;
$mform->setElementError('importfile', $msg); $mform->setElementError('importfile', $msg);

12
classes/form/import/sessions_confirm.php

@ -8,11 +8,11 @@
// //
// Moodle is distributed in the hope that it will be useful, // Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // 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. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // 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. * Import attendance sessions.
@ -27,7 +27,7 @@ namespace mod_attendance\form\import;
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
use moodleform; use moodleform;
require_once ($CFG->libdir . '/formslib.php'); require_once($CFG->libdir . '/formslib.php');
/** /**
* Import attendance sessions. * Import attendance sessions.
@ -37,14 +37,12 @@ require_once ($CFG->libdir . '/formslib.php');
* @copyright 2017 Catalyst IT * @copyright 2017 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @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 * Define the form - called by parent constructor
*/ */
public function definition() public function definition() {
{
$importer = $this->_customdata; $importer = $this->_customdata;
$mform = $this->_form; $mform = $this->_form;

53
classes/import/sessions.php

@ -8,13 +8,16 @@
// //
// Moodle is distributed in the hope that it will be useful, // Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // 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. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // 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; namespace mod_attendance\import;
defined('MOODLE_INTERNAL') || die();
use csv_import_reader; use csv_import_reader;
use mod_attendance_notifyqueue; use mod_attendance_notifyqueue;
use mod_attendance_structure; use mod_attendance_structure;
@ -28,8 +31,7 @@ use stdClass;
* @copyright 2017 Catalyst IT * @copyright 2017 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @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 */ /** @var string $error The errors message from reading the xml */
protected $error = ''; protected $error = '';
@ -56,8 +58,7 @@ class sessions
* *
* @param string $msg * @param string $msg
*/ */
public function fail($msg) public function fail($msg) {
{
$this->error = $msg; $this->error = $msg;
return false; return false;
} }
@ -67,8 +68,7 @@ class sessions
* *
* @return string The import id. * @return string The import id.
*/ */
public function get_importid() public function get_importid() {
{
return $this->importid; return $this->importid;
} }
@ -77,8 +77,7 @@ class sessions
* *
* @return array The headers (lang strings) * @return array The headers (lang strings)
*/ */
public static function list_required_headers() public static function list_required_headers() {
{
return array( return array(
get_string('course', 'attendance'), get_string('course', 'attendance'),
get_string('groups', 'attendance'), get_string('groups', 'attendance'),
@ -101,8 +100,7 @@ class sessions
* *
* @return array The found headers (names from import) * @return array The found headers (names from import)
*/ */
public function list_found_headers() public function list_found_headers() {
{
return $this->foundheaders; return $this->foundheaders;
} }
@ -112,8 +110,7 @@ class sessions
* @param * @param
* data array The mapping data. * data array The mapping data.
*/ */
protected function read_mapping_data($data) protected function read_mapping_data($data) {
{
if ($data) { if ($data) {
return array( return array(
'course' => $data->header0, 'course' => $data->header0,
@ -158,8 +155,7 @@ class sessions
* index The column index we want * index The column index we want
* @return string The column data. * @return string The column data.
*/ */
protected function get_column_data($row, $index) protected function get_column_data($row, $index) {
{
if ($index < 0) { if ($index < 0) {
return ''; return '';
} }
@ -182,11 +178,11 @@ class sessions
* @param bool $useprogressbar * @param bool $useprogressbar
* Whether progress bar should be displayed, to avoid html output on CLI. * 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; global $CFG;
require_once ($CFG->libdir . '/csvlib.class.php'); require_once($CFG->libdir . '/csvlib.class.php');
$type = 'sessions'; $type = 'sessions';
@ -318,8 +314,7 @@ class sessions
* *
* @return array of errors from parsing the xml. * @return array of errors from parsing the xml.
*/ */
public function get_error() public function get_error() {
{
return $this->error; return $this->error;
} }
@ -328,12 +323,12 @@ class sessions
* *
* @return void * @return void
*/ */
public function import() public function import() {
{
global $DB; global $DB;
// Count of sessions added. // Count of sessions added.
$okcount = 0; $okcount = 0;
$groupids = array();
foreach ($this->sessions as $session) { foreach ($this->sessions as $session) {
// Check course shortname matches. // Check course shortname matches.
@ -354,7 +349,8 @@ class sessions
foreach ($session->groups as $groupname) { foreach ($session->groups as $groupname) {
$gid = groups_get_group_by_name($course->id, $groupname); $gid = groups_get_group_by_name($course->id, $groupname);
if ($gid === false) { if ($gid === false) {
\mod_attendance_notifyqueue::notify_problem(get_string('sessionunknowngroup', 'attendance', $groupname)); \mod_attendance_notifyqueue::notify_problem(get_string('sessionunknowngroup',
'attendance', $groupname));
} else { } else {
$groupids[] = $gid; $groupids[] = $gid;
} }
@ -368,7 +364,7 @@ class sessions
), 'id', 'id'); ), 'id', 'id');
foreach ($activities as $activity) { foreach ($activities as $activity) {
// Build the session data // Build the session data.
$cm = get_coursemodule_from_instance('attendance', $activity->id, $course->id); $cm = get_coursemodule_from_instance('attendance', $activity->id, $course->id);
$att = new mod_attendance_structure($activity, $cm, $course); $att = new mod_attendance_structure($activity, $cm, $course);
$sessions = attendance_construct_sessions_data_for_add($session, $att); $sessions = attendance_construct_sessions_data_for_add($session, $att);
@ -391,7 +387,8 @@ class sessions
} }
$activities->close(); $activities->close();
} else { } 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 { } else {
mod_attendance_notifyqueue::notify_problem(get_string('error:coursenotfound', 'attendance', $session->course)); mod_attendance_notifyqueue::notify_problem(get_string('error:coursenotfound', 'attendance', $session->course));
@ -423,8 +420,7 @@ class sessions
* @param stdClass $session * @param stdClass $session
* @return boolean * @return boolean
*/ */
private function session_exists(stdClass $session) private function session_exists(stdClass $session) {
{
global $DB; global $DB;
$check = clone $session; $check = clone $session;
@ -441,4 +437,3 @@ class sessions
return false; return false;
} }
} }

15
import/sessions.php

@ -8,11 +8,11 @@
// //
// Moodle is distributed in the hope that it will be useful, // Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // 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. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // 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. * Import attendance sessions.
@ -22,10 +22,13 @@
* @copyright 2017 Catalyst IT * @copyright 2017 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once (__DIR__ . '/../../../config.php');
require_once ($CFG->libdir . '/adminlib.php'); define('NO_OUTPUT_BUFFERING', true);
require_once ($CFG->dirroot . '/mod/attendance/lib.php');
require_once ($CFG->dirroot . '/mod/attendance/locallib.php'); 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'); admin_externalpage_setup('managemodules');
$pagetitle = get_string('importsessions', 'attendance'); $pagetitle = get_string('importsessions', 'attendance');

Loading…
Cancel
Save