forked from AppStateESS/InternshipInventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAffiliationContractFactory.php
69 lines (50 loc) · 1.88 KB
/
AffiliationContractFactory.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
<?php
namespace Intern;
class AffiliationContractFactory {
/**
* Saves an AffiliationAgreement into the database
*
* @param AffiliationAgreement
* @returns AffiliationAgreement
* @throws InvalidArgumentException
* @throws Exception
* @throws InternshipNotFoundException
*/
public static function save(AffiliationContract $agreement)
{
if(!isset($agreement) || is_null($agreement)){
throw new \InvalidArgumentException('Missing agreement object');
}
$db = PdoFactory::getPdoInstance();
$values = array('agreementId' => $agreement->getAgreementId(), 'documentId' => $agreement->getDocumentId());
$query = "INSERT INTO intern_agreement_documents
(agreement_id, document_id)
VALUES (:agreementId,:documentId)";
$stmt = $db->prepare($query);
$stmt->execute($values);
}
/**
* Delete row from database that matches this object's $id.
* Also, delete the associated document in filecabinet.
*/
public static function deleteByDocId($docId)
{
if(!isset($docId) || is_null($docId)){
throw new \InvalidArgumentException('Missing document Id');
}
//Delete from intern_agreement_documents
$db = PdoFactory::getPdoInstance();
$values = array('documentId' => $docId);
$query = "DELETE FROM intern_agreement_documents
WHERE document_id = :documentId";
$stmt = $db->prepare($query);
$stmt->execute($values);
//Once its deleted from intern_agreement_documents move to
//deleting from the phpws document database.
$values = array('documentId' => $docId);
$query = "DELETE FROM documents
WHERE id = :documentId";
$stmt = $db->prepare($query);
$stmt->execute($values);
}
}