You are here

function _quiz_is_int in Quiz 8.4

Same name and namespace in other branches
  1. 6.4 quiz.module \_quiz_is_int()
  2. 7.6 quiz.module \_quiz_is_int()
  3. 7 quiz.module \_quiz_is_int()
  4. 7.4 quiz.module \_quiz_is_int()
  5. 7.5 quiz.module \_quiz_is_int()

Helper function used when validating integers.

Parameters

$value: The value to be validated.

$min: The minimum value $value is allowed to be.

$max: The maximum value $value is allowed to be.

Return value

TRUE if integer in the allowed range. FALSE otherwise.

17 calls to _quiz_is_int()
long_answer_report_validate in question_types/long_answer/long_answer.module
Validation function for the report form
long_answer_score_form_validate in question_types/long_answer/long_answer.admin.inc
Validates the long answer score form
matching_config_validate in question_types/matching/matching.module
Validate the matching config form values
MultichoiceQuestion::forgive in question_types/multichoice/lib/Drupal/multichoice/MultichoiceQuestion.php
Forgive some possible logical flaws in the user input.
multichoice_config_validate in question_types/multichoice/multichoice.module
Validate the multichoice config form values

... See full list

File

./quiz.module, line 787
Quiz Module

Code

function _quiz_is_int($value, $min = 1, $max = NULL) {
  $to_return = (string) $value === (string) (int) $value;

  // $value is not an integer.
  if (!$to_return) {
    return FALSE;
  }

  // $value is too small.
  if ($value < $min) {
    return FALSE;
  }

  // $value is too big.
  if (isset($max)) {
    if ($value > $max) {
      return FALSE;
    }
  }

  // $value is an integer in the allowed range.
  return TRUE;
}