-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathNetCommonsTimeComponent.php
More file actions
79 lines (73 loc) · 2.16 KB
/
NetCommonsTimeComponent.php
File metadata and controls
79 lines (73 loc) · 2.16 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
<?php
/**
* NetCommonsTimeComponent
*
* @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('NetCommonsTime', 'NetCommons.Utility');
/**
* Class NetCommonsTimeComponent
*
* NetCommonsFormHelper::input()で、typeをdatetimeに指定された項目の値を
* サーバータイムゾーン(UTC)に変換します。
*
* #### サンプルコード(Viewテンプレート)
* ```
* <?php
* echo $this->NetCommonsForm->input(
* 'publish_start',
* array('type' => 'datetime')
* );
* ?>
* ```
*
*/
class NetCommonsTimeComponent extends Component {
/**
* @var NetCommonsTime NetCommonsTimeのインスタンス
*/
protected $_netCommonsTime;
/**
* コントローラの beforeFilter メソッドの前に呼び出されます。
*
* @param Controller $controller コントローラ
* @return void
*/
public function initialize(Controller $controller) {
$this->_netCommonsTime = new NetCommonsTime();
$this->_convertTimezone($controller);
}
/**
* ラップ用マジックメソッド。
*
* @param string $method メソッド
* @param array $params パラメータ
* @return mixed
*/
public function __call($method, $params) {
return call_user_func_array(array($this->_netCommonsTime, $method), $params);
}
/**
* ユーザタイムゾーンからサーバータイムゾーンへの自動変換
* NetCommonsFormと連携している
*
* @param Controller $controller コントローラ
* @return void
*/
protected function _convertTimezone(Controller $controller) {
if (isset($controller->request->data['_NetCommonsTime']['user_timezone'])) {
$userTimezone = $controller->request->data['_NetCommonsTime']['user_timezone'];
$convertFieldsString = isset($controller->request->data['_NetCommonsTime']['convert_fields']) ?
$controller->request->data['_NetCommonsTime']['convert_fields'] :
'';
$convertFields = explode(',', $convertFieldsString);
$controller->request->data = $this->_netCommonsTime->toServerDatetimeArray(
$controller->request->data,
$convertFields,
$userTimezone
);
}
}
}