示例#1
0
 /**
  * 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);
 }
示例#2
0
 /**
  * Perform a search based on the provided filters and return a paginated list of records.
  *
  * Requires moodle/competency:competencyview capability at some context.
  *
  * @param array $filters A list of filters to apply to the list.
  * @param string $sort The column to sort on
  * @param string $order ('ASC' or 'DESC')
  * @param int $skip Number of records to skip (pagination)
  * @param int $limit Max of records to return (pagination)
  * @return array of competencies
  */
 public static function list_competencies($filters, $sort = '', $order = 'ASC', $skip = 0, $limit = 0)
 {
     static::require_enabled();
     if (!isset($filters['competencyframeworkid'])) {
         $context = context_system::instance();
     } else {
         $framework = new competency_framework($filters['competencyframeworkid']);
         $context = $framework->get_context();
     }
     // First we do a permissions check.
     if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'), $context)) {
         throw new required_capability_exception($context, 'moodle/competency:competencyview', 'nopermissions', '');
     }
     // OK - all set.
     return competency::get_records($filters, $sort, $order, $skip, $limit);
 }