-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathNetCommonsTimeHelper.php
More file actions
99 lines (87 loc) · 2.28 KB
/
NetCommonsTimeHelper.php
File metadata and controls
99 lines (87 loc) · 2.28 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
<?php
/**
* NetCommonsTimeHelper
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
App::uses('AppHelper', 'View/Helper');
App::uses('NetCommonsTime', 'NetCommons.Utility');
/**
* Class NetCommonsTimeHelper
*/
class NetCommonsTimeHelper extends AppHelper {
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'Form',
);
/**
* @var NetCommonsTime NetCommonsTimeのインスタンス
*/
protected $_netCommonsTime = null;
/**
* @var array タイムゾーン変換対象フィールド
*/
protected $_convertFields = array();
/**
* コンストラクタ
*
* @param View $View The View this helper is being attached to.
* @param array $settings Configuration settings for the helper.
* @return NetCommonsTimeHelper
*/
public function __construct(View $View, $settings = array()) {
$this->_netCommonsTime = new NetCommonsTime();
parent::__construct($View, $settings);
}
/**
* NetCommonsTime ラップ用マジックメソッド。
*
* @param string $method メソッド
* @param array $params パラメータ
* @return mixed
*/
public function __call($method, $params) {
return call_user_func_array(array($this->_netCommonsTime, $method), $params);
}
/**
* コンバートするFieldsをセットする処理
* NetCommonsForm::inputから呼ばれる。
*
* @param string $fieldName field name
* @param array $options options
* @return void
*/
public function beforeFormInput($fieldName, $options) {
if (Hash::get($options, 'convert_timezone') === true) {
if (strpos($fieldName, '.') === false) {
$fieldName = $this->Form->defaultModel . '.' . $fieldName;
}
$this->_convertFields[] = $fieldName;
}
}
/**
* Timezone変換の準備を組み込んだForm::end
*
* @return string $out timezone変換用のhiddenタグ
*/
public function beforeFormEnd() {
$out = '';
// modelをみてdatetime
$out .= $this->Form->hidden(
'_NetCommonsTime.user_timezone',
array('value' => Current::read('User.timezone'))
);
$out .= $this->Form->hidden(
'_NetCommonsTime.convert_fields',
array('value' => implode(',', $this->_convertFields))
);
$this->_convertFields = array();
return $out;
}
}