-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCalendarTopicsBehavior.php
More file actions
144 lines (130 loc) · 4.28 KB
/
CalendarTopicsBehavior.php
File metadata and controls
144 lines (130 loc) · 4.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
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
<?php
/**
* CalendarTopics 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');
App::uses('WorkflowComponent', 'Workflow.Controller/Component');
App::uses('CalendarPermissiveRooms', 'Calendars.Utility');
App::uses('CalendarPlan', 'Calendars.Helper');
App::uses('CalendarPlanRrule', 'Calendars.Helper');
/**
* CalendarTopicsBehavior
*
* @author Allcreator <info@allcreator.net>
* @package NetCommons\Calendars\Model\Behavior
*/
class CalendarTopicsBehavior extends CalendarAppBehavior {
/**
* saveTopics
*
* 新着設定
*
* @param Model $model モデル
* @param int $eventId イベントID(繰り返しの場合は先頭のイベント)
* @return void
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function saveCalendarTopics(Model $model, $eventId) {
$model->loadModels([
'Block' => 'Blocks.Block',
'CalendarEvent' => 'Calendars.CalendarEvent'
]);
// 指定されたイベント情報を取得
$data = $model->CalendarEvent->getEventById($eventId);
if (! $data) {
return;
}
$model->CalendarEvent->set($data);
// プライベート予定のとき、共有者がいたら共有者情報を取得しておく
$shareUsers = $this->_getShareUsers($data);
// すり替え前にオリジナルルームID, オリジナルブロックIDを確保
$originalRoomId = Current::read('Room.id');
$originalBlockId = Current::read('Block.id');
$originalFrameBlockId = Current::read('Frame.block_id');
$originalFrameId = Current::read('Frame.id');
// 予定のルームID
$eventRoomId = $data['CalendarEvent']['room_id'];
// 予定のブロック情報
$eventBlockId = $originalBlockId;
$block = $model->Block->find('first', array(
'conditions' => array(
'plugin_key' => 'calendars',
'room_id' => $eventRoomId
)
));
if ($block) {
$eventBlockId = $block['Block']['id'];
}
// カレントのルームIDをすり替え
Current::$current['Room']['id'] = $eventRoomId;
Current::$current['Block']['id'] = $eventBlockId;
Current::$current['Frame']['block_id'] = $eventBlockId;
Current::$current['Frame']['id'] = null;
$model->CalendarEvent->Behaviors->load('Topics.Topics', array(
'fields' => array(
'path' => '/:plugin_key/calendar_plans/view/:content_key',
'summary' => array('description'),
),
'search_contents' => array(
'title', 'location', 'contact', 'description'
),
'users' => $shareUsers,
'data' => array('is_in_room' => !(int)$shareUsers)
));
$model->CalendarEvent->saveTopics();
$model->CalendarEvent->Behaviors->unload('Topics.Topics');
// すり替えものをリカバー
Current::$current['Room']['id'] = $originalRoomId;
Current::$current['Block']['id'] = $originalBlockId;
Current::$current['Frame']['block_id'] = $originalFrameBlockId;
Current::$current['Frame']['id'] = $originalFrameId;
}
/**
* deleteCalendarTopics
*
* 新着削除
*
* @param Model $model モデル
* @param string $eventKey イベントKey
* @param bool $isOriginRepeat 繰り返しか
* @param string $originEventKey 繰り返しの場合のオリジナルのキー
* @param int $editRrule 削除方法
* @return void
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function deleteCalendarTopics(Model $model, $eventKey, $isOriginRepeat,
$originEventKey, $editRrule) {
// 繰り返し系で
// 全て削除、以外で
// 今のキーと、もともとの繰り返しデータのキーが同じ場合は新着は消さない
if ($isOriginRepeat && $editRrule != CalendarAppBehavior::CALENDAR_PLAN_EDIT_ALL) {
if ($eventKey == $originEventKey) {
return;
}
}
$model->contentKey = $eventKey;
$model->beforeDeleteTopics();
$model->afterDeleteTopics();
}
/**
* _getShareUsers
*
* @param array $data 予定データ
* @return array ShareUser配列
*/
protected function _getShareUsers($data) {
$ret = [];
if (isset($data['CalendarEventShareUser'])) {
foreach ($data['CalendarEventShareUser'] as $shareUser) {
$ret[$shareUser['share_user']] = $shareUser['share_user'];
}
}
return $ret;
}
}