Skip to content

Commit

Permalink
Merge pull request #351 from colemanw/tags
Browse files Browse the repository at this point in the history
Fix tag set retrieval
  • Loading branch information
KarinG authored Sep 5, 2020
2 parents e00b307 + a913370 commit f88dd28
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions includes/utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ function wf_crm_get_tags($used_for, $parent_id = NULL) {
}
// Fetch child tags
unset($params['parent_id']);
$params += ['return' => ['name', 'parent_id'], 'parent_id.is_tagset' => 0, 'parent_id.is_selectable' => 1];
$params += ['return' => ['name', 'parent_id'], 'parent_id.is_tagset' => 0, 'parent_id.is_selectable' => 1, 'parent_id.used_for' => $params['used_for']];
$unsorted = wf_crm_apivalues('Tag', 'get', $params);
$parents = array_fill_keys(array_keys($tags), ['depth' => 1]);
// Loop until all children are placed under their parents
while ($unsorted) {
// Place children under their parents.
$prevLoop = NULL;
while ($unsorted && count($unsorted) !== $prevLoop) {
// If count stops going down then we are left with only orphan tags & will abort the loop
$prevLoop = count($unsorted);
foreach ($unsorted as $id => $tag) {
$parent = $tag['parent_id'];
if (isset($parents[$parent])) {
Expand Down

0 comments on commit f88dd28

Please sign in to comment.