-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCalendarShareUsersHelper.php
More file actions
110 lines (107 loc) · 3.08 KB
/
CalendarShareUsersHelper.php
File metadata and controls
110 lines (107 loc) · 3.08 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
<?php
/**
* Calendar ShareUser Calendar Helper
*
* @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 2014, NetCommons Project
*/
App::uses('AppHelper', 'View/Helper');
/**
* Calendar ShareUser Calendar Helper
*
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @package NetCommons\Calendars\View\Helper
*/
class CalendarShareUsersHelper extends AppHelper {
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'Calendars.CalendarCommon',
'Users.DisplayUser'
);
/**
* getShareUserTitle
*
* 共有ユーザーHTML取得
* この関数が呼ばれるときは共有予定であることが前提とします
* プライベート、共有でないときには使ってはいけません
*
* @param array $vars カレンンダー情報
* @param array $event カレンダー予定
* @param array $shareUsers 共有者
* @return string 共有ユーザーHTML
*/
public function getCalendarShareUserTitle($vars, $event, $shareUsers) {
// 自分が差し込んだものか、もしくは共有された予定か
if ($this->isMyShareEvent($event)) {
$html = __d('calendars', 'People to share the schedule');
} else {
$html = __d('calendars', 'Person who made the schedule');
}
return $html;
}
/**
* getShareUser
*
* 共有ユーザーHTML取得
* この関数が呼ばれるときは共有予定であることが前提とします
* プライベート、共有でないときには使ってはいけません
*
* @param array $vars カレンンダー情報
* @param array $event カレンダー予定
* @param array $shareUsers 共有者
* @return string 共有ユーザーHTML
*/
public function getCalendarShareUser($vars, $event, $shareUsers) {
// 自分が差し込んだものか、もしくは共有された予定か
// 自分の場合、共有者の名まえの羅列
// 差し込まれた場合、XXさんによって共有された予定です
if ($this->isMyShareEvent($event)) {
// 自分が差し込んだ場合は共有者全員
$html = '';
foreach ($shareUsers as $shareUser) {
$html .= $this->DisplayUser->handleLink($shareUser,
array('avatar' => true), [], 'User');
$html .= ', ';
}
$html = trim($html, ', ');
} else {
// ひとさまから差し込まれた場合は
$html = $this->DisplayUser->handleLink($event, array('avatar' => true));
}
return $html;
}
/**
* isShareEvent
* 共有予定か
*
* @param arary $event カレンダー予定
* @return bool
*/
public function isShareEvent($event) {
if (empty($event['CalendarEventShareUser'])) {
return false;
}
return true;
}
/**
* isMyShareEvent
* 自分が差し込んだ共有予定か
*
* @param arary $event カレンダー予定
* @return bool
*/
public function isMyShareEvent($event) {
if ($this->isShareEvent($event) &&
$event['CalendarEvent']['created_user'] == Current::read('User.id')) {
return true;
} else {
return false;
}
}
}