I am building custom plugin, where the admin can manually add user (choosing from the existing user and filling fields with information about him) or import .cvs
file with users and their data inside. In both cases every user's entry has the following data firstname
lastname
datefrom
dateuntil
address
status
(booked
,notattended
,attended
)
I use the following function in my import_form.php
class mod_myplugin_import_form extends moodleform {
/**
* Called to define this moodle form
*
* @return void
*/
public function definition() {
global $USER;
$mform =& $this->_form;
$course = $this->_customdata['course'];
$cm = $this->_customdata['cm'];
$modcontext = $this->_customdata['modcontext'];
$mform->addElement('header', 'general', get_string('importattendees', 'myplugin'));
$mform->addElement('filepicker', 'userfile', get_string('file'));
$mform->addRule('userfile', null, 'required');
$choices = csv_import_reader::get_delimiter_list();
$mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices);
if (array_key_exists('cfg', $choices)) {
$mform->setDefault('delimiter_name', 'cfg');
} else if (get_string('listsep', 'langconfig') == ';') {
$mform->setDefault('delimiter_name', 'semicolon');
} else {
$mform->setDefault('delimiter_name', 'comma');
}
$choices = core_text::get_encodings();
$mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices);
$mform->setDefault('encoding', 'UTF-8');
$choices = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
$mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'tool_uploaduser'), $choices);
$mform->setType('previewrows', PARAM_INT);
$this->add_action_buttons(false, get_string('uploadusers', 'tool_uploaduser'));
$mform->addElement('hidden', 'id', $cm->id);
}
How to match user's firstname
and lastname
in order to check, if the user exist, then combine the new data with the user's existing data and show it with in the userlist.php, where we display a list with the users and the imported data about them?
I didn't found anything similar in plugin for Moodle and as a newbie I am not sure how to proceed.
Thank youin advance.
S.