($PROCESSED["group_id"] ? " AND f.`audience_value` = " . $db->qstr($PROCESSED["group_id"]) : "") . "\n ORDER BY c.`course_id`, c.`event_start` DESC"; $event_objectives = $db->GetAll($query); } $query = "\tSELECT a.`objective_id`, a.`objective_name`, a.`objective_parent`\n\n FROM `global_lu_objectives` AS a\n JOIN `objective_organisation` AS b\n ON a.`objective_id` = b.`objective_id`\n\n WHERE a.`objective_parent` = " . $db->qstr($objective_info["objective_parent"] != 0 && $PROCESSED["objective_parent"] == $PROCESSED["id"] ? $objective_info["objective_parent"] : $PROCESSED["objective_parent"]) . "\n AND a.`objective_active` = '1'\n AND b.`organisation_id` = " . $db->qstr($ENTRADA_USER->getActiveOrganisation()) . "\n\n GROUP BY a.`objective_id`\n ORDER BY a.`objective_id` ASC"; $child_objectives = $db->GetAll($query); if ($child_objectives) { $i = 0; foreach ($child_objectives as $child) { if ($PROCESSED["count"] == 1 || $PROCESSED["count"] == 2) { $course_count = array_sum(count_objective_child_courses($child["objective_id"])); } else { $course_count = 0; } $child_objectives[$i]["course_count"] = $course_count; if ($PROCESSED["count"] == 1 || $PROCESSED["count"] == 3) { $event_count = array_sum(count_objective_child_events($child["objective_id"], $SEARCH_DURATION["start"], $SEARCH_DURATION["end"], $PROCESSED["course_id"], $PROCESSED["group_id"])); } else { $event_count = 0; } $child_objectives[$i]["event_count"] = $event_count; $i++; } } $objective_parents = fetch_objective_parents($PROCESSED["objective_parent"]); if ($objective_parents) { $flattened_objectives = flatten_array($objective_parents); for ($i = 0; $i <= count($flattened_objectives); $i++) { if ($i % 2 == 0 && (!empty($flattened_objectives[$i]) && ($flattened_objectives[$i] != $PROCESSED["objective_parent"] || count($objective_parents) == 2))) { $o_breadcrumb[] = "<a class=\"objective-link\" href=\"" . ENTRADA_RELATIVE . "/curriculum/explorer?objective_parent=" . ($flattened_objectives[$i + 2] ? $flattened_objectives[$i + 2] : 0) . "&id=" . $flattened_objectives[$i] . "&step=2\" data-id=\"" . $flattened_objectives[$i] . "\">" . $flattened_objectives[$i + 1] . "</a>"; } else { if ($i % 2 == 0) {
function count_objective_child_events($objective_id = 0, $start = NULL, $end = NULL, $course_id = NULL, $group_id = NULL, $level = 0) { global $db, $ENTRADA_USER; if ($level >= 99) { application_log("error", "Recursion depth out of bounds in [count_objective_child_events]."); return false; } $objective_id = (int) $objective_id; /* Fetch Objective Mapped Events */ $query = "\tSELECT COUNT(DISTINCT a.`event_id`) AS `event_count`\n\t\t\t\tFROM `event_objectives` AS a\n\t\t\t\tJOIN `events` AS b\n\t\t\t\tON a.`event_id` = b.`event_id`\n\t\t\t\tLEFT JOIN `event_audience` AS c\n\t\t\t\tON a.`event_id` = c.`event_id`" . ($group_id != NULL ? " AND c.`audience_type` = 'cohort' " : "") . "\n\t\t\t\tWHERE `objective_id` = " . $db->qstr($objective_id) . ($start != NULL ? " AND (IF (b.`event_id` IS NOT NULL, b.`event_start` BETWEEN " . $db->qstr($start) . " AND " . $db->qstr($end) . ", '1' = '1'))" : "") . ($course_id != NULL ? " AND b.`course_id` = " . $db->qstr($course_id) : "") . ($group_id != NULL ? " AND c.`audience_value` = " . $db->qstr($group_id) : ""); $output[$objective_id] = $db->GetOne($query); /* Fetch objective children */ $query = "\tSELECT a.`objective_id`\n\t\t\t\tFROM `global_lu_objectives` AS a\n\t\t\t\tJOIN `objective_organisation` AS b\n\t\t\t\tON a.`objective_id` = b.`objective_id`\n\t\t\t\tWHERE a.`objective_parent` = " . $db->qstr($objective_id) . "\n\t\t\t\tAND a.`objective_active` = '1'\n\t\t\t\tAND b.`organisation_id` = " . $ENTRADA_USER->getActiveOrganisation(); $children = $db->GetAll($query); if ($children) { foreach ($children as $child) { $child_count = count_objective_child_events($child["objective_id"], $start, $end, $course_id, $group_id, $level++); if (is_array($child_count)) { $return = array_sum($child_count); } else { $return = $event_count; } $output[$child["objective_id"]] = $return; } } return $output; }