Révision c304a780
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/ctools/plugins/access/term_has_parent.inc | ||
---|---|---|
1 | 1 |
<?php |
2 |
|
|
2 | 3 |
/** |
3 | 4 |
* @file |
4 | 5 |
* Plugin to provide access control based upon a parent term. |
... | ... | |
20 | 21 |
); |
21 | 22 |
|
22 | 23 |
/** |
23 |
* Settings form for the 'by parent term' access plugin |
|
24 |
* Settings form for the 'by parent term' access plugin.
|
|
24 | 25 |
*/ |
25 | 26 |
function ctools_term_has_parent_ctools_access_settings($form, &$form_state, $conf) { |
26 | 27 |
// If no configuration was saved before, set some defaults. |
... | ... | |
49 | 50 |
// A note: Dependency works strangely on these forms as they have never been |
50 | 51 |
// updated to a more modern system so they are not individual forms of their |
51 | 52 |
// own like the content types. |
52 |
|
|
53 | 53 |
$form['settings']['#tree'] = TRUE; |
54 | 54 |
|
55 | 55 |
// Loop over each of the configured vocabularies. |
... | ... | |
62 | 62 |
'#default_value' => !empty($conf['vid_' . $vid]) ? $conf['vid_' . $vid] : '', |
63 | 63 |
'#size' => 10, |
64 | 64 |
'#multiple' => TRUE, |
65 |
//@todo: Remove the following workaround when the following patch is in core. {@see:http://drupal.org/node/1117526} |
|
65 |
// @todo: Remove the following workaround when the following patch is in core. {@see:http://drupal.org/node/1117526}
|
|
66 | 66 |
'#name' => sprintf("settings[%u][]", $vid), |
67 | 67 |
'#attributes' => array('multiple' => 'multiple'), |
68 | 68 |
); |
... | ... | |
71 | 71 |
foreach (taxonomy_get_tree($vocabulary->vid) as $term) { |
72 | 72 |
$terms[$term->tid] = str_repeat('-', $term->depth) . ($term->depth ? ' ' : '') . $term->name; |
73 | 73 |
} |
74 |
//$form['settings']['vid_' . $vid]['#type'] = 'select'; |
|
75 | 74 |
$form['settings']['vid_' . $vid]['#type'] = 'checkboxes'; |
76 | 75 |
$form['settings']['vid_' . $vid]['#options'] = $terms; |
77 | 76 |
unset($terms); |
... | ... | |
116 | 115 |
// we'll start looking up the hierarchy from our context term id. |
117 | 116 |
$current_term = $context->data->tid; |
118 | 117 |
|
119 |
$term='';
|
|
118 |
$term = '';
|
|
120 | 119 |
|
121 |
// scan up the tree.
|
|
122 |
while (true) {
|
|
123 |
// select parent as term_parent to avoid PHP5 complications with the parent keyword
|
|
124 |
//@todo: Find a way to reduce the number of queries required for really deep hierarchies. |
|
125 |
$term = db_query("SELECT parent AS term_parent, tid AS tid FROM {taxonomy_term_hierarchy} th WHERE th.tid = :tid", array(':tid'=>$current_term))->fetchObject();
|
|
120 |
// Scan up the tree.
|
|
121 |
while (TRUE) {
|
|
122 |
// Select parent as term_parent to avoid PHP5 complications with the parent keyword.
|
|
123 |
// @todo: Find a way to reduce the number of queries required for really deep hierarchies.
|
|
124 |
$term = db_query("SELECT parent AS term_parent, tid AS tid FROM {taxonomy_term_hierarchy} th WHERE th.tid = :tid", array(':tid' => $current_term))->fetchObject();
|
|
126 | 125 |
|
127 |
// if no term is found, get out of the loop
|
|
126 |
// If no term is found, get out of the loop.
|
|
128 | 127 |
if (!$term || empty($term->tid)) { |
129 | 128 |
break; |
130 | 129 |
} |
131 | 130 |
|
132 |
// check the term selected, if the user asked it to.
|
|
131 |
// Check the term selected, if the user asked it to.
|
|
133 | 132 |
if (!empty($conf['include_self']) && isset($conf['vid_' . $vid][$term->tid])) { |
134 | 133 |
return TRUE; |
135 | 134 |
} |
136 | 135 |
|
137 |
// did we find the parent TID we were looking for?
|
|
136 |
// Did we find the parent TID we were looking for?
|
|
138 | 137 |
if (isset($conf['vid_' . $vid][$term->tid])) { |
139 | 138 |
// YES, we're done! |
140 | 139 |
return TRUE; |
141 | 140 |
} |
142 | 141 |
// Nope, we didn't find it. |
143 |
|
|
144 | 142 |
// If this is the top of the hierarchy, stop scanning. |
145 |
if ($term->term_parent==0) {
|
|
143 |
if ($term->term_parent == 0) {
|
|
146 | 144 |
break; |
147 | 145 |
} |
148 | 146 |
|
149 |
// update the parent, and keep scanning.
|
|
147 |
// Update the parent, and keep scanning.
|
|
150 | 148 |
$current_term = $term->term_parent; |
151 | 149 |
} |
152 | 150 |
|
... | ... | |
157 | 155 |
* Provide a summary description based upon the checked terms. |
158 | 156 |
*/ |
159 | 157 |
function ctools_term_has_parent_ctools_access_summary($conf, $context) { |
160 |
$vid = (int)$conf['vid']; |
|
158 |
$vid = (int) $conf['vid'];
|
|
161 | 159 |
$terms = array(); |
162 | 160 |
foreach ($conf['vid_' . $vid] as $tid) { |
163 | 161 |
$term = taxonomy_term_load($tid); |
... | ... | |
167 | 165 |
return format_plural(count($terms), |
168 | 166 |
'@term can have the parent "@terms"', |
169 | 167 |
'@term can have one of these parents: @terms', |
170 |
array('@terms' => implode(', ', $terms), |
|
171 |
'@term' => $context->identifier)); |
|
168 |
array( |
|
169 |
'@terms' => implode(', ', $terms), |
|
170 |
'@term' => $context->identifier, |
|
171 |
)); |
|
172 | 172 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules