-
Notifications
You must be signed in to change notification settings - Fork 1
/
teacher_import.php
38 lines (30 loc) · 978 Bytes
/
teacher_import.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
* @file
* CSV importer for teacher bundle contact entities.
*/
$csv_path = "/home/bc/Downloads/initial_teacher_import.csv";
if (($handle = fopen($csv_path, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
teacherimport($data);
}
}
fclose($handle);
/**
* Imports a single teacher record from a CSV row.
*
* @param array $data
* Four-element array from CSV.
*/
function teacherimport($data) {
$newteacher = entity_create('e3_contact', array('type' => 'teacher'));
$newteacher->uid = '1';
$newteacher->firstname = $data[0];
$newteacher->lastname = $data[1];
$fullname = implode(' ', array($data[0], $data[1]));
$newteacher->fullname = $fullname;
$newteacher->field_email = array(LANGUAGE_NONE => array(0 => array('value' => $data[2])));
$wrapper = entity_metadata_wrapper('e3_contact', $newteacher);
$wrapper->field_contact_addy->phone_number = $data[3];
entity_save('e3_contact', $newteacher);
}