-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathResourceAcquisition.php
1015 lines (756 loc) · 35.3 KB
/
ResourceAcquisition.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
class ResourceAcquisition extends DatabaseObject {
protected function defineRelationships() {}
protected function overridePrimaryKeyName() {}
//returns array of notes objects
public function getNotes($tabName = NULL) {
if ($tabName) {
$query = "SELECT * FROM ResourceNote RN
WHERE entityID = '" . $this->resourceAcquisitionID . "'
AND UPPER(tabName) = UPPER('" . $tabName . "')
ORDER BY updateDate desc";
}else{
$query = "SELECT RN.*
FROM ResourceNote RN
LEFT JOIN NoteType NT ON NT.noteTypeID = RN.noteTypeID
WHERE entityID = '" . $this->resourceAcquisitionID . "'
ORDER BY updateDate desc, NT.shortName";
}
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['resourceNoteID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new ResourceNote(new NamedArguments(array('primaryKey' => $row['resourceNoteID'])));
array_push($objects, $object);
}
return $objects;
}
//returns array of the initial note object
public function getInitialNote() {
$noteType = new NoteType();
$query = "SELECT * FROM ResourceNote RN
WHERE entityID = '" . $this->resourceAcquisitionID . "'
AND noteTypeID = " . $noteType->getInitialNoteTypeID() . "
ORDER BY noteTypeID desc LIMIT 0,1";
$result = $this->db->processQuery($query, 'assoc');
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['resourceNoteID'])) {
return new ResourceNote(new NamedArguments(array('primaryKey' => $result['resourceNoteID'])));
} else{
return new ResourceNote();
}
}
//returns array of ResourceStep objects for this Resource
public function getResourceSteps() {
$query = "SELECT * FROM ResourceStep
WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'
ORDER BY (archivingDate IS NOT NULL), archivingDate DESC, displayOrderSequence, stepID";
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['resourceStepID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new ResourceStep(new NamedArguments(array('primaryKey' => $row['resourceStepID'])));
array_push($objects, $object);
}
return $objects;
}
public function getCurrentWorkflowID() {
$query = "SELECT Step.workflowID FROM Step, ResourceStep
WHERE ResourceStep.resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'
AND ResourceStep.archivingDate IS NULL
AND ResourceStep.stepID = Step.stepID LIMIT 1";
$result = $this->db->processQuery($query, 'assoc');
return isset($result['workflowID']) ? $result['workflowID'] : NULL;
}
public function getCurrentWorkflowResourceSteps(){
$query = "SELECT * FROM ResourceStep
WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'
AND archivingDate IS NULL ORDER BY displayOrderSequence, stepID";
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['resourceStepID'])){
$object = new ResourceStep(new NamedArguments(array('primaryKey' => $result['resourceStepID'])));
array_push($objects, $object);
}else{
foreach ($result as $row) {
$object = new ResourceStep(new NamedArguments(array('primaryKey' => $row['resourceStepID'])));
array_push($objects, $object);
}
}
return $objects;
}
public function isCurrentWorkflowComplete() {
$status = new Status();
$statusID = $status->getIDFromName('complete');
$resource = new Resource(new NamedArguments(array('primaryKey' => $this->resourceID)));
if ($resource->statusID == $statusID) {
return true;
}
$steps = $this->getCurrentWorkflowResourceSteps();
foreach ($steps as $step) {
if (!$step->isComplete()) return false;
}
return true;
}
public function getDistinctWorkflows() {
$query = "SELECT DISTINCT archivingDate FROM ResourceStep
WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'
AND archivingDate IS NOT NULL
ORDER BY archivingDate ASC";
$result = $this->db->processQuery($query, 'assoc');
return $result;
}
public function getArchivedResourceSteps() {
return $this->getResourceSteps(true);
}
//returns first steps (object) in the workflow for this resource
public function getFirstSteps() {
$query = "SELECT * FROM ResourceStep
WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'
AND (priorStepID is null OR priorStepID = '0')
AND archivingDate IS NULL
ORDER BY stepID";
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['resourceStepID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new ResourceStep(new NamedArguments(array('primaryKey' => $row['resourceStepID'])));
array_push($objects, $object);
}
return $objects;
}
public function archiveWorkflow() {
// And archive the workflow
$query = "UPDATE ResourceStep SET archivingDate=NOW() WHERE archivingDate IS NULL AND resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query);
}
public function deleteWorkflow() {
$query = "DELETE FROM ResourceStep WHERE archivingDate IS NULL AND resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query);
}
//enters resource into new workflow
public function enterNewWorkflow($workflowID = null, $sendEmail = true){
$config = new Configuration();
$resource = new Resource(new NamedArguments(array('primaryKey' => $this->resourceID)));
//make sure this resource is marked in progress in case it was archived
$status = new Status();
$resource->statusID = $status->getIDFromName('progress');
$resource->save();
//Determine the workflow this resource belongs to
$workflowObj = new Workflow();
if ($workflowID == null) {
$workflowID = $workflowObj->getWorkflowID($resource->resourceTypeID, $resource->resourceFormatID, $this->acquisitionTypeID);
}
if ($workflowID){
$workflow = new Workflow(new NamedArguments(array('primaryKey' => $workflowID)));
$resourceTypeObj = new ResourceType();
$resourceFormatObj = new ResourceFormat();
$acquisitionTypeObj = new AcquisitionType();
//set new resourceType, resourceFormat and acquisitionType for the resource, according to the selected workflow
$resource->resourceTypeID = ($workflow->resourceTypeIDValue != null) ? $workflow->resourceTypeIDValue : $resourceTypeObj->getResourceTypeIDByName('any');
$resource->resourceFormatID = ($workflow->resourceFormatIDValue != null) ? $workflow->resourceFormatIDValue : $resourceFormatObj->getResourceFormatIDByName('any');
$this->acquisitionTypeID = ($workflow->acquisitionTypeIDValue != null) ? $workflow->acquisitionTypeIDValue : $acquisitionTypeObj->getAcquisitionTypeIDByName('any');
$resource->save();
$this->save();
//Copy all of the step attributes for this workflow to a new resource step
foreach ($workflow->getSteps() as $step) {
$resourceStep = new ResourceStep();
$resourceStep->resourceStepID = '';
$resourceStep->resourceAcquisitionID = $this->resourceAcquisitionID;
$resourceStep->stepID = $step->stepID;
$resourceStep->priorStepID = $step->priorStepID;
$resourceStep->stepName = $step->stepName;
$resourceStep->stepStartDate = '';
$resourceStep->stepEndDate = '';
$resourceStep->archivingDate = '';
$resourceStep->endLoginID = '';
$resourceStep->userGroupID = $step->userGroupID;
$resourceStep->displayOrderSequence = $step->displayOrderSequence;
$resourceStep->save();
}
//Start the first step
//this handles updating the db and sending notifications for approval groups
foreach ($this->getFirstSteps() as $resourceStep) {
$resourceStep->startStep($sendEmail);
}
}
//send an email notification to the feedback email address and the creator
$cUser = new User(new NamedArguments(array('primaryKey' => $this->createLoginID)));
$acquisitionType = new AcquisitionType(new NamedArguments(array('primaryKey' => $this->acquisitionTypeID)));
if ($cUser->firstName) {
$creator = $cUser->firstName . " " . $cUser->lastName;
}else if ($this->createLoginID) { //for some reason user isn't set up or their firstname/last name don't exist
$creator = $this->createLoginID;
}else{
$creator = "(unknown user)";
}
if (($config->settings->feedbackEmailAddress) || ($cUser->emailAddress)) {
$email = new Email();
$util = new Utility();
$email->message = $util->createMessageFromTemplate('NewResourceMain', $this->resourceID, $resource->titleText, '', '', $creator);
if ($cUser->emailAddress) {
$emailTo[] = $cUser->emailAddress;
}
if ($config->settings->feedbackEmailAddress != '') {
$emailTo[] = $config->settings->feedbackEmailAddress;
}
$email->to = implode(",", $emailTo);
if ($acquisitionType->shortName) {
$email->subject = "CORAL Alert: New " . $acquisitionType->shortName . " Resource Added: " . $resource->titleText;
}else{
$email->subject = "CORAL Alert: New Resource Added: " . $resource->titleText;
}
$email->send();
}
}
//completes a workflow (changes status to complete and sends notifications to creator and "master email")
public function completeWorkflow() {
$config = new Configuration();
$util = new Utility();
$status = new Status();
$statusID = $status->getIDFromName('complete');
$resource = new Resource(new NamedArguments(array('primaryKey' => $this->resourceID)));
if ($statusID) {
$resource->statusID = $statusID;
$resource->save();
}
//send notification to creator and master email address
$cUser = new User(new NamedArguments(array('primaryKey' => $resource->createLoginID)));
//formulate emil to be sent
$email = new Email();
$email->message = $util->createMessageFromTemplate('CompleteResource', $resource->resourceID, $resource->titleText, '', $resource->systemNumber, '');
if ($cUser->emailAddress) {
$emailTo[] = $cUser->emailAddress;
}
if ($config->settings->feedbackEmailAddress != '') {
$emailTo[] = $config->settings->feedbackEmailAddress;
}
$email->to = implode(",", $emailTo);
$email->subject = "CORAL Alert: Workflow completion for " . $resource->titleText;
$email->send();
}
private function getDownTimeResults($archivedOnly=false) {
$query = "SELECT d.*
FROM Downtime d
WHERE d.resourceAcquisitionID='{$this->resourceAcquisitionID}' AND d.entityTypeID=2";
if ($archivedOnly) {
$query .= " AND d.endDate < CURDATE()";
} else {
$query .= " AND (d.endDate >= CURDATE() OR d.endDate IS NULL)";
}
$query .= " ORDER BY d.dateCreated DESC";
return $this->db->processQuery($query, 'assoc');
}
public function getDowntime($archivedOnly=false) {
$result = $this->getDownTimeResults($archivedOnly);
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['downtimeID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new Downtime(new NamedArguments(array('primaryKey' => $row['downtimeID'])));
array_push($objects, $object);
}
return $objects;
}
public function getIssues($archivedOnly=false) {
$query = "SELECT i.*
FROM Issue i
LEFT JOIN IssueRelationship ir ON ir.issueID=i.issueID
WHERE ir.resourceAcquisitionID='$this->resourceAcquisitionID' AND ir.entityTypeID=2";
if ($archivedOnly) {
$query .= " AND i.dateClosed IS NOT NULL";
} else {
$query .= " AND i.dateClosed IS NULL";
}
$query .= " ORDER BY i.dateCreated DESC";
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['issueID'])){ $result = [$result]; }
foreach ($result as $row) {
$object = new Issue(new NamedArguments(array('primaryKey' => $row['issueID'])));
array_push($objects, $object);
}
return $objects;
}
//returns array of associated licenses
public function getLicenseArray() {
$config = new Configuration;
//if the lic module is installed get the lic name from lic database
if ($config->settings->licensingModule == 'Y') {
$dbName = $config->settings->licensingDatabaseName;
$resourceLicenseArray = array();
$query = "SELECT * FROM ResourceLicenseLink WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['licenseID'])) {
$licArray = array();
//first, get the license name
$query = "SELECT shortName FROM " . $dbName . ".License WHERE licenseID = " . $result['licenseID'];
if ($licResult = $this->db->query($query)) {
while ($licRow = $licResult->fetch_assoc()) {
$licArray['license'] = $licRow['shortName'];
$licArray['licenseID'] = $result['licenseID'];
$licArray['resourceLicenseLinkID'] = $result['resourceLicenseLinkID'];
}
}
array_push($resourceLicenseArray, $licArray);
}else{
foreach ($result as $row) {
$licArray = array();
//first, get the license name
$query = "SELECT shortName FROM " . $dbName . ".License WHERE licenseID = " . $row['licenseID'];
if ($licResult = $this->db->query($query)) {
while ($licRow = $licResult->fetch_assoc()) {
$licArray['license'] = $licRow['shortName'];
$licArray['licenseID'] = $row['licenseID'];
$licArray['resourceLicenseLinkID'] = $row['resourceLicenseLinkID'];
}
}
array_push($resourceLicenseArray, $licArray);
}
}
return $resourceLicenseArray;
}
}
//returns array of resource license status objects
public function getResourceLicenseStatuses() {
$query = "SELECT * FROM ResourceLicenseStatus WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "' ORDER BY licenseStatusChangeDate desc;";
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['resourceLicenseStatusID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new ResourceLicenseStatus(new NamedArguments(array('primaryKey' => $row['resourceLicenseStatusID'])));
array_push($objects, $object);
}
return $objects;
}
//returns LicenseStatusID of the most recent resource license status
public function getCurrentResourceLicenseStatus() {
$query = "SELECT licenseStatusID FROM ResourceLicenseStatus RLS WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "' AND licenseStatusChangeDate = (SELECT MAX(licenseStatusChangeDate) FROM ResourceLicenseStatus WHERE ResourceLicenseStatus.resourceAcquisitionID = '" . $this->resourceAcquisitionID . "') LIMIT 0,1;";
$result = $this->db->processQuery($query, 'assoc');
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['licenseStatusID'])) {
return $result['licenseStatusID'];
}
}
//removes this order
public function removeResourceAcquisition() {
//delete data from child linked tables
$this->deleteResourcePayments();
$this->deleteLicenses();
$this->deleteAccess();
$this->deleteContacts();
$this->deleteAttachments();
$this->deleteNotes();
$this->delete();
}
//removes resource licenses
public function removeResourceLicenses() {
$query = "DELETE
FROM ResourceLicenseLink
WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query);
}
//removes resource license statuses
public function removeResourceLicenseStatuses() {
$query = "DELETE
FROM ResourceLicenseStatus
WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query);
}
// Copy what was linked to the resourceAcquisition given in parameter to this one
public function cloneFrom($sourceID) {
$source = new ResourceAcquisition(new NamedArguments(array('primaryKey' => $sourceID)));
// Copy cost history
$this->cloneResourcePayments($source);
// Copy licenses
$this->cloneLicenses($source);
// Copy access
$this->cloneAccess($source);
// Copy cataloging
// Nothing to do, already cloned in ResourceAcquisition
// Copy contacts
$this->cloneContacts($source);
// Copy attachments
$this->cloneAttachments($source);
}
public function cloneAttachments($source) {
foreach ($source->getAttachments() as $s) {
$s->attachmentID = null;
$newID = $s->saveAsNew();
$query = "UPDATE Attachment SET ResourceAcquisitionID=" . $this->resourceAcquisitionID . " WHERE attachmentID=" . $newID;
$result = $this->db->processQuery($query);
}
}
public function cloneContacts($source) {
foreach ($source->getUnarchivedContacts() as $s) {
if ($s['contactID'] != null && $s['contactID'] != '') {
$c = new Contact(new NamedArguments(array('primaryKey' => $s['contactID'])));
$contactRoles = $c->getContactRoles();
$c->contactID = null;
$newID = $c->saveAsNew();
if ($newID) {
$query = "UPDATE Contact SET ResourceAcquisitionID=" . $this->resourceAcquisitionID . " WHERE contactID=" . $newID;
$result = $this->db->processQuery($query);
foreach ($contactRoles as $contactRole) {
$query = "INSERT INTO ContactRoleProfile(contactID, contactRoleID) VALUES ($newID, " . $contactRole->contactRoleID . ")";
$result = $this->db->processQuery($query);
}
}
}
}
}
public function cloneResourcePayments($source) {
foreach ($source->getResourcePayments() as $srp) {
$srp->resourcePaymentID = null;
$newRPID = $srp->saveAsNew();
$query = "UPDATE ResourcePayment SET resourceAcquisitionID=" . $this->resourceAcquisitionID . " WHERE resourcePaymentID=" . $newRPID;
$result = $this->db->processQuery($query);
}
}
public function cloneAccess($source) {
foreach ($source->getAdministeringSitesLinks() as $s) {
$s->resourceAdministeringSiteLinkID = null;
$newID = $s->saveAsNew();
$query = "UPDATE ResourceAdministeringSiteLink SET resourceAcquisitionID=" . $this->resourceAcquisitionID . " WHERE resourceAdministeringSiteLinkID=" . $newID;
$result = $this->db->processQuery($query);
}
foreach ($source->getAuthorizedSitesLinks() as $s) {
$s->resourceAuthorizedSiteLinkID = null;
$newID = $s->saveAsNew();
$query = "UPDATE ResourceAuthorizedSiteLink SET resourceAcquisitionID=" . $this->resourceAcquisitionID . " WHERE resourceAuthorizedSiteLinkID=" . $newID;
$result = $this->db->processQuery($query);
}
}
public function cloneLicenses($source) {
foreach ($source->getLicenseArray() as $s) {
$rll = new ResourceLicenseLink();
$rll->resourceAcquisitionID = $this->resourceAcquisitionID;;
$rll->licenseID = $s['licenseID'];
$rll->save;
}
foreach ($source->getResourceLicenseStatuses() as $s) {
$s->resourceLicenseStatusID = null;
$newID = $s->saveAsNew();
$query = "UPDATE ResourceLicenseStatus SET resourceAcquisitionID=" . $this->resourceAcquisitionID . " WHERE resourceLicenseStatusID=" . $newID;
$result = $this->db->processQuery($query);
}
}
public function deleteResourcePayments() {
foreach ($this->getResourcePayments() as $srp) {
$srp->delete();
}
}
public function deleteAccess() {
foreach ($this->getAdministeringSitesLinks() as $s) {
$s->delete();
}
foreach ($this->getAuthorizedSitesLinks() as $s) {
$s->delete();
}
}
public function deleteLicenses() {
foreach ($this->getLicenseArray() as $s) {
$rll = new ResourceLicenseLink(new NamedArguments(array('primaryKey' => $s['resourceLicenseLinkID'])));
$rll->delete();
}
foreach ($this->getResourceLicenseStatuses() as $s) {
$s->delete();
}
}
public function deleteContacts() {
foreach ($this->getContacts() as $c) {
$c->removeContactRoles();
$c->delete();
}
}
public function deleteAttachments() {
foreach ($this->getAttachments() as $s) {
$s->delete();
}
}
public function deleteNotes() {
foreach (array("Acquisitions", "Access", "Cataloging") as $tabName) {
foreach ($this->getNotes($tabName) as $s) {
$s->delete();
}
}
}
//returns array of contact objects
public function getUnarchivedContacts($moduleFilter=false) {
$config = new Configuration;
$contactsArray = array();
if (!$moduleFilter || $moduleFilter == 'resources') {
//get resource specific contacts first
$query = "SELECT C.*, GROUP_CONCAT(CR.shortName SEPARATOR '<br /> ') contactRoles
FROM Contact C, ContactRole CR, ContactRoleProfile CRP
WHERE (archiveDate = '0000-00-00' OR archiveDate is null)
AND C.contactID = CRP.contactID
AND CRP.contactRoleID = CR.contactRoleID
AND resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'
GROUP BY C.contactID
ORDER BY C.name";
$result = $this->db->processQuery($query, 'assoc');
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['contactID'])) { $result = [$result]; }
foreach ($result as $row) {
array_push($contactsArray, $row);
}
}
//if the org module is installed also get the org contacts from org database
if ($config->settings->organizationsModule == 'Y' && (!$moduleFilter || $moduleFilter == 'organizations')) {
$dbName = $config->settings->organizationsDatabaseName;
$query = "SELECT distinct OC.*, O.name organizationName, GROUP_CONCAT(DISTINCT CR.shortName SEPARATOR '<br /> ') contactRoles
FROM " . $dbName . ".Contact OC, " . $dbName . ".ContactRole CR, " . $dbName . ".ContactRoleProfile CRP, " . $dbName . ".Organization O, Resource R, ResourceAcquisition RA, ResourceOrganizationLink ROL
WHERE (OC.archiveDate = '0000-00-00' OR OC.archiveDate is null)
AND R.resourceID = ROL.resourceID
AND ROL.organizationID = OC.organizationID
AND CRP.contactID = OC.contactID
AND CRP.contactRoleID = CR.contactRoleID
AND O.organizationID = OC.organizationID
AND R.resourceID = RA.resourceID
AND RA.resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'
GROUP BY OC.contactID, O.name
ORDER BY OC.name";
$result = $this->db->processQuery($query, 'assoc');
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['contactID'])) { $result = [$result]; }
foreach ($result as $row) {
array_push($contactsArray, $row);
}
}
return $contactsArray;
}
//returns array of contact objects
public function getArchivedContacts() {
$config = new Configuration;
$contactsArray = array();
//get resource specific contacts
$query = "SELECT C.*, GROUP_CONCAT(CR.shortName SEPARATOR '<br /> ') contactRoles
FROM Contact C, ContactRole CR, ContactRoleProfile CRP
WHERE (archiveDate != '0000-00-00' && archiveDate != '')
AND C.contactID = CRP.contactID
AND CRP.contactRoleID = CR.contactRoleID
AND resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'
GROUP BY C.contactID
ORDER BY C.name";
$result = $this->db->processQuery($query, 'assoc');
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['contactID'])) { $result = [$result]; }
foreach ($result as $row) {
array_push($contactsArray, $row);
}
//if the org module is installed also get the org contacts from org database
if ($config->settings->organizationsModule == 'Y') {
$dbName = $config->settings->organizationsDatabaseName;
$query = "SELECT DISTINCT OC.*, O.name organizationName, GROUP_CONCAT(DISTINCT CR.shortName SEPARATOR '<br /> ') contactRoles
FROM " . $dbName . ".Contact OC, " . $dbName . ".ContactRole CR, " . $dbName . ".ContactRoleProfile CRP, " . $dbName . ".Organization O, Resource R, ResourceAcquisition RA, ResourceOrganizationLink ROL
WHERE (OC.archiveDate != '0000-00-00' && OC.archiveDate is not null)
AND R.resourceID = ROL.resourceID
AND ROL.organizationID = OC.organizationID
AND CRP.contactID = OC.contactID
AND CRP.contactRoleID = CR.contactRoleID
AND O.organizationID = OC.organizationID
AND R.resourceID = RA.resourceID
AND RA.resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'
GROUP BY OC.contactID, O.name
ORDER BY OC.name";
$result = $this->db->processQuery($query, 'assoc');
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['contactID'])) { $result = [$result]; }
foreach ($result as $row) {
array_push($contactsArray, $row);
}
}
return $contactsArray;
}
//returns array of contact objects
public function getContacts() {
$query = "SELECT * FROM Contact
WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['contactID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new Contact(new NamedArguments(array('primaryKey' => $row['contactID'])));
array_push($objects, $object);
}
return $objects;
}
//removes payment records
public function removeResourcePayments() {
$query = "DELETE
FROM ResourcePayment
WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query);
}
//returns array of ResourcePayment objects
public function getResourcePayments() {
$query = "SELECT * FROM ResourcePayment WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "' ORDER BY year DESC, subscriptionStartDate DESC";
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['resourcePaymentID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new ResourcePayment(new NamedArguments(array('primaryKey' => $row['resourcePaymentID'])));
array_push($objects, $object);
}
return $objects;
}
//returns array of attachments objects
public function getAttachments() {
$query = "SELECT * FROM Attachment A, AttachmentType AT
WHERE AT.attachmentTypeID = A.attachmentTypeID
AND resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'
ORDER BY AT.shortName";
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['attachmentID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new Attachment(new NamedArguments(array('primaryKey' => $row['attachmentID'])));
array_push($objects, $object);
}
return $objects;
}
//removes resourceAcquisition authorized sites
public function removeAuthorizedSites() {
$query = "DELETE
FROM ResourceAuthorizedSiteLink
WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query);
}
public function getOrganization() {
if (!$this->organizationID) return null;
$config = new Configuration;
$dbName = $config->settings->organizationsDatabaseName;
$query = ($config->settings->organizationsModule == 'Y') ?
"SELECT name FROM " . $dbName . ".Organization WHERE organizationID = " . $this->organizationID :
"SELECT shortName AS name FROM Organization WHERE organizationID = " . $this->organizationID;
if ($orgResult = $this->db->query($query)) {
while ($orgRow = $orgResult->fetch_assoc()) {
$orgArray['organization'] = $orgRow['name'];
$orgArray['organizationID'] = $this->organizationID;;
}
}
return $orgArray;
}
public function hasCatalogingInformation() {
return ($this->recordSetIdentifier || $this->recordSetIdentifier || $this->bibSourceURL || $this->catalogingTypeID || $this->catalogingStatusID || $this->numberRecordsAvailable || $this->numberRecordsLoaded || $this->hasOclcHoldings);
}
//removes resourceAcquisition administering sites
public function removeAdministeringSites() {
$query = "DELETE
FROM ResourceAdministeringSiteLink
WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query);
}
//removes resource purchase sites
public function removePurchaseSites() {
$query = "DELETE
FROM ResourcePurchaseSiteLink
WHERE resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query);
}
//returns array of purchase site objects
public function getPurchaseSites() {
$query = "SELECT PurchaseSite.* FROM PurchaseSite, ResourcePurchaseSiteLink RPSL where RPSL.purchaseSiteID = PurchaseSite.purchaseSiteID AND resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['purchaseSiteID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new PurchaseSite(new NamedArguments(array('primaryKey' => $row['purchaseSiteID'])));
array_push($objects, $object);
}
return $objects;
}
//returns array of authorized site objects
public function getAuthorizedSites() {
$query = "SELECT AuthorizedSite.* FROM AuthorizedSite, ResourceAuthorizedSiteLink RPSL where RPSL.authorizedSiteID = AuthorizedSite.authorizedSiteID AND resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['authorizedSiteID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new AuthorizedSite(new NamedArguments(array('primaryKey' => $row['authorizedSiteID'])));
array_push($objects, $object);
}
return $objects;
}
public function getAuthorizedSitesLinks() {
$query = "SELECT * FROM ResourceAuthorizedSiteLink where resourceAcquisitionID=" . $this->resourceAcquisitionID;
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['resourceAuthorizedSiteLinkID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new ResourceAuthorizedSiteLink(new NamedArguments(array('primaryKey' => $row['resourceAuthorizedSiteLinkID'])));
array_push($objects, $object);
}
return $objects;
}
public function getPurchaseSitesLinks() {
$query = "SELECT * FROM ResourcePurchaseSiteLink where resourceAcquisitionID=" . $this->resourceAcquisitionID;
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['resourcePurchaseSiteLinkID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new ResourcePurchaseSiteLink(new NamedArguments(array('primaryKey' => $row['resourcePurchaseSiteLinkID'])));
array_push($objects, $object);
}
return $objects;
}
public function getAdministeringSitesLinks() {
$query = "SELECT * FROM ResourceAdministeringSiteLink where resourceAcquisitionID=" . $this->resourceAcquisitionID;
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['resourceAdministeringSiteLinkID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new ResourceAdministeringSiteLink(new NamedArguments(array('primaryKey' => $row['resourceAdministeringSiteLinkID'])));
array_push($objects, $object);
}
return $objects;
}
//returns array of administering site objects
public function getAdministeringSites() {
$query = "SELECT AdministeringSite.* FROM AdministeringSite, ResourceAdministeringSiteLink RPSL where RPSL.administeringSiteID = AdministeringSite.administeringSiteID AND resourceAcquisitionID = '" . $this->resourceAcquisitionID . "'";
$result = $this->db->processQuery($query, 'assoc');
$objects = array();
//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['administeringSiteID'])) { $result = [$result]; }
foreach ($result as $row) {
$object = new AdministeringSite(new NamedArguments(array('primaryKey' => $row['administeringSiteID'])));
array_push($objects, $object);
}
return $objects;
}
// Returns true if today is between the order's subscription start date and end date
// Returns false otherwise
public function isActiveToday() {
$start = new DateTime($this->subscriptionStartDate);
$end = new DateTime($this->subscriptionEndDate);
$now = new DateTime(date("Y-m-d"));