23
23
class agStaffImportNormalization extends agImportNormalization
26
* This class's constructor.
27
* @param string $tempTable The name of the temporary import table to use
28
* @param string $logEventLevel An optional parameter dictating the event level logging to be used
30
public function __construct($tempTable, $logEventLevel = NULL)
26
* Method to return an instance of this class
27
* @param string $tempTable The name of the temporary import table to use
28
* @param string $logEventLevel An optional parameter dictating the event level logging to be used
29
* @return self An instance of this class
31
public static function getInstance($tempTable, $logEventLevel = NULL)
34
$self->__init($tempTable, $logEventLevel);
39
* Method to return an instance of this class
40
* @param string $tempTable The name of the temporary import table to use
41
* @param string $logEventLevel An optional parameter dictating the event level logging to be used
42
* @return self An instance of this class
44
public function __init($tempTable = NULL, $logEventLevel = NULL)
46
if (is_null($tempTable)) { $tempTable = 'temp_staff_import'; }
33
parent::__construct($tempTable, $logEventLevel);
49
parent::__init($tempTable, $logEventLevel);
35
51
// set the import components array as a class property
36
52
$this->setImportComponents();
53
$this->tempTableOptions = array('type' => 'MYISAM', 'charset' => 'utf8');
54
$this->importHeaderStrictValidation = TRUE;
56
$this->eh->setErrThreshold(100);
40
* Method to import staff from an excel file.
60
* Imports staff from an excel file.
42
public function importStaffFromExcel()
62
public function processXlsImportFile($importFile)
44
// @todo call agImportHelper (parent) import excel method
45
// @todo Build temp table here --^
64
// process the excel file and create a temporary table
65
parent::processXlsImportFile($importFile);
47
67
// start our iterator and initialize our select query
48
68
$this->tempToRaw($this->buildTempSelectQuery());
174
211
// array( [order] => array(component => component name, helperClass => Name of the helper class, throwOnError => boolean, method => method name) )
175
212
// setEntity creates entity, person, and staff records.
176
$this->importComponents[] = array( 'component' => 'entity', 'throwOnError' => TRUE, 'method' => 'setEntities');
177
$this->importComponents[] = array( 'component' => 'personName', 'throwOnError' => TRUE, 'method' => 'setPersonNames', 'helperClass' => 'agPersonNameHelper');
178
$this->importComponents[] = array( 'component' => 'phone', 'throwOnError' => FALSE, 'method' => 'setEntityPhone', 'helperClass' => 'agEntityPhoneHelper');
179
$this->importComponents[] = array( 'component' => 'email', 'throwOnError' => FALSE, 'method' => 'setEntityEmail', 'helperClass' => 'agEntityEmailHelper');
180
# $this->importComponents[] = array( 'component' => 'address', 'throwOnError' => FALSE, 'method' => 'setEntityAddress', 'helperClass' => 'agEntityAddressHelper');
181
$this->importComponents[] = array( 'component' => 'customField', 'throwOnError' => FALSE, 'method' => 'setPersonCustomField');
182
// $this->importComponents[] = array( 'component' => 'staffResource', 'throwOnError' => TRUE, 'method' => 'setStaffResourceOrg');
183
$this->importComponents[] = array( 'component' => 'staffResource', 'throwOnError' => FALSE, 'method' => 'setStaffResourceOrg');
213
$this->importComponents[] = array(
214
'component' => 'entity',
215
'throwOnError' => TRUE,
216
'method' => 'setEntities'
218
$this->importComponents[] = array(
219
'component' => 'personName',
220
'throwOnError' => TRUE,
221
'method' => 'setPersonNames',
222
'helperClass' => 'agPersonNameHelper'
224
$this->importComponents[] = array(
225
'component' => 'phone',
226
'throwOnError' => FALSE,
227
'method' => 'setEntityPhone',
228
'helperClass' => 'agEntityPhoneHelper'
230
$this->importComponents[] = array(
231
'component' => 'email',
232
'throwOnError' => FALSE,
233
'method' => 'setEntityEmail',
234
'helperClass' => 'agEntityEmailHelper'
236
$this->importComponents[] = array(
237
'component' => 'address',
238
'throwOnError' => FALSE,
239
'method' => 'setEntityAddress',
240
'helperClass' => 'agEntityAddressHelper'
242
$this->importComponents[] = array(
243
'component' => 'customField',
244
'throwOnError' => FALSE,
245
'method' => 'setPersonCustomField'
247
$this->importComponents[] = array(
248
'component' => 'staffResource',
249
'throwOnError' => TRUE,
250
'method' => 'setStaffResourceOrg'
252
$this->importComponents[] = array(
253
'component' => 'personLanguage',
254
'throwOnError' => FALSE,
255
'method' => 'setPersonLanguage',
256
'helperClass' => 'agPersonLanguageHelper'
743
912
foreach($coll AS $index => &$record)
745
914
$stfId = $record['staff_id'];
746
$rawData = $this->importData[$staffIds[$stfId]]['_rawData'];
747
$rscTypeId = $stfRscTypeIds[$rawData['resource_type']];
915
$stfRscType = array_search($record['staff_resource_type_id'], $stfRscTypeIds);
749
if ( $record['staff_resource_type_id'] == $rscTypeId )
917
if (isset($staffIds[$stfId][$stfRscType]))
751
$orgId = $organizationIds[$rawData['organization']];
919
$rawData = $this->importData[$staffIds[$stfId][$stfRscType]]['_rawData'];
921
// Check if import organization is valid.
922
if (!array_key_exists(strtolower($rawData['organization']), $organizationIds))
924
$errMsg = sprintf('Invalid organization %s from record id %d.',
925
$rawData['organization'], $staffIds[$stfId]);
927
// Capture error in error log.
928
$this->eh->logErr($errMsg);
932
throw new Exception($errMsg);
940
// Check if import staff resource status is valid.
941
if (!array_key_exists(strtolower($rawData['resource_status']), $stfRscStatusIds))
943
$errMsg = sprintf('Invalid staff resource status %s from record id %d.',
944
$rawData['resource_status'], $staffIds[$stfId]);
946
// Capture error in error log.
947
$this->eh->logErr($errMsg);
951
throw new Exception($errMsg);
959
$orgId = $organizationIds[strtolower($rawData['organization'])];
752
960
$record['organization_id'] = $orgId;
753
$stfRscStatusId = $stfRscStatusIds[$rawData['resource_status']];
961
$stfRscStatusId = $stfRscStatusIds[strtolower($rawData['resource_status'])];
754
962
$record['staff_resource_status_id'] = $stfRscStatusId;
755
unset($staffIds[$stfId]);
963
unset($staffIds[$stfId][$stfRscType]);
967
// here we check our current transaction scope and create a transaction or savepoint
968
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
971
$conn->beginTransaction(__FUNCTION__);
975
$conn->beginTransaction();
982
// commit, being sensitive to our nesting
983
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
988
$errMsg = sprintf('%s failed at: %s', __FUNCTION__, $e->getMessage());
989
$this->eh->logErr($errMsg);
992
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
994
// ALWAYS throw an error, it's like stepping on a crack if you don't
997
throw new Exception($errMsg);
762
1003
// Now $staffIds are left with new staff resources.
763
foreach($staffIds AS $stfId => $rowId)
1004
foreach($staffIds AS $stfId => $stfResources)
765
$rawData = $this->importData[$staffIds[$stfId]]['_rawData'];
767
$fKeys['staff_id'] = $stfId;
768
$fKeys['organization_id'] = $organizationIds[$rawData['organization']];
769
$fKeys['staff_resource_type_id'] = $stfRscTypeIds[$rawData['resource_type']];
770
$fKeys['staff_resource_status_id'] = $stfRscStatusIds[$rawData['resource_status']];
772
$staffResource = $this->createNewRec('agStaffResource', $fKeys);
1006
foreach ($stfResources AS $stfRsc => $rowId)
1008
$rawData = $this->importData[$rowId]['_rawData'];
1010
// Check if import resource type is valid.
1011
if (!array_key_exists(strtolower($rawData['resource_type']), $stfRscTypeIds))
1013
$errMsg = sprintf('Invalid resource type %s from record id %d.',
1014
$rawData['resource_type'], $staffIds[$stfId]);
1016
// Capture error in error log.
1017
$this->eh->logErr($errMsg);
1021
throw new Exception($errMsg);
1029
// Check if import organization is valid.
1030
if (!array_key_exists(strtolower($rawData['organization']), $organizationIds))
1032
$errMsg = sprintf('Invalid organization %s from record id %d.',
1033
$rawData['organization'], $staffIds[$stfId]);
1035
// Capture error in error log.
1036
$this->eh->logErr($errMsg);
1040
throw new Exception($errMsg);
1048
// Check if import staff resource status is valid.
1049
if (!array_key_exists(strtolower($rawData['resource_status']), $stfRscStatusIds))
1051
$errMsg = sprintf('Invalid staff resource status %s from record id %d.',
1052
$rawData['resource_status'], $staffIds[$stfId]);
1054
// Capture error in error log.
1055
$this->eh->logErr($errMsg);
1059
throw new Exception($errMsg);
1068
$fKeys['staff_id'] = $stfId;
1069
$fKeys['organization_id'] = $organizationIds[strtolower($rawData['organization'])];
1070
$fKeys['staff_resource_type_id'] = $stfRscTypeIds[strtolower($rawData['resource_type'])];
1071
$fKeys['staff_resource_status_id'] = $stfRscStatusIds[strtolower($rawData['resource_status'])];
1073
$staffResource = $this->createNewRec('agStaffResource', $fKeys);
777
public function testDataNorm()
1080
* Method to set person language during staff import.
1081
* @param boolean $throwOnError Parameter sometimes used by import normalization methods to
1082
* control whether or not errors will be thrown.
1083
* @param Doctrine_Connection $conn A doctrine connection for data manipulation.
1085
protected function setPersonLanguage($throwOnError, Doctrine_Connection $conn)
779
$this->setLogEventLevel(self::EVENT_INFO);
780
$_rawData1 = array('entity_id' => '3',
781
'first_name' => 'Mork',
782
// 'middle_name' => '',
783
'last_name' => 'Ork',
784
'mobile_phone' => '123.123.1234',
785
// 'home_phone' => '',
786
'home_email' => 'mork.ork@home.com',
787
// 'work_phone' => '',
788
// 'work_email' => '',
789
'home_address_line_1' => '5 Silly Lane Street',
790
'home_address_city' => 'Inwood',
791
'home_address_state' => 'Bronze',
792
'home_address_country' => 'United States of America',
793
'work_address_line_1' => '5 Silly Man',
794
'work_address_line_2' => 'In rooom 728',
795
'work_address_city' => 'New York',
796
'work_address_state' => 'NY',
797
'work_address_zip' => '10013',
798
'work_address_country' => 'United States of America',
799
'organization' => 'GOAL',
800
'resource_type' => 'Medical Nurse',
801
'resource_status' => 'active',
802
'drivers_license_class' => 'Class A',
803
'civil_service_title' => 'Court Clerk'
806
$_rawData2 = array('entity_id' => '183',
807
'first_name' => 'Ork',
808
'middle_name' => 'Mork',
809
// 'last_name' => '',
810
// 'mobile_phone' => '',
811
'home_phone' => '(222) 222-1234',
812
// 'home_email' => '',
813
'work_phone' => '(212) 234-2344 x234',
814
'work_address_line_1' => '235 President Pl',
815
'work_address_city' => 'New York',
816
'work_address_state' => 'NY',
817
'work_address_zip' => '11001',
818
'work_address_country' => 'United States of America',
819
'organization' => 'volunteer',
820
'resource_type' => 'Specialist',
821
'resource_status' => 'inactive',
822
'civil_service_title' => 'Judge'
825
$_rawData3 = array('entity_id' => '11',
826
// 'first_name' => '',
827
// 'middle_name' => '',
828
// 'last_name' => '',
829
// 'mobile_phone' => '',
830
// 'home_phone' => '',
831
// 'home_email' => '',
832
'work_phone' => '333.3333.3333.',
833
// 'work_email' => '',
834
'new custom field' => 'smiley face'
837
$_rawData4 = array('entity_id' => '4983',
838
'first_name' => 'Ae432',
839
'middle_name' => 'LinjaAA ',
840
'last_name' => ' asdkfjkl; ',
841
'mobile_phone' => '999.9999.9999',
842
// 'home_phone' => '',
843
// 'home_email' => '',
844
'work_phone' => '222.3333.4444 x342',
845
'work_email' => 'Linjawork.com',
846
'organization' => 'CHAD',
847
'resource_type' => 'Medical Assistant',
848
'resource_status' => 'Bouncing',
849
'pms_id' => 'P23423452'
852
$_rawData5 = array('entity_id' => '392',
853
'first_name' => 'Aimee',
854
// 'middle_name' => '',
855
'last_name' => 'Adu',
856
// 'mobile_phone' => '',
857
// 'home_phone' => '',
858
// 'home_email' => '',
859
// 'work_phone' => '',
860
'work_email' => 'aimeeemailnow@work.com'
863
$this->importData[1] = array( '_rawData' => $_rawData1, 'primaryKey' => array(), 'success' => 0);
864
$this->importData[2] = array( '_rawData' => $_rawData2, 'primaryKey' => array(), 'success' => 0);
865
$this->importData[3] = array( '_rawData' => $_rawData3, 'primaryKey' => array(), 'success' => 0);
866
$this->importData[4] = array( '_rawData' => $_rawData4, 'primaryKey' => array(), 'success' => 0);
867
$this->importData[5] = array( '_rawData' => $_rawData5, 'primaryKey' => array(), 'success' => 0);
869
$this->clearNullRawData();
870
$this->normalizeData();
871
print_r($this->getEvents());
1087
// always start with any data maps we'll need so they're explicit
1088
$importLanguageComponents = array( 'language_1' => array( 'l1_speak' => 'speak',
1089
'l1_read' => 'read',
1090
'l1_write' => 'write'),
1091
'language_2' => array( 'l2_speak' => 'speak',
1092
'l2_read' => 'read',
1093
'l2_write' => 'write'),
1094
'language_3' => array( 'l3_speak' => 'speak',
1095
'l3_read' => 'read',
1096
'l3_write' => 'write')
1099
$personLanguages = array();
1102
// let's get ahold of our helper object since we're going to use him/her a lot
1103
$plh =& $this->helperObjects['agPersonLanguageHelper'];
1106
// loop through our raw data and build our person language data
1107
foreach ($this->importData as $rowId => $rowData)
1109
if (array_key_exists('person_id', $rowData['primaryKeys']))
1111
// this just makes it easier to use
1112
$personId = $rowData['primaryKeys']['person_id'];
1114
// Always initialize $languageComponents as an empty array. Assign an empty array to
1115
// $personLanguages only if no language was specified from import.
1116
$languageComponents = array();
1117
foreach($importLanguageComponents as $importLanguage => $langComponents)
1119
if (array_key_exists($importLanguage, $rowData['_rawData']))
1121
// Always initialize $formatCompetencies as an emtpy array. Assign an emtpy array to
1122
// $languageComponents only if no format/competency details is specified for the
1123
// language from import.
1124
$formatCompetencies = array();
1125
foreach ($langComponents as $importFormat => $dbFormat)
1127
if (array_key_exists($importFormat, $rowData['_rawData']))
1129
$formatCompetencies[$dbFormat] = $rowData['_rawData'][$importFormat];
1132
$languageComponents[] = array($rowData['_rawData'][$importLanguage], $formatCompetencies);
1135
$personLanguages[$personId] = $languageComponents;
1139
// pick up some of our components / objects
1140
$keepHistory = agGlobal::getParam('staff_import_keep_history');
1141
$createEdgeTableValues = agGlobal::getParam('create_edge_table_values');;
1143
// execute the helper and finish
1144
$results = $plh->setPersonLanguages($personLanguages, $keepHistory, $createEdgeTableValues, $throwOnError, $conn);
1145
unset($personLanguages);
1147
// @todo do your results reporting here
b'\\ No newline at end of file'