-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPagesTreeBehavior.php
More file actions
103 lines (92 loc) · 3.11 KB
/
PagesTreeBehavior.php
File metadata and controls
103 lines (92 loc) · 3.11 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
<?php
/**
* PageTree Behavior
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
//App::uses('TreeBehavior', 'Model/Behavior');
App::uses('NetCommonsTreeBehavior', 'NetCommons.Model/Behavior');
/**
* Page Behavior
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Pages\Model\Behavior
*/
class PagesTreeBehavior extends NetCommonsTreeBehavior {
/**
* A convenience method for returning a hierarchical array used for HTML select boxes
*
* @param Model $Model Model using this behavior
* @param string|array $conditions SQL conditions as a string or as an array('field' =>'value',...)
* @param string $keyPath A string path to the key, i.e. "{n}.Post.id"
* @param string $valuePath A string path to the value, i.e. "{n}.Post.title"
* @param string $spacer The character or characters which will be repeated
* @param int $recursive The number of levels deep to fetch associated records
* @return array An associative array of records, where the id is the key, and the display field is the value
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::generateTreeList
* @codingStandardsIgnoreStart
*/
public function generateTreeList(Model $Model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = null) {
// @codingStandardsIgnoreEnd
$Model->loadModels([
'PagesLanguage' => 'Pages.PagesLanguage',
]);
$recursive = 0;
if (isset($Model->belongsTo['Room'])) {
$Model->PagesLanguage->useDbConfig = $Model->useDbConfig;
$pageLangConditions = $Model->PagesLanguage->getConditions(array(
'PagesLanguage.page_id = Page.id',
), true);
$Model->bindModel(array(
'belongsTo' => array(
'Space' => array(
'className' => 'Rooms.Space',
'foreignKey' => false,
'conditions' => array(
'Room.space_id = Space.id',
),
'fields' => '',
'order' => ''
),
'PagesLanguage' => array(
'className' => 'Pages.PagesLanguage',
'foreignKey' => false,
'conditions' => array(
'PagesLanguage.page_id = Page.id',
),
'fields' => '',
'order' => ''
),
'OriginPagesLanguage' => array(
'className' => 'Pages.PagesLanguage',
'foreignKey' => false,
'conditions' => array(
'PagesLanguage.page_id = OriginPagesLanguage.page_id',
'OriginPagesLanguage.language_id' => Current::read('Language.id'),
),
'fields' => '',
'order' => ''
),
)
), false);
if ($conditions) {
$conditions = Hash::merge($pageLangConditions, $conditions);
} else {
$conditions = $pageLangConditions;
}
}
$results = parent::generateTreeList(
$Model, $conditions, $keyPath, $valuePath, $spacer, $recursive
);
if (isset($Model->belongsTo['Room'])) {
$Model->unbindModel(
array('belongsTo' => array('Space', 'PagesLanguage', 'OriginPagesLanguage'))
);
}
return $results;
}
}