Commit | Line | Data |
---|---|---|
f532671f CW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
f532671f | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
f532671f | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
f532671f CW |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
f532671f CW |
16 | */ |
17 | ||
18 | /** | |
2b4bc760 | 19 | * This class previews the uploaded file and returns summary statistics. |
20 | * | |
f532671f CW |
21 | * TODO: CRM-11254 - if preProcess and postProcess functions can be reconciled between the 5 child classes, |
22 | * those classes can be removed entirely and this class will not need to be abstract | |
23 | */ | |
9d7974eb | 24 | abstract class CRM_Import_Form_Preview extends CRM_Import_Forms { |
971e129b | 25 | |
f532671f | 26 | /** |
2b4bc760 | 27 | * Return a descriptive name for the page, used in wizard header. |
f532671f CW |
28 | * |
29 | * @return string | |
f532671f CW |
30 | */ |
31 | public function getTitle() { | |
32 | return ts('Preview'); | |
33 | } | |
34 | ||
9d7974eb EM |
35 | /** |
36 | * Assign common values to the template. | |
37 | */ | |
38 | public function preProcess() { | |
4d9f4d69 | 39 | $this->assignPreviewVariables(); |
9d7974eb EM |
40 | } |
41 | ||
f532671f | 42 | /** |
fe482240 | 43 | * Build the form object. |
f532671f CW |
44 | */ |
45 | public function buildQuickForm() { | |
4c7e1926 CW |
46 | |
47 | // FIXME: This is a hack... | |
48 | // The tpl contains javascript that starts the import on form submit | |
49 | // Since our back/cancel buttons are of html type "submit" we have to prevent a form submit event when they are clicked | |
50 | // Hacking in some onclick js to make them act more like links instead of buttons | |
51 | $path = CRM_Utils_System::currentPath(); | |
52 | $query = ['_qf_MapField_display' => 'true']; | |
53 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String'); | |
54 | if (CRM_Utils_Rule::qfKey($qfKey)) { | |
55 | $query['qfKey'] = $qfKey; | |
56 | } | |
57 | $previousURL = CRM_Utils_System::url($path, $query, FALSE, NULL, FALSE); | |
58 | $cancelURL = CRM_Utils_System::url($path, 'reset=1', FALSE, NULL, FALSE); | |
59 | ||
be2fb01f | 60 | $this->addButtons([ |
4c7e1926 CW |
61 | [ |
62 | 'type' => 'back', | |
63 | 'name' => ts('Previous'), | |
64 | 'js' => ['onclick' => "location.href='{$previousURL}'; return false;"], | |
65 | ], | |
66 | [ | |
67 | 'type' => 'next', | |
68 | 'name' => ts('Import Now'), | |
69 | 'spacing' => ' ', | |
70 | 'isDefault' => TRUE, | |
71 | ], | |
72 | [ | |
73 | 'type' => 'cancel', | |
74 | 'name' => ts('Cancel'), | |
75 | 'js' => ['onclick' => "location.href='{$cancelURL}'; return false;"], | |
76 | ], | |
971e129b | 77 | ]); |
f532671f CW |
78 | } |
79 | ||
8cebffb2 JP |
80 | /** |
81 | * Set status url for ajax. | |
82 | */ | |
83 | public function setStatusUrl() { | |
84 | $statusID = $this->get('statusID'); | |
85 | if (!$statusID) { | |
86 | $statusID = md5(uniqid(rand(), TRUE)); | |
87 | $this->set('statusID', $statusID); | |
88 | } | |
89 | $statusUrl = CRM_Utils_System::url('civicrm/ajax/status', "id={$statusID}", FALSE, NULL, FALSE); | |
90 | $this->assign('statusUrl', $statusUrl); | |
91 | } | |
92 | ||
4d9f4d69 EM |
93 | /** |
94 | * Assign smarty variables for the preview screen. | |
95 | * | |
96 | * @throws \API_Exception | |
97 | * @throws \CRM_Core_Exception | |
98 | */ | |
99 | protected function assignPreviewVariables(): void { | |
100 | $this->assign('downloadErrorRecordsUrl', $this->getDownloadURL(CRM_Import_Parser::ERROR)); | |
101 | $this->assign('invalidRowCount', $this->getRowCount(CRM_Import_Parser::ERROR)); | |
102 | $this->assign('validRowCount', $this->getRowCount(CRM_Import_Parser::VALID)); | |
103 | $this->assign('totalRowCount', $this->getRowCount([])); | |
104 | $this->assign('mapper', $this->getMappedFieldLabels()); | |
105 | $this->assign('dataValues', $this->getDataRows([], 2)); | |
106 | $this->assign('columnNames', $this->getColumnHeaders()); | |
107 | //get the mapping name displayed if the mappingId is set | |
108 | $mappingId = $this->get('loadMappingId'); | |
109 | if ($mappingId) { | |
110 | $mapDAO = new CRM_Core_DAO_Mapping(); | |
111 | $mapDAO->id = $mappingId; | |
112 | $mapDAO->find(TRUE); | |
113 | } | |
114 | $this->assign('savedMappingName', $mappingId ? $mapDAO->name : NULL); | |
115 | $this->assign('skipColumnHeader', $this->getSubmittedValue('skipColumnHeader')); | |
116 | // rowDisplayCount is deprecated - it used to be used with {section} but we have nearly gotten rid of it. | |
117 | $this->assign('rowDisplayCount', $this->getSubmittedValue('skipColumnHeader') ? 3 : 2); | |
118 | } | |
119 | ||
f532671f | 120 | } |