Exemple #1
0
/**
 * Prepare the user data to go into the database.
 */
function cleanup_session_data($session) {

    // Convert hours (expressed like "1.75" or "2" or "3.5") to minutes
    $session->duration = facetoface_hours_to_minutes($session->duration);

    // Only numbers allowed here
    $session->capacity = preg_replace('/[^\d]/', '', $session->capacity);
    $MAX_CAPACITY = 100000;
    if ($session->capacity < 1) {
        $session->capacity = 1;
    }
    elseif ($session->capacity > $MAX_CAPACITY) {
        $session->capacity = $MAX_CAPACITY;
    }

    return $session;
}
 public function test_facetoface_hours_to_minutes()
 {
     // Should negative values return 0 or a negative value?
     // Test for positive hours value.
     $this->assertEqual(facetoface_hours_to_minutes('10'), '600');
     // Test for positive minutes and hours value.
     $this->assertEqual(facetoface_hours_to_minutes('11:17'), '677');
     // Test for negative hours value.
     $this->assertEqual(facetoface_hours_to_minutes('-3'), '-180');
     // Test for negative hours & minutes value.
     $this->assertEqual(facetoface_hours_to_minutes('-2:1'), '-119');
     // Test for invalid characters value.
     $this->assertEqual(facetoface_hours_to_minutes('invalid_string'), '');
 }
Exemple #3
0
/**
 * Prepare the user data to go into the database.
 */
function cleanup_session_data($session)
{
    // Convert hours (expressed like "1.75" or "2" or "3.5") to minutes.
    $session->duration = facetoface_hours_to_minutes($session->duration);
    // Only numbers allowed here.
    $session->capacity = preg_replace('/[^\\d]/', '', $session->capacity);
    $MAX_CAPACITY = 100000;
    if ($session->capacity < 1) {
        $session->capacity = 1;
    } else {
        if ($session->capacity > $MAX_CAPACITY) {
            $session->capacity = $MAX_CAPACITY;
        }
    }
    // Get the decimal point separator.
    setlocale(LC_MONETARY, get_string('locale', 'langconfig'));
    $localeinfo = localeconv();
    $symbol = $localeinfo['decimal_point'];
    if (empty($symbol)) {
        // Cannot get the locale information, default to en_US.UTF-8.
        $symbol = '.';
    }
    // Only numbers or decimal separators allowed here.
    $session->normalcost = round(preg_replace("/[^\\d{$symbol}]/", '', $session->normalcost));
    $session->discountcost = round(preg_replace("/[^\\d{$symbol}]/", '', $session->discountcost));
    return $session;
}
    function test_facetoface_hours_to_minutes() {
        // Test - for positive hours value.
        $this->assertEquals(facetoface_hours_to_minutes('10'), '600');

        // Test - for positive minutes and hours value.
        $this->assertEquals(facetoface_hours_to_minutes('11:17'), '677');

        // Test - for negative hours value.
        $this->assertEquals(facetoface_hours_to_minutes('-3'), '-180');

        // Test - for negative hours & minutes value.
        $this->assertEquals(facetoface_hours_to_minutes('-2:1'), '-119');

        // Test - for invalid characters value.
        $this->assertEquals(facetoface_hours_to_minutes('invalid_string'), 0.0);

        $this->resetAfterTest(true);
    }