/
SourceUpload.php
89 lines (75 loc) · 2.62 KB
/
SourceUpload.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
<?php
require_once 'CRM/Core/Form.php';
class CRM_Finance_Form_Import_SourceUpload extends CRM_Core_Form {
function preProcess() {
$this->assign('formObject', $this);
parent::preProcess( );
}
/**
* Returns form element without buttons
* @return array
*/
public function getUserElements() {
$els = array();
foreach($this->_elements as $el) {
//matusz: group type represents buttons?
if($el->getType() != 'group' && $el->getType() != 'hidden') {
$els[] = $el;
}
}
return $els;
}
public function getTitle() {
$opts = $this->getImportTypeOptions();
$sn = $this->get('sourceName');
$ret = "Upload data";
if($sn) {
$name = $opts[$sn];
$ret .= " - $name";
}
return $ret;
}
private function getImportTypeOptions() {
require_once('CRM/Finance/BAO/Import/Source.php');
return CRM_Finance_BAO_Import_Source::getAllAsOptions();
}
// public function setDefaultValues() {
// $item = $this->getItem();
//
// return array(
// 'supporterName' => 'TODO Supporter name',
// 'contact[1]' => 'TODO Matus Zeman',
// 'contact_select_id[1]' => 1,
// 'pageName' => $item['pageShortName'],
// 'pageDescription' => 'TODO page desc',//$item['pageDescription'],
// 'campaign_id' => 1,//$item['pageDescription'],
// 'issueName' => 'TODO issue #',
// );
// }
function buildQuickForm( ) {
$this->controller->getImportBAO()->buildQuickForm($this);
//$this->addFormRule(array($this, 'formRule'));
$this->addButtons(array(
array ('type' => 'upload',
'name' => ts('Next'),
//'spacing' => ' ',
'isDefault' => true ),
// array ('type' => 'cancel',
// 'name' => ts('Cancel')
// ),
));
}
public function postProcess() {
$params = $this->controller->exportValues( );
$bao = $this->controller->getImportBAO();
$ret = $bao->import($params);
$id = $ret['id'];
$ops = $this->getImportTypeOptions();
$ret['sourceName'] = $ops[$ret['source']];
$this->controller->set('importId', $id);
$this->controller->set('importSummary', $ret);
}
// public function formRule($values) {
// return true;
// }
}