-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCalendarEntryBehavior.php
More file actions
183 lines (165 loc) · 5.64 KB
/
CalendarEntryBehavior.php
File metadata and controls
183 lines (165 loc) · 5.64 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/**
* CalendarEntry Behavior
*
* @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
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('CalendarAppBehavior', 'Calendars.Model/Behavior');
/**
* CalendarEntryBehavior
*
* @author Allcreator <info@allcreator.net>
* @package NetCommons\Calendars\Model\Behavior
*/
class CalendarEntryBehavior extends CalendarAppBehavior {
/**
* Default settings
*
* 値が変わった時、発動する。
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author AllCreator Co., Ltd. <info@allcreator.net>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2015, NetCommons Project
*/
protected $_defaults = array(
//'calendarRruleModel' => 'Calendars.CalendarRrule',
//'fields' => array(
// 'rrule_id' => 'calendar_rrule_id',
// ),
);
/**
* Setup
*
* @param Model $model instance of model
* @param array $config array of configuration settings.
* @return void
*/
public function setup(Model $model, $config = array()) {
$this->settings[$model->alias] = Hash::merge($this->_defaults, $config);
}
/**
* Checks wether model has the required fields
*
* @param Model $model instance of model
* @return bool True if $model has the required fields
*/
protected function _hasCalendarEntryFields(Model $model) {
$fields = $this->settings[$model->alias]['fields'];
return $model->hasField($fields['description']) && $model->hasField($fields['start_date']);
}
///**
//* Bind relationship on the fly
// *
// * @param Model $model instance of model
// * @param bool $cascade 削除時のカスケード指定
// * @return void
// */
//public function beforeDelete(Model $model, $cascade = true) {
// $this->log("DBG : beforeDelete", LOG_DEBUG);
//
// return parent::beforeDelete($model, $cascade);
//}
/**
* Bind relationship on the fly
*
* @param Model $model instance of model
* @return void
*/
public function afterDelete(Model $model) {
$this->log('DBG : afterDelete', LOG_DEBUG);
return parent::afterDelete($model);
}
/**
* Bind relationship on the fly
*
* @param Model $model instance of model
* @param array $options オプション配列
* @return void
*/
public function beforeSave(Model $model, $options = array()) {
$this->log('DBG: before Save', LOG_DEBUG);
if (isset($this->calendarEntryIndicator)) {
//カレンダー登録指示子(insert|update)があれば、それに従う
//$this->log('DBG: given calendarEntryIndicator[' . $this->calendarEntryIndicator . ']', LOG_DEBUG);
return parent::beforeSave($model, $options);
}
//カレンダー指示子がないので、自分で見つけ出す。
//
$linkPlugin = Current::read('Plugin.name');
$linkPluginModel = $model->alias;
$this->log('DBG: linkPluginModel[' . $linkPluginModel . ']', LOG_DEBUG);
$vars = get_object_vars($model);
$mdl = $vars[$model->alias];
$linkPluginKey = $mdl->data[$model->alias]['key'];
/* FUJI 意味のない処理?後でカットする
$frameAndBlockInfo = array(
'Frame.id' => Current::read('Frame.id'),
'Block.id' => Current::read('Block.id'),
);
$linkPluginOhterInfos = serialize($frameAndBlockInfo);
$this->log('DBG: linkPluginOhterInfos[' . $linkPluginOhterInfos . ']', LOG_DEBUG);
*/
$this->loadEventAndRruleModels($model);
$params = array(
'conditions' => array(
'CalendarEvent.link_plugin' => $linkPlugin,
//'CalendarEvent.link_plugin_model' => $linkPluginModel,
'CalendarEvent.link_key' => $linkPluginKey,
),
'recursive' => -1, //belongTo, hasOneの1跨ぎの関係までとってくる。
'callbacks' => false
);
$count = $model->CalendarEvent->find('count', $params);
if ($count > 0) {
//既にlinkデータがあるので、update
$this->calendarEntryIndicator = 'update';
} else {
//データがないので、insert
$this->calendarEntryIndicator = 'insert';
}
//$this->log('DBG: i descid calendarEntryIndicator[' . $this->calendarEntryIndicator . ']', LOG_DEBUG);
return parent::beforeSave($model, $options);
}
/**
* Bind relationship on the fly
*
* @param Model $model instance of model
* @param bool $created 生成しかたどうか
* @param array $options オプション配列
* @return void
*/
public function afterSave(Model $model, $created, $options = array()) {
$this->log("DBG : afterSave", LOG_DEBUG);
$this->log('DBG: calendarEntryIndicator is[' . $this->calendarEntryIndicator . ']', LOG_DEBUG);
//$this->log("DBG : All Current Props[" . print_r( Current::read(), true). "]", LOG_DEBUG);
return;
/*
* 以下、コーディング中。
*
if (!$this->_hasCalendarEntryFields($model)) {
$this->log("DBG : nop", LOG_DEBUG);
return;
}
$this->log("DBG : OK created[" . $created . "]", LOG_DEBUG);
//$this->log("DBG :" . serialize($model->data), LOG_DEBUG);
$fields = $this->settings[$model->alias]['fields'];
//$this->log("DBG : description[" . $model->data[$model->alias][$fields['description']] . "]", LOG_DEBUG);
//$this->log("DBG : start_date[" . $model->data[$model->alias][$fields['start_date']] . "]", LOG_DEBUG);
if (!$model->Behaviors->hasMethod('insertPlan')) {
$model->Behaviors->load('Calendars.CalendarInsertPlan');
}
$planParams = array(
'description' => $model->data[$model->alias][$fields['description']],
'start_date' => $model->data[$model->alias][$fields['start_date']],
);
$this->log("DBG : planParams[" . serialize($planParams) . "]", LOG_DEBUG);
$model->insertPlan($planParams);
*/
}
}