original_string: public static function count_records_for_template($templateid, $proficiency=null) {
          global $DB;
  
          $params = array('templateid' => $templateid);
          $sql = 'SELECT ' . " COUNT('x') " .
                   'FROM {' . self::TABLE . '} ucp
                    JOIN {' . plan::TABLE . '} p
                      ON ucp.planid = p.id
                   WHERE p.templateid = :templateid';
          if ($proficiency === true) {
              $sql .= ' AND ucp.proficiency = :proficiency';
              $params['proficiency'] = true;
          } else if ($proficiency === false) {
              $sql .= ' AND (ucp.proficiency = :proficiency OR ucp.proficiency IS NULL)';
              $params['proficiency'] = false;
          }
  
          return $DB->count_records_sql($sql, $params);
      }
code: public static function count_records_for_template($templateid, $proficiency=null) {
          global $DB;
  
          $params = array('templateid' => $templateid);
          $sql = 'SELECT ' . " COUNT('x') " .
                   'FROM {' . self::TABLE . '} ucp
                    JOIN {' . plan::TABLE . '} p
                      ON ucp.planid = p.id
                   WHERE p.templateid = :templateid';
          if ($proficiency === true) {
              $sql .= ' AND ucp.proficiency = :proficiency';
              $params['proficiency'] = true;
          } else if ($proficiency === false) {
              $sql .= ' AND (ucp.proficiency = :proficiency OR ucp.proficiency IS NULL)';
              $params['proficiency'] = false;
          }
  
          return $DB->count_records_sql($sql, $params);
      }
code_tokens: public static function count_records_for_template ( $ templateid , $ proficiency = null ) { global $ DB ; $ params = array ( 'templateid' => $ templateid ) ; $ sql = 'SELECT ' . " COUNT('x') " . 'FROM {' . self :: TABLE . '} ucp
                    JOIN {' . plan :: TABLE . '} p
                      ON ucp.planid = p.id
                   WHERE p.templateid = :templateid' ; if ( $ proficiency === true ) { $ sql .= ' AND ucp.proficiency = :proficiency' ; $ params [ 'proficiency' ] = true ; } else if ( $ proficiency === false ) { $ sql .= ' AND (ucp.proficiency = :proficiency OR ucp.proficiency IS NULL)' ; $ params [ 'proficiency' ] = false ; } return $ DB -> count_records_sql ( $ sql , $ params ) ; }
docstring: Count the number of records matching a specific template, optionally filtered by proficient values.
  
  @param int $templateid
  @param mixed $proficiency - If true - filter by proficiency, if false filter by not proficient, if null - do not filter.
  @return int
docstring_tokens: Count the number of records matching a specific template optionally filtered by proficient values .