-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRegistrationExport.php
More file actions
133 lines (123 loc) · 4.12 KB
/
RegistrationExport.php
File metadata and controls
133 lines (123 loc) · 4.12 KB
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
<?php
/**
* RegistrationExport Model
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author AllCreator <info@allcreator.net>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
App::uses('RegistrationsAppModel', 'Registrations.Model');
App::uses('WysIsWygDownloader', 'Registrations.Utility');
App::uses('RegistrationsComponent', 'Registrations.Controller/Component');
/**
* Summary for Registration Model
*/
class RegistrationExport extends RegistrationsAppModel {
/**
* Use table config
*
* @var bool
*/
public $useTable = 'registrations';
/**
* use behaviors
*
* @var array
*/
public $actsAs = array(
'AuthorizationKeys.AuthorizationKey',
);
/**
* Validation rules
*
* @var array
*/
public $validate = array();
/**
* getExportData
*
* @param string $registrationKey 登録フォームキー
* @return array RegistrationData for Export
*/
public function getExportData($registrationKey) {
// 登録フォームデータをjsonにして記述した内容を含むZIPファイルを作成する
$zipData = array();
// バージョン情報を取得するためComposer情報を得る
$Plugin = ClassRegistry::init('Plugins.Plugin');
$composer = $Plugin->getComposer('netcommons/registrations');
// 最初のデータは登録フォームプラグインのバージョン
$zipData['version'] = $composer['version'];
// 言語数分
$Language = ClassRegistry::init('Languages.Language');
$languages = $Language->find('all', array(
'recursive' => -1
));
$Registration = ClassRegistry::init('Registrations.Registration');
$registrations = array();
foreach ($languages as $lang) {
// 指定の登録フォームデータを取得
$registration = $Registration->find('first', array(
'conditions' => array(
'Registration.key' => $registrationKey,
'Registration.is_active' => true,
'Registration.is_latest' => true,
'Registration.language_id' => $lang['Language']['id']
),
'recursive' => 0
));
// 指定の言語データがない場合もあることを想定
if (empty($registration)) {
continue;
}
$registration = Hash::remove($registration, 'Block');
$registration = Hash::remove($registration, 'TrackableCreator');
$registration = Hash::remove($registration, 'TrackableUpdater');
$Registration->clearRegistrationId($registration);
$registrations[] = $registration;
}
$zipData['Registrations'] = $registrations;
return $zipData;
}
/**
* putToZip
*
* @param ZipDownloader $zipFile ZIPファイルオブジェクト
* @param array $zipData zip data
* @return void
*/
public function putToZip($zipFile, $zipData) {
$this->Registration = ClassRegistry::init('Registrations.Registration');
$this->RegistrationPage = ClassRegistry::init('Registrations.RegistrationPage');
$this->RegistrationQuestion = ClassRegistry::init('Registrations.RegistrationQuestion');
$wysiswyg = new WysIsWygDownloader();
// 登録フォームデータの中でもWYSISWYGデータのものについては
// フォルダ別に確保(フォルダの中にZIPがある)
$flatRegistration = Hash::flatten($zipData);
foreach ($flatRegistration as $key => &$value) {
$model = null;
if (strpos($key, 'RegistrationQuestion.') !== false) {
$model = $this->RegistrationQuestion;
} elseif (strpos($key, 'RegistrationPage.') !== false) {
$model = $this->RegistrationPage;
} elseif (strpos($key, 'Registration.') !== false) {
$model = $this->Registration;
}
if (!$model) {
continue;
}
$columnName = substr($key, strrpos($key, '.') + 1);
if ($model->hasField($columnName)) {
if ($model->getColumnType($columnName) == 'text') {
$wysiswygZipFile = $wysiswyg->createWysIsWygZIP($model->alias . '.' . $columnName, $value);
$wysiswygFileName = $key . '.zip';
$zipFile->addFile($wysiswygZipFile, $wysiswygFileName);
$value = $wysiswygFileName;
}
}
}
$registration = Hash::expand($flatRegistration);
// jsonデータにして書き込み
$zipFile->addFromString(RegistrationsComponent::REGISTRATION_JSON_FILENAME, json_encode($registration));
}
}