Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions Model/Behavior/WorkflowBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,23 @@ private function __hasSaveField(Model $model, $needle) {
*
* @param Model $model Model using this behavior
* @param array $conditions Model::find conditions default value
* @param bool $useCommentCreatable コメントの作成権限でもチェックするかどうか
* @return array Conditions data
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function getWorkflowConditions(Model $model, $conditions = array()) {
public function getWorkflowConditions(
Model $model,
$conditions = array(),
$useCommentCreatable = false
) {
if (Current::permission('content_editable')) {
$activeConditions = array();
$latestConditons = array(
$model->alias . '.is_latest' => true,
);
} elseif (Current::permission('content_creatable')) {
} elseif (Current::permission('content_creatable') ||
$useCommentCreatable && Current::permission('content_comment_creatable')) {
$activeConditions = array(
$model->alias . '.is_active' => true,
$model->alias . '.created_user !=' => Current::read('User.id'),
Expand Down Expand Up @@ -318,12 +325,19 @@ public function getWorkflowConditions(Model $model, $conditions = array()) {
* @param Model $model Model using this behavior
* @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
* @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
* @param bool $useCommentCreatable コメントの作成権限でもチェックするかどうか
* @return array Conditions data
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function getWorkflowContents(Model $model, $type, $query = array()) {
public function getWorkflowContents(
Model $model,
$type,
$query = array(),
$useCommentCreatable = false
) {
$query = Hash::merge(array(
'recursive' => -1,
'conditions' => $this->getWorkflowConditions($model)
'conditions' => $this->getWorkflowConditions($model, [], $useCommentCreatable)
), $query);

return $model->find($type, $query);
Expand Down Expand Up @@ -384,7 +398,8 @@ public function canEditWorkflowContent(Model $model, $data) {
* @return bool true:削除可、false:削除不可
*/
public function canDeleteWorkflowContent(Model $model, $data) {
if (! $this->canEditWorkflowContent($model, $data)) {
//Model側で継承している場合、そのcanEditWorkflowContentが実行されるように、$thisではなく、$modelで呼び出す。
if (! $model->canEditWorkflowContent($data)) {
return false;
}
if (Current::permission('content_publishable')) {
Expand Down