/** * Whether or not the rule is matched. * * @param user_competency $usercompetency The user competency. * @return bool */ public function matches(user_competency $usercompetency) { global $DB; // TODO Improve performance here, perhaps the caller could already provide records. $children = competency::get_records(array('parentid' => $this->competency->get_id())); if (empty($children)) { // Leaves are not compatible with this rule. return false; } $ids = array(); foreach ($children as $child) { $ids[] = $child->get_id(); } list($insql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED); $sql = "userid = :userid\n AND proficiency = :proficiency\n AND competencyid {$insql}"; $params['userid'] = $usercompetency->get_userid(); $params['proficiency'] = 1; // Is the user is marked as proficient in all children? return user_competency::count_records_select($sql, $params) === count($ids); }