Révision 6d8023f2
Ajouté par Assos Assos il y a plus de 5 ans
drupal7/sites/all/modules/taxonomy_menu/taxonomy_menu.database.inc | ||
---|---|---|
6 | 6 |
* Database functions |
7 | 7 |
*/ |
8 | 8 |
|
9 |
/**
|
|
10 |
* helper function to insert a menu item
|
|
9 |
/** |
|
10 |
* Inserts a menu item.
|
|
11 | 11 |
* |
12 |
* @param $mlid |
|
13 |
* @param $tid |
|
14 |
* @param $vid |
|
12 |
* @param int $mlid |
|
13 |
* Menu link ID. |
|
14 |
* @param int $tid |
|
15 |
* Taxonomy term ID. |
|
16 |
* @param int $vid |
|
17 |
* Vocabulary ID. |
|
15 | 18 |
*/ |
16 | 19 |
function _taxonomy_menu_insert_menu_item($mlid, $tid, $vid) { |
17 | 20 |
$fields = array( |
... | ... | |
23 | 26 |
} |
24 | 27 |
|
25 | 28 |
/** |
26 |
* Return the corresponding menu link id. |
|
29 |
* Returns the corresponding menu link id.
|
|
27 | 30 |
* |
28 |
* @param $tid |
|
29 |
* the term's id |
|
31 |
* @param int $tid |
|
32 |
* Taxonomy term ID. |
|
33 |
* @param int $vid |
|
34 |
* Vocabulary ID. |
|
35 |
* @return int |
|
36 |
* Menu link ID for that taxonomy term. |
|
30 | 37 |
*/ |
31 | 38 |
function _taxonomy_menu_get_mlid($tid, $vid) { |
32 | 39 |
$where = array( |
... | ... | |
37 | 44 |
} |
38 | 45 |
|
39 | 46 |
/** |
40 |
* Retrieve the term / menu relations for a vocab. |
|
47 |
* Retrieves the term / menu relations for a vocab.
|
|
41 | 48 |
* |
42 | 49 |
* @param $vid |
43 |
* vocabulary's id |
|
44 |
* @return |
|
45 |
* array(tid => mlid) |
|
50 |
* Vocabulary ID. |
|
51 |
* |
|
52 |
* @return array |
|
53 |
* Relations to menu link ID as an array keyed by taxonomy term ID. |
|
54 |
* array(tid => mlid) |
|
46 | 55 |
*/ |
47 | 56 |
function _taxonomy_menu_get_menu_items($vid) { |
48 |
|
|
49 |
$result = db_query('SELECT tid, mlid FROM {taxonomy_menu} WHERE vid = :vid', array(':vid' => $vid)); |
|
50 |
$menu_items = array(); |
|
51 |
$menu_items = $result->fetchAllKeyed(); |
|
52 |
return $menu_items; |
|
57 |
return db_query('SELECT tid, mlid FROM {taxonomy_menu} WHERE vid = :vid', array(':vid' => $vid))->fetchAllKeyed(); |
|
53 | 58 |
} |
54 | 59 |
|
55 |
/**
|
|
56 |
* Delete all links associated with this vocab from both the taxonomy_menu
|
|
57 |
* table and the menu_link table.
|
|
58 |
*
|
|
59 |
* @param $vid
|
|
60 |
* vocabulary's id
|
|
61 |
*/
|
|
60 |
/** |
|
61 |
* Deletes all links associated with this vocab from both the taxonomy_menu
|
|
62 |
* table and the menu_link table. |
|
63 |
* |
|
64 |
* @param int $vid
|
|
65 |
* Vocabulary ID.
|
|
66 |
*/ |
|
62 | 67 |
function _taxonomy_menu_delete_all($vid) { |
63 | 68 |
$menu_terms = _taxonomy_menu_get_menu_items($vid); |
64 | 69 |
if (!empty($menu_terms)) { |
... | ... | |
74 | 79 |
} |
75 | 80 |
|
76 | 81 |
/** |
77 |
* Get an array of the tid's related to the node |
|
82 |
* Gets an array of the tid's related to the node |
|
83 |
* |
|
84 |
* @param object $node |
|
85 |
* Node object. |
|
78 | 86 |
* |
79 |
* @param $node
|
|
80 |
* @return array of tids
|
|
87 |
* @return array
|
|
88 |
* Array of taxonomy term IDs.
|
|
81 | 89 |
*/ |
82 | 90 |
function _taxonomy_menu_get_node_terms($node) { |
83 | 91 |
// Get the taxonomy fields. |
... | ... | |
89 | 97 |
if (isset($node->$field_name)) { |
90 | 98 |
$tid_field = $node->$field_name; |
91 | 99 |
// Loop through all the languages. |
92 |
|
|
93 | 100 |
foreach ($tid_field as $tid_field_languages) { |
94 | 101 |
// Loop through all the tids |
95 |
|
|
96 | 102 |
foreach ($tid_field_languages as $tid) { |
97 | 103 |
$tids[] = $tid['tid']; |
98 | 104 |
} |
... | ... | |
103 | 109 |
} |
104 | 110 |
|
105 | 111 |
/** |
106 |
* Get an array of the tid's from the parent
|
|
112 |
* Gets the parent tids for a taxonomy term.
|
|
107 | 113 |
* |
108 |
* @param $tid |
|
109 |
* @return array of tid |
|
114 |
* @param int $tid |
|
115 |
* Taxonomy term ID. |
|
116 |
* |
|
117 |
* @return array |
|
118 |
* Array of taxonomy term IDs. |
|
110 | 119 |
*/ |
111 | 120 |
function _taxonomy_menu_get_parents($tid) { |
112 | 121 |
$output = array(); |
... | ... | |
118 | 127 |
} |
119 | 128 |
|
120 | 129 |
/** |
121 |
* Delete all rows from {taxomony_menu} associated with this tid |
|
122 |
* |
|
123 |
* @param $vid |
|
124 |
* @param $tid |
|
125 |
*/ |
|
130 |
* Deletes all rows from {taxomony_menu} associated with this tid |
|
131 |
* |
|
132 |
* @param $vid |
|
133 |
* @param $tid |
|
134 |
* @param int $vid |
|
135 |
* Vocabulary ID. |
|
136 |
* @param int $tid |
|
137 |
* Taxonomy term ID. |
|
138 |
*/ |
|
126 | 139 |
function _taxonomy_menu_delete_item($vid, $tid) { |
127 | 140 |
$and = db_and()->condition('vid', $vid)->condition('tid', $tid); |
128 | 141 |
db_delete('taxonomy_menu')->condition($and)->execute(); |
129 | 142 |
} |
130 | 143 |
|
131 | 144 |
/** |
132 |
* Get all of the tid for a given vid
|
|
145 |
* Gets all taxonomy terms for a given vocabulary.
|
|
133 | 146 |
* |
134 |
* @param $vid |
|
135 |
* @return array of $tid |
|
147 |
* @param int $vid |
|
148 |
* Vocabulary ID. |
|
149 |
* |
|
150 |
* @return array |
|
151 |
* Array of taxonomy term IDs. |
|
136 | 152 |
*/ |
137 | 153 |
function _taxonomy_menu_get_terms($vid) { |
138 | 154 |
$result = db_select('taxonomy_term_data', 'td') |
... | ... | |
143 | 159 |
} |
144 | 160 |
|
145 | 161 |
/** |
146 |
* @TODO Needs Updating since terms are related via node fields
|
|
162 |
* Gets the count of nodes for each term (without children).
|
|
147 | 163 |
* |
148 |
* used to get the count without children |
|
164 |
* @param int $tid |
|
165 |
* Taxonomy term ID. |
|
149 | 166 |
* |
150 |
* @param $tid |
|
167 |
* @return int |
|
168 |
* Count of nodes that reference the term. |
|
169 |
* |
|
170 |
* @todo Needs updating since terms are related via fields now. |
|
151 | 171 |
*/ |
152 | 172 |
function _taxonomy_menu_term_count($tid) { |
153 | 173 |
$result = db_select('taxonomy_index', 'tn'); |
... | ... | |
160 | 180 |
} |
161 | 181 |
|
162 | 182 |
/** |
163 |
* Get tid for a given mlid
|
|
183 |
* Gets tid for a given mlid.
|
|
164 | 184 |
* |
165 |
* @param $mlid |
|
166 |
* @return $tid |
|
185 |
* @param int $mlid |
|
186 |
* Menu link ID. |
|
187 |
* |
|
188 |
* @return int $tid |
|
189 |
* Taxonomy term ID. |
|
167 | 190 |
*/ |
168 | 191 |
function _taxonomy_menu_get_tid($mlid) { |
169 |
$where = array( |
|
170 |
':mlid' => $mlid, |
|
171 |
); |
|
172 |
return db_query('SELECT tid FROM {taxonomy_menu} WHERE mlid = :mlid', $where)->fetchField(); |
|
192 |
return db_query('SELECT tid FROM {taxonomy_menu} WHERE mlid = :mlid', array(':mlid' => $mlid))->fetchField(); |
|
173 | 193 |
} |
174 | 194 |
|
175 | 195 |
/** |
176 |
* Get vid, tid for a given mlid |
|
196 |
* Gets the vocabulary ID and taxonomy term ID for a given menu link ID. |
|
197 |
* |
|
198 |
* @param int $mlid |
|
199 |
* Menu link ID. |
|
177 | 200 |
* |
178 |
* @param $mlid
|
|
179 |
* @return array of vid, tid
|
|
201 |
* @return array
|
|
202 |
* array(vid, tid)
|
|
180 | 203 |
*/ |
181 | 204 |
function _taxonomy_menu_get_item($mlid) { |
182 | 205 |
$result = db_select('taxonomy_menu', 'tm') |
183 | 206 |
->condition('mlid', $mlid, '=') |
184 | 207 |
->fields('tm', array('tid', 'vid')) |
185 | 208 |
->execute(); |
209 |
|
|
186 | 210 |
return $result->fetch(); |
187 | 211 |
} |
188 | 212 |
|
189 | 213 |
/** |
190 |
* Get the vocabulary for a tid |
|
191 |
* @param $tid array of tids |
|
214 |
* Gets the vocabulary for a taxonomy term ID. |
|
215 |
* |
|
216 |
* @param array $tids |
|
217 |
* Taxonomy term IDs. |
|
218 |
* |
|
192 | 219 |
* @return $vid |
220 |
* Vocabulary ID. |
|
193 | 221 |
*/ |
194 | 222 |
function _taxonomy_menu_get_vid_by_tid($tids) { |
195 | 223 |
if ($tids) { |
... | ... | |
198 | 226 |
->fields('term_data', array('vid')) |
199 | 227 |
->distinct() |
200 | 228 |
->execute(); |
201 |
$vids = array(); |
|
202 | 229 |
return $result->fetchAllAssoc('vid'); |
203 | 230 |
} |
204 | 231 |
} |
205 |
|
|
206 |
/** |
|
207 |
* Options functions |
|
208 |
*/ |
Formats disponibles : Unified diff
Weekly update of contrib modules