-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBlogEntryPermissionComponent.php
More file actions
90 lines (84 loc) · 2.15 KB
/
BlogEntryPermissionComponent.php
File metadata and controls
90 lines (84 loc) · 2.15 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
<?php
/**
* Created by PhpStorm.
* User: ryuji
* Date: 2015/07/23
* Time: 19:23
*/
/**
* Class BlogEntryPermissionComponent
*/
class BlogEntryPermissionComponent extends Component {
/**
* @var Controller 呼び出し元コントローラ startupでセット
*/
protected $_controller = null;
/**
* startup
*
* @param Controller $controller 呼び出し元コントローラ
*
* @return void
*/
public function startup(Controller $controller) {
$this->_controller = $controller;
}
/**
* 編集の権限チェック
*
* @param array $blogEntry コンテンツデータ
* @return bool
*/
public function canEdit($blogEntry) {
if ($this->_controller->viewVars['contentEditable']) {
// 編集権限あり =>OK
} elseif ($this->_controller->viewVars['contentCreatable']) {
// 作成権限あり→自分の記事ならOK
if ($blogEntry['BlogEntry']['created_user'] !== $this->_controller->Auth->user('id')) {
return false;
}
} else {
return false;
}
return true;
}
/**
* 削除権限チェック
*
* @param array $blogEntry コンテンツデータ
* @return bool
*/
public function canDelete($blogEntry) {
// 編集できるかチェック
if ($this->canEdit($blogEntry)) {
// 公開権限あれば削除OK
if ($this->_controller->viewVars['contentPublishable']) {
return true;
}
// 公開権限無しなら一度も公開されてなければ削除OK
if ($this->_controller->BlogEntry->yetPublish($blogEntry)) {
return true;
}
}
// 上記以外削除NG
return false;
}
// ε( v ゚ω゚) <他でも使えるようにするには、ModelをControllerから確保だな
//protected function _getModel() {
// if (isset($this->Controller->{$this->Controller->modelClass})) {
// return $this->Controller->{$this->Controller->modelClass};
// }
//
// $className = null;
// $name = $this->Controller->uses[0];
// if (strpos($this->Controller->uses[0], '.') !== false) {
// list($name, $className) = explode('.', $this->Controller->uses[0]);
// }
// if ($className) {
// return $this->Controller->{$className};
// }
//
// return $this->Controller->{$name};
//
//}
}