Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
aba1cd8b EM |
2 | |
3 | /** | |
4 | * Class PCPBlock | |
5 | */ | |
6a488035 TO |
6 | class PCPBlock extends PHPUnit_Framework_Testcase { |
7 | /** | |
8 | * Helper function to create a PCP Block for Contribution Page | |
9 | * | |
10 | * @param int $contributionPageId - id of the Contribution Page | |
11 | * to be deleted | |
12 | * @return array of created pcp block | |
13 | * | |
14 | */ | |
15 | function create($contributionPageId) { | |
16 | $profileParams = array( | |
17 | 'group_type' => 'Individual,Contact', | |
18 | 'title' => 'Test Supprorter Profile', | |
19 | 'help_pre' => 'Profle to PCP Contribution', | |
20 | 'is_active' => 1, | |
21 | 'is_cms_user' => 2, | |
22 | ); | |
23 | ||
24 | $ufGroup = civicrm_api('uf_group', 'create', $profileParams); | |
25 | $profileId = $ufGroup['id']; | |
26 | ||
27 | $fieldsParams = array( | |
28 | array( | |
29 | 'field_name' => 'first_name', | |
30 | 'field_type' => 'Individual', | |
31 | 'visibility' => 'Public Pages and Listings', | |
32 | 'weight' => 1, | |
33 | 'label' => 'First Name', | |
34 | 'is_required' => 1, | |
35 | 'is_active' => 1, | |
36 | ), | |
37 | array( | |
38 | 'field_name' => 'last_name', | |
39 | 'field_type' => 'Individual', | |
40 | 'visibility' => 'Public Pages and Listings', | |
41 | 'weight' => 2, | |
42 | 'label' => 'Last Name', | |
43 | 'is_required' => 1, | |
44 | 'is_active' => 1, | |
45 | ), | |
46 | array( | |
47 | 'field_name' => 'email', | |
48 | 'field_type' => 'Contact', | |
49 | 'visibility' => 'Public Pages and Listings', | |
50 | 'weight' => 3, | |
51 | 'label' => 'Email', | |
52 | 'is_required' => 1, | |
53 | 'is_active' => 1, | |
54 | ), | |
55 | ); | |
56 | ||
57 | foreach ($fieldsParams as $value) { | |
58 | // we assume api v3. | |
59 | $value['version'] = 3; | |
60 | $value['uf_group_id'] = $profileId; | |
61 | $ufField = civicrm_api('uf_field', 'create', $value); | |
62 | } | |
63 | ||
64 | $joinParams = array( | |
65 | 'module' => 'Profile', | |
66 | 'entity_table' => 'civicrm_contribution_page', | |
67 | 'entity_id' => 1, | |
68 | 'weight' => 1, | |
69 | 'uf_group_id' => $profileId, | |
70 | 'is_active' => 1, | |
71 | ); | |
72 | $ufJoin = civicrm_api('uf_join', 'create', $joinParams); | |
73 | ||
74 | $params = array( | |
75 | 'entity_table' => 'civicrm_contribution_page', | |
76 | 'entity_id' => $contributionPageId, | |
77 | 'supporter_profile_id' => $profileId, | |
78 | 'is_approval_needed' => 0, | |
79 | 'is_tellfriend_enabled' => 0, | |
80 | 'tellfriend_limit' => 0, | |
81 | 'link_text' => 'Create your own Personal Campaign Page!', | |
82 | 'is_active' => 1, | |
83 | 'notify_email' => 'info@civicrm.org', | |
84 | ); | |
85 | require_once 'CRM/Contribute/BAO/PCP.php'; | |
86 | $blockPCP = CRM_Contribute_BAO_PCP::add($params); | |
87 | return array('blockId' => $blockPCP->id, 'profileId' => $profileId); | |
88 | } | |
89 | ||
90 | /** | |
91 | * Helper function to delete a PCP related stuff viz. Profile, PCP Block Entry | |
92 | * | |
93 | * @param array key value pair | |
94 | * pcpBlockId - id of the PCP Block Id, profileID - id of Supporter Profile | |
95 | * to be deleted | |
96 | * @return boolean true if success, false otherwise | |
97 | * | |
98 | */ | |
99 | function delete($params) { | |
100 | ||
101 | $delete_params = array('id' => $params['profileId']); | |
102 | $resulProfile = civicrm_api('uf_group', 'delete', $delete_params); | |
103 | ||
104 | ||
105 | require_once 'CRM/Contribute/DAO/PCPBlock.php'; | |
106 | $dao = new CRM_Contribute_DAO_PCPBlock(); | |
107 | $dao->id = $params['blockId']; | |
108 | if ($dao->find(TRUE)) { | |
109 | $resultBlock = $dao->delete(); | |
110 | } | |
111 | if ($id = CRM_Utils_Array::value('pcpId', $params)) { | |
112 | require_once 'CRM/Contribute/BAO/PCP.php'; | |
113 | CRM_Contribute_BAO_PCP::delete($id); | |
114 | } | |
115 | if ($resulProfile && $resultBlock) { | |
116 | return TRUE; | |
117 | } | |
118 | return FALSE; | |
119 | } | |
120 | } |