469
469
$scenarioFacilityResource = $this->createScenarioFacilityResource($facilityResource,
470
470
$scenarioFacilityGroup,
471
471
$facility_resource_allocation_status_id,
472
$facility_activation_sequence);
472
$facility_activation_sequence,
474
475
$scenarioFacilityResource = $this->updateScenarioFacilityResource($scenarioFacilityResource,
475
476
$scenarioFacilityGroup->id,
476
477
$facility_resource_allocation_status_id,
477
$facility_activation_sequence);
478
$facility_activation_sequence,
481
483
if ($validEmail) {
482
$this->updateFacilityEmail($facility, $email, $workEmailTypeId);
484
$this->updateFacilityEmail($facility, $email, $workEmailTypeId, $conn);
486
488
if ($validPhone) {
487
$this->updateFacilityPhone($facility, $phone, $workPhoneTypeId, $workPhoneFormatId);
489
$this->updateFacilityPhone($facility, $phone, $workPhoneTypeId, $workPhoneFormatId, $conn);
564
581
->set('facility_name', $facilityName)
565
582
->set('facility_code', $facilityCode);
566
583
$facility->save($conn);
585
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
567
586
} catch(Exception $e) {
568
587
// ALWAYS log rollbacks with as much useful information as possible
569
$this->errMsg = sprintf('Couldn\'t insert facility %s! Rolled back changes!', $facilityCode);
588
$this->errMsg = sprintf('Couldn\'t insert facility with facility code %s! Rolled back changes!', $facilityCode);
590
// if we started with a savepoint, let's end with one, otherwise, rollback globally
591
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
570
593
throw $e; // always remember to throw an exception after rollback
573
596
return $facility;
576
protected function updateFacility($facility, $facilityName, $conn)
599
protected function updateFacility($facility, $facilityName, $conn = NULL)
601
// here you can pick up the default connection if not passed one explicitly
602
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
604
// here we check our current transaction scope and create a transaction or savepoint based on need
605
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
608
$conn->beginTransaction(__FUNCTION__);
612
$conn->beginTransaction();
579
616
if ($facility->facility_name != $facilityName)
584
621
->where('f.id = ?', $facility->id)
625
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
587
626
} catch(Exception $e) {
588
627
// ALWAYS log rollbacks with as much useful information as possible
589
$this->errMsg = sprintf('Couldn\'t update facility %s! Rolled back changes!', $facility->facility_code);
628
$this->errMsg = sprintf('Couldn\'t update facility with facility code %s! Rolled back changes!', $facility->facility_code);
630
// if we started with a savepoint, let's end with one, otherwise, rollback globally
631
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
590
634
throw $e; // always remember to throw an exception after rollback
593
636
return $facility;
596
639
/* Facility Resource */
598
641
protected function createFacilityResource($facility, $facilityResourceTypeAbbrId,
599
$facilityResourceStatusId, $capacity, $conn)
642
$facilityResourceStatusId, $capacity, $conn = NULL)
644
// here you can pick up the default connection if not passed one explicitly
645
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
647
// here we check our current transaction scope and create a transaction or savepoint based on need
648
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
651
$conn->beginTransaction(__FUNCTION__);
655
$conn->beginTransaction();
602
659
$facilityResource = new agFacilityResource();
603
660
$facilityResource->set('facility_id', $facility->id)
639
716
$updateQuery = $updateQuery->execute();
717
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
641
719
$updateQuery = NULL;
643
721
} catch(Exception $e) {
644
722
// ALWAYS log rollbacks with as much useful information as possible
645
723
$this->errMsg = sprintf('Couldn\'t update facility resource (%s, %s)! Rolled back changes!',
646
$facility->facility_code,
724
$facilityResource->getAgFacility()->facility_code,
647
725
array_search($facilityResource->facility_resource_type_id, $this->facilityResourceTypes));
727
// if we started with a savepoint, let's end with one, otherwise, rollback globally
728
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
648
730
throw $e; // always remember to throw an exception after rollback
651
733
return $facilityResource;
654
protected function updateFacilityStaffResources($scenarioFacilityResourceId, $staff_data)
736
protected function updateFacilityStaffResources($scenarioFacilityResourceId, $staff_data, $conn = NULL)
656
738
$facilityStaffResource = agDoctrineQuery::create()
657
739
->select('srt.id, fsr.minimum_staff, fsr.maximum_staff, fsr.id')
663
745
$deleteFacStfResId = array();
664
746
foreach ($staff_data as $staffTypeId => $count) {
665
747
if (array_key_exists($staffTypeId, $facilityStaffResource)) {
667
$updateQuery = agDoctrineQuery::create()
668
->update('agFacilityStaffResource')
669
->where('id = ?', $facilityStaffResource[$staffTypeId][2]);
671
if ($count['min'] == 0 && $count['max'] == 0) {
672
$deleteFacStfResId[] = $facilityStaffResource[$staffTypeId][2];
676
if ($facilityStaffResource[$staffTypeId][0] != $count['min']) {
677
$updateQuery->set('minimum_staff', $count['min']);
681
if ($facilityStaffResource[$staffTypeId][1] != $count['max']) {
682
$updateQuery->set('maximum_staff', $count['max']);
687
$updateQuery->execute();
748
// here you can pick up the default connection if not passed one explicitly
749
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
751
// here we check our current transaction scope and create a transaction or savepoint based on need
752
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
755
$conn->beginTransaction(__FUNCTION__);
759
$conn->beginTransaction();
764
$updateQuery = agDoctrineQuery::create($conn)
765
->update('agFacilityStaffResource')
766
->where('id = ?', $facilityStaffResource[$staffTypeId][2]);
768
if ($count['min'] == 0 && $count['max'] == 0) {
769
$deleteFacStfResId[] = $facilityStaffResource[$staffTypeId][2];
773
if ($facilityStaffResource[$staffTypeId][0] != $count['min']) {
774
$updateQuery->set('minimum_staff', $count['min']);
778
if ($facilityStaffResource[$staffTypeId][1] != $count['max']) {
779
$updateQuery->set('maximum_staff', $count['max']);
784
$updateQuery->execute();
785
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
789
} catch(Exception $e) {
790
// ALWAYS log rollbacks with as much useful information as possible
791
$this->errMsg = sprintf('Couldn\'t update facility staff resource! Rolled back changes!');
793
// if we started with a savepoint, let's end with one, otherwise, rollback globally
794
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
796
throw $e; // always remember to throw an exception after rollback
692
799
if ($count['min'] != 0 && $count['max'] != 0) {
693
$this->createFacilityStaffResource($scenarioFacilityResourceId, $staffTypeId, $count['min'], $count['max']);
800
$this->createFacilityStaffResource($scenarioFacilityResourceId, $staffTypeId, $count['min'], $count['max'], $conn);
698
805
if (!empty($deleteFacStfResId)) {
699
$deleteQuery = agDoctrineQuery::create()
700
->delete('agFacilityStaffResource')
701
->whereIn('id', $deleteFacStfResId)
806
// here you can pick up the default connection if not passed one explicitly
807
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
809
// here we check our current transaction scope and create a transaction or savepoint based on need
810
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
813
$conn->beginTransaction(__FUNCTION__);
817
$conn->beginTransaction();
821
$deleteQuery = agDoctrineQuery::create($conn)
822
->delete('agFacilityStaffResource')
823
->whereIn('id', $deleteFacStfResId)
825
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
826
} catch(Exception $e) {
827
// ALWAYS log rollbacks with as much useful information as possible
828
$this->errMsg = sprintf('Couldn\'t update facility staff resource! Rolled back changes!');
830
// if we started with a savepoint, let's end with one, otherwise, rollback globally
831
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
833
throw $e; // always remember to throw an exception after rollback
705
837
return $facilityStaffResource;
708
protected function createFacilityStaffResource($scenarioFacilityResourceId, $staffTypeId, $min_staff,
840
protected function createFacilityStaffResource($scenarioFacilityResourceId,
841
$staffTypeId, $min_staff,
842
$max_staff, $conn = NULL)
711
$facilityStaffResource = new agFacilityStaffResource();
712
$facilityStaffResource->set('staff_resource_type_id', $staffTypeId)
713
->set('scenario_facility_resource_id', $scenarioFacilityResourceId)
714
->set('minimum_staff', $min_staff)
715
->set('maximum_staff', $max_staff);
716
$facilityStaffResource->save();
844
// here you can pick up the default connection if not passed one explicitly
845
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
847
// here we check our current transaction scope and create a transaction or savepoint based on need
848
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
851
$conn->beginTransaction(__FUNCTION__);
855
$conn->beginTransaction();
859
$facilityStaffResource = new agFacilityStaffResource();
860
$facilityStaffResource->set('staff_resource_type_id', $staffTypeId)
861
->set('scenario_facility_resource_id', $scenarioFacilityResourceId)
862
->set('minimum_staff', $min_staff)
863
->set('maximum_staff', $max_staff);
864
$facilityStaffResource->save($conn);
865
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
866
} catch(Exception $e) {
867
$scenarioFacilityResource = Doctrine_Core::getTable('agScenarioFacilityResource')->find($scenarioFacilityResourceId);
868
// ALWAYS log rollbacks with as much useful information as possible
869
$this->errMsg = sprintf('Couldn\'t create facility staff resource (%s, %s)! Rolled back changes!',
870
$scenarioFacilityResource->getAgFacilityResource()->getAgFacility()->facility_name,
871
$scenarioFacilityResource->getAgStaffResourceType()->staff_resource_type);
873
// if we started with a savepoint, let's end with one, otherwise, rollback globally
874
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
876
throw $e; // always remember to throw an exception after rollback
717
878
return $facilityStaffResource;
745
925
protected function updateScenarioFacilityGroup($scenarioFacilityGroup, $facilityGroupTypeId,
746
926
$facilityGroupAllocationStatusId,
747
$facilityGroupActivationSequence, $conn)
927
$facilityGroupActivationSequence, $conn = NULL)
929
// here you can pick up the default connection if not passed one explicitly
930
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
932
// here we check our current transaction scope and create a transaction or savepoint based on need
933
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
936
$conn->beginTransaction(__FUNCTION__);
940
$conn->beginTransaction();
750
944
$doUpdate = FALSE;
751
$updateQuery = agDoctrineQuery::create()
945
$updateQuery = agDoctrineQuery::create($conn)
752
946
->update('agScenarioFacilityGroup sfg')
753
947
->where('id = ?', $scenarioFacilityGroup->id);
755
if (strtolower($scenarioFacilityGroup->facility_group_type_id) != strtolower($facilityGroupTypeId)) {
949
// if (strtolower($scenarioFacilityGroup->facility_group_type_id) != strtolower($facilityGroupTypeId)) {
756
950
$updateQuery->set('facility_group_type_id', '?', $facilityGroupTypeId);
757
951
$doUpdate = TRUE;
760
954
if ($scenarioFacilityGroup->facility_group_allocation_status_id != $facilityGroupAllocationStatusId) {
761
955
$updateQuery->set('facility_group_allocation_status_id', '?', $facilityGroupAllocationStatusId);
787
986
protected function createScenarioFacilityResource($facilityResource, $scenarioFacilityGroup,
788
987
$facilityResourceAllocationStatusId,
789
$facilityActivationSequence)
988
$facilityActivationSequence, $conn = NULL)
791
$scenarioFacilityResource = new agScenarioFacilityResource();
792
$scenarioFacilityResource->set('facility_resource_id', $facilityResource->id)
793
->set('scenario_facility_group_id', $scenarioFacilityGroup->id)
794
->set('facility_resource_allocation_status_id', $facilityResourceAllocationStatusId)
795
->set('activation_sequence', $facilityActivationSequence);
796
$scenarioFacilityResource->save();
990
// here you can pick up the default connection if not passed one explicitly
991
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
993
// here we check our current transaction scope and create a transaction or savepoint based on need
994
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
997
$conn->beginTransaction(__FUNCTION__);
1001
$conn->beginTransaction();
1005
$scenarioFacilityResource = new agScenarioFacilityResource();
1006
$scenarioFacilityResource->set('facility_resource_id', $facilityResource->id)
1007
->set('scenario_facility_group_id', $scenarioFacilityGroup->id)
1008
->set('facility_resource_allocation_status_id', $facilityResourceAllocationStatusId)
1009
->set('activation_sequence', $facilityActivationSequence);
1010
$scenarioFacilityResource->save($conn);
1011
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
1012
} catch(Exception $e) {
1013
// ALWAYS log rollbacks with as much useful information as possible
1014
$this->errMsg = sprintf('Couldn\'t insert scenario facility resource (%s, %s, %s)! Rolled back changes!',
1015
$facilityResource->getAgFacility()->facility_name,
1016
$facilityResource->getAgFacilityResourceType()->facility_resource_type_abbr,
1017
$scenarioFacilityGroup->scenario_facility_group);
1019
// if we started with a savepoint, let's end with one, otherwise, rollback globally
1020
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
1022
throw $e; // always remember to throw an exception after rollback
797
1025
return $scenarioFacilityResource;
800
protected function updateScenarioFacilityResource($scenarioFacilityResource, $scenarioFacilityGroupId, $facilityResourceAllocationStatusId, $facilityActivationSequence)
1028
protected function updateScenarioFacilityResource($scenarioFacilityResource,
1029
$scenarioFacilityGroupId,
1030
$facilityResourceAllocationStatusId,
1031
$facilityActivationSequence, $conn = NULL)
803
$updateQuery = agDoctrineQuery::create()
804
->update('agScenarioFacilityResource')
805
->where('id = ?', $scenarioFacilityResource->id);
807
if ($scenarioFacilityResource->scenario_facility_group_id != $scenarioFacilityGroupId) {
808
$updateQuery->set('scenario_facility_group_id', $scenarioFacilityGroupId);
812
if ($scenarioFacilityResource->facility_resource_allocation_status_id != $scenarioFacilityResourceAllocationStatusId) {
813
$updateQuery->set('facility_resource_allocation_status_id', $facilityResourceAllocationStatusId);
817
if ($scenarioFacilityResource->activation_sequence != $facilityActivationSequence) {
818
$updateQuery->set('activation_sequence', $facilityActivationSequence);
823
$updateQuery = $updateQuery->execute();
1033
// here you can pick up the default connection if not passed one explicitly
1034
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
1036
// here we check our current transaction scope and create a transaction or savepoint based on need
1037
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
1040
$conn->beginTransaction(__FUNCTION__);
1044
$conn->beginTransaction();
1049
$updateQuery = agDoctrineQuery::create($conn)
1050
->update('agScenarioFacilityResource')
1051
->where('id = ?', $scenarioFacilityResource->id);
1053
if ($scenarioFacilityResource->scenario_facility_group_id != $scenarioFacilityGroupId) {
1054
$updateQuery->set('scenario_facility_group_id', $scenarioFacilityGroupId);
1058
if ($scenarioFacilityResource->facility_resource_allocation_status_id != $scenarioFacilityResourceAllocationStatusId) {
1059
$updateQuery->set('facility_resource_allocation_status_id', $facilityResourceAllocationStatusId);
1063
if ($scenarioFacilityResource->activation_sequence != $facilityActivationSequence) {
1064
$updateQuery->set('activation_sequence', $facilityActivationSequence);
1069
$updateQuery = $updateQuery->execute();
1070
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
1072
$updateQuery = NULL;
1074
} catch(Exception $e) {
1075
// ALWAYS log rollbacks with as much useful information as possible
1076
$this->errMsg = sprintf('Couldn\'t update scenario facility resource (%s, %s, %s)! Rolled back changes!',
1077
$scenarioFacilityResource->getAgFacilityResource()->getAgFacility()->facility_name,
1078
$scenarioFacilityResource->getAgFacilityResource()->getAgFacilityResourceType()->facility_resource_type_abbr,
1079
Doctrine_Core::getTable('agScenarioFacilityGroup')->find($scenarioFacilityGroupId)->scenario_facility_group);
1081
// if we started with a savepoint, let's end with one, otherwise, rollback globally
1082
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
1084
throw $e; // always remember to throw an exception after rollback
828
1087
return $scenarioFacilityResource;
839
1098
return $emailContact;
842
protected function createEmail($email)
1101
protected function createEmail($email, $conn = NULL)
844
$emailContact = new agEmailContact();
845
$emailContact->set('email_contact', $email);
846
$emailContact->save();
1103
// here you can pick up the default connection if not passed one explicitly
1104
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
1106
// here we check our current transaction scope and create a transaction or savepoint based on need
1107
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
1110
$conn->beginTransaction(__FUNCTION__);
1114
$conn->beginTransaction();
1118
$emailContact = new agEmailContact();
1119
$emailContact->set('email_contact', $email);
1120
$emailContact->save($conn);
1121
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
1122
} catch (Exception $e) {
1123
// ALWAYS log rollbacks with as much useful information as possible
1124
$this->errMsg = sprintf('Couldn\'t create email %s! Rolled back changes!', $email);
1126
// if we started with a savepoint, let's end with one, otherwise, rollback globally
1127
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
1129
throw $e; // always remember to throw an exception after rollback
847
1132
return $emailContact;
850
protected function createEntityEmail($entityId, $emailId, $typeId)
1135
protected function createEntityEmail($entityId, $emailId, $typeId, $conn = NULl)
852
1137
$priority = $this->getPriorityCounter('email', $entityId);
854
$entityEmail = new agEntityEmailContact();
855
$entityEmail->set('entity_id', $entityId)
856
->set('email_contact_id', $emailId)
857
->set('email_contact_type_id', $typeId)
858
->set('priority', $priority);
859
$entityEmail->save();
1139
// here you can pick up the default connection if not passed one explicitly
1140
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
1142
// here we check our current transaction scope and create a transaction or savepoint based on need
1143
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
1146
$conn->beginTransaction(__FUNCTION__);
1150
$conn->beginTransaction();
1154
$entityEmail = new agEntityEmailContact();
1155
$entityEmail->set('entity_id', $entityId)
1156
->set('email_contact_id', $emailId)
1157
->set('email_contact_type_id', $typeId)
1158
->set('priority', $priority);
1159
$entityEmail->save($conn);
1160
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
1161
} catch (Exception $e) {
1162
// ALWAYS log rollbacks with as much useful information as possible
1163
$this->errMsg = sprintf('Couldn\'t create entity email (%s, %s)! Rolled back changes!',
1164
array_search($typeId, $this->emailContactTypes),
1165
Doctrine_Core::getTable('agEmailContact')->find($emailId)->email_contact);
1167
// if we started with a savepoint, let's end with one, otherwise, rollback globally
1168
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
1170
throw $e; // always remember to throw an exception after rollback
861
1173
return $entityEmail;
864
protected function updateEntityEmail($entityEmailObject, $emailObject)
1176
protected function updateEntityEmail($entityEmailObject, $emailObject, $conn = NULL)
866
$entityEmailObject->set('email_contact_id', $emailObject->id);
867
$entityEmailObject->save();
1178
// here you can pick up the default connection if not passed one explicitly
1179
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
1181
// here we check our current transaction scope and create a transaction or savepoint based on need
1182
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
1185
$conn->beginTransaction(__FUNCTION__);
1189
$conn->beginTransaction();
1193
$entityEmailObject->set('email_contact_id', $emailObject->id);
1194
$entityEmailObject->save($conn);
1195
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
1196
} catch (Exception $e) {
1197
// ALWAYS log rollbacks with as much useful information as possible
1198
$this->errMsg = sprintf('Couldn\'t update entity email (%s, %s)! Rolled back changes!',
1199
$entityEmailObject->getAgEmailContactType()->email_contact_type,
1200
$emailObject->email_contact);
1202
// if we started with a savepoint, let's end with one, otherwise, rollback globally
1203
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
1205
throw $e; // always remember to throw an exception after rollback
868
1208
return $entityEmailObject;
894
1234
// only useful for nonrequired emails
895
1235
// if importedEmail null
896
1236
if (empty($email) && !empty($facilityEmail)) {
897
$entityEmail->delete();
1237
// here we check our current transaction scope and create a transaction or savepoint based on need
1238
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
1241
$conn->beginTransaction(__FUNCTION__);
1245
$conn->beginTransaction();
1248
$entityEmail->delete($conn);
1249
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
1251
} catch (Exception $e) {
1252
// ALWAYS log rollbacks with as much useful information as possible
1253
$this->errMsg = sprintf('Couldn\'t remove old entity email (%s, %s)! Rolled back changes!',
1254
array_search($workEmailTypeId, $this->emailContactTypes),
1257
// if we started with a savepoint, let's end with one, otherwise, rollback globally
1258
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
1260
throw $e; // always remember to throw an exception after rollback
901
1265
$emailEntity = $this->getEmailObject($email);
903
1267
if (empty($emailEntity)) {
904
$emailEntity = $this->createEmail($email);
1268
$emailEntity = $this->createEmail($email, $conn);
907
1271
if (empty($facilityEmail)) {
908
$this->createEntityEmail($entityId, $emailEntity->id, $workEmailTypeId);
1272
$this->createEntityEmail($entityId, $emailEntity->id, $workEmailTypeId, $conn);
912
1276
// Facility email exists and does not match import email.
913
$this->updateEntityEmail($entityEmail, $emailEntity);
1277
$this->updateEntityEmail($entityEmail, $emailEntity, $conn);
926
1290
return $phoneContact;
929
protected function createPhone($phone, $phoneFormatId)
1293
protected function createPhone($phone, $phoneFormatId, $conn = NULL)
931
$phoneContact = new agPhoneContact();
933
->set('phone_contact', $phone)
934
->set('phone_format_id', $phoneFormatId);
935
$phoneContact->save();
1295
// here you can pick up the default connection if not passed one explicitly
1296
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
1298
// here we check our current transaction scope and create a transaction or savepoint based on need
1299
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
1302
$conn->beginTransaction(__FUNCTION__);
1306
$conn->beginTransaction();
1310
$phoneContact = new agPhoneContact();
1312
->set('phone_contact', $phone)
1313
->set('phone_format_id', $phoneFormatId);
1314
$phoneContact->save($conn);
1315
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
1316
} catch (Exception $e) {
1317
// ALWAYS log rollbacks with as much useful information as possible
1318
$this->errMsg = sprintf('Couldn\'t insert phone %s! Rolled back changes!', $phone);
1320
// if we started with a savepoint, let's end with one, otherwise, rollback globally
1321
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
1323
throw $e; // always remember to throw an exception after rollback
936
1326
return $phoneContact;
939
protected function createEntityPhone($entityId, $phoneContactId, $typeId)
1329
protected function createEntityPhone($entityId, $phoneContactId, $typeId, $conn = NULL)
941
1331
$priority = $this->getPriorityCounter('phone', $entityId);
943
$entityPhone = new agEntityPhoneContact();
944
$entityPhone->set('entity_id', $entityId)
945
->set('phone_contact_id', $phoneContactId)
946
->set('phone_contact_type_id', $typeId)
947
->set('priority', $priority);
948
$entityPhone->save();
1333
// here you can pick up the default connection if not passed one explicitly
1334
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
1336
// here we check our current transaction scope and create a transaction or savepoint based on need
1337
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
1340
$conn->beginTransaction(__FUNCTION__);
1344
$conn->beginTransaction();
1348
$entityPhone = new agEntityPhoneContact();
1349
$entityPhone->set('entity_id', $entityId)
1350
->set('phone_contact_id', $phoneContactId)
1351
->set('phone_contact_type_id', $typeId)
1352
->set('priority', $priority);
1353
$entityPhone->save($conn);
1354
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
1355
} catch (Exception $e) {
1356
// ALWAYS log rollbacks with as much useful information as possible
1357
$this->errMsg = sprintf('Couldn\'t create entity phone (%s, %s)! Rolled back changes!',
1358
array_search($typeId, $this->phoneContactTypes),
1359
Doctrine_Core::getTable('agPhoneContact')->find($phoneContactId)->phone_contact);
1361
// if we started with a savepoint, let's end with one, otherwise, rollback globally
1362
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
1364
throw $e; // always remember to throw an exception after rollback
950
1367
return $entityPhone;
953
protected function updateEntityPhone($entityPhoneObject, $phoneObject)
1370
protected function updateEntityPhone($entityPhoneObject, $phoneObject, $conn = NULL)
955
$entityPhoneObject->set('phone_contact_id', $phoneObject->id);
956
$entityPhoneObject->save();
1372
// here you can pick up the default connection if not passed one explicitly
1373
if (is_null($conn)) { $conn = Doctrine_Manager::connection(); }
1375
// here we check our current transaction scope and create a transaction or savepoint based on need
1376
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
1379
$conn->beginTransaction(__FUNCTION__);
1383
$conn->beginTransaction();
1387
$entityPhoneObject->set('phone_contact_id', $phoneObject->id);
1388
$entityPhoneObject->save($conn);
1389
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
1390
} catch (Exception $e) {
1391
// ALWAYS log rollbacks with as much useful information as possible
1392
$this->errMsg = sprintf('Couldn\'t update entity email (%s, %s)! Rolled back changes!',
1393
$entityEmailObject->getAgEmailContactType()->email_contact_type,
1394
$emailObject->email_contact);
1396
// if we started with a savepoint, let's end with one, otherwise, rollback globally
1397
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
1399
throw $e; // always remember to throw an exception after rollback
957
1402
return $entityPhone;
984
1429
// only useful for nonrequired phones
985
1430
// if importedEmail null
986
1431
if (empty($phone)) {
987
$entityPhone->delete();
1432
// here we check our current transaction scope and create a transaction or savepoint based on need
1433
$useSavepoint = ($conn->getTransactionLevel() > 0) ? TRUE : FALSE;
1436
$conn->beginTransaction(__FUNCTION__);
1440
$conn->beginTransaction();
1443
$entityPhone->delete($conn);
1444
if ($useSavepoint) { $conn->commit(__FUNCTION__); } else { $conn->commit(); }
1445
} catch (Exception $e) {
1446
// ALWAYS log rollbacks with as much useful information as possible
1447
$this->errMsg = sprintf('Couldn\'t remove old entity phone (%s, %s)! Rolled back changes!',
1448
array_search($workPhoneTypeId, $this->phoneContactTypes),
1451
// if we started with a savepoint, let's end with one, otherwise, rollback globally
1452
if ($useSavepoint) { $conn->rollback(__FUNCTION__); } else { $conn->rollback(); }
1454
throw $e; // always remember to throw an exception after rollback
991
1459
$phoneEntity = $this->getPhoneObject($phone);
993
1461
if (empty($phoneEntity)) {
994
$phoneEntity = $this->createPhone($phone, $phoneFormatId);
1462
$phoneEntity = $this->createPhone($phone, $phoneFormatId, $conn);
997
1465
if (empty($facilityPhone)) {
998
$this->createEntityPhone($entityId, $phoneEntity->id, $workPhoneTypeId);
1466
$this->createEntityPhone($entityId, $phoneEntity->id, $workPhoneTypeId, $conn);
1002
1470
// Facility phone exists and does not match import phone
1003
$this->updateEntityPhone($entityPhone, $phoneEntity);
1471
$this->updateEntityPhone($entityPhone, $phoneEntity, $conn);