-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCabinetFileTree.php
More file actions
95 lines (86 loc) · 2.43 KB
/
CabinetFileTree.php
File metadata and controls
95 lines (86 loc) · 2.43 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
<?php
/**
* CabinetFile Model
*
* @property CabinetCategory $CabinetCategory
* @property CabinetFileTagLink $CabinetFileTagLink
*
* @author Jun Nishikawa <topaz2@m0n0m0n0.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
App::uses('CabinetsAppModel', 'Cabinets.Model');
App::uses('NetCommonsTime', 'NetCommons.Utility');
//App::uses('AttachmentBehavior', 'Files.Model/Behavior');
/**
* Summary for CabinetFile Model
*/
class CabinetFileTree extends CabinetsAppModel {
/**
* @var int recursiveはデフォルトアソシエーションなしに
*/
public $recursive = 0;
/**
* use behaviors
*
* @var array
*/
public $actsAs = array(
'Tree'
);
/**
* beforeFind
*
* @param array $query クエリ
* @return array クエリ
*/
public function beforeFind($query) {
$this->loadModels([
'CabinetFile' => 'Cabinets.CabinetFile',
]);
// workflow連動でアソシエーションさせる!
$association = [
//'CabinetFileTree.cabinet_file_key = CabinetFile.key'
'CabinetFileTree.id = CabinetFile.cabinet_file_tree_id'
];
$cabinetFileCondition = $this->CabinetFile->getWorkflowConditions($association);
$belongsTo = [
'belongsTo' => [
'CabinetFile' => array(
'className' => 'Cabinets.CabinetFile',
'foreignKey' => false,
'conditions' => $cabinetFileCondition,
'fields' => '',
'order' => ''
),
]
];
$this->bindModel($belongsTo, true);
// recursive 0以上の時だけにする NOT NULL 条件を追加する
$recursive = Hash::get($query, 'recursive', $this->recursive);
if ($recursive >= 0) {
// CabinetFileがLEFT JOIN されるが、
// JOINできないTreeレコードを切り捨てるためにCabinetFile.id NOT NULLを条件に入れる
$query['conditions']['NOT']['CabinetFile.id'] = null;
}
return $query;
}
/**
* modifiedを常に更新
*
* @param null $data 登録データ
* @param bool $validate バリデートを実行するか
* @param array $fieldList フィールド
* @return mixed
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function save($data = null, $validate = true, $fieldList = array()) {
// 保存前に modified フィールドをクリアする
$this->set($data);
if (isset($this->data[$this->alias]['modified'])) {
unset($this->data[$this->alias]['modified']);
}
return parent::save($this->data, $validate, $fieldList);
}
}