Exemplo n.º 1
0
/**
 @see nextImage
*/
function previousImage($args)
{
    --$_SESSION['imageCount'];
    if (!inRange()) {
        ++$_SESSION['imageCount'];
    }
    return true;
}
Exemplo n.º 2
0
<?php

function inRange($x, $a, $b)
{
    return $x >= $a && $x <= $b ? "YES" : "NO";
}
$file = tempnam(sys_get_temp_dir(), 'touch_date');
// No args
$now = time();
touch($file);
$fileInfo = new SplFileInfo($file);
print inRange($fileInfo->getMTime(), $now, $now + 10) . "\n";
print inRange($fileInfo->getATime(), $now, $now + 10) . "\n";
// Mofification time only
touch($file, strtotime("@100200300"));
$fileInfo = new SplFileInfo($file);
print $fileInfo->getMTime() . "\n";
print $fileInfo->getATime() . "\n";
// Modification and access time
touch($file, strtotime("@100200300"), strtotime("@100400500"));
$fileInfo = new SplFileInfo($file);
print $fileInfo->getMTime() . "\n";
print $fileInfo->getATime() . "\n";
Exemplo n.º 3
0
function expandEvent($event, $recurrenceRule, $start, $end)
{
    $ret = array();
    $rStartDTO = date_create_from_format(DATE_FORMAT, $start);
    $rEndDTO = date_create_from_format(DATE_FORMAT, $end);
    $inRange = 0;
    $count = 0;
    while ($inRange != 1 && $event != null) {
        $eStartDTO = date_create_from_format(DATE_FORMAT, $event['e.start']);
        $eEndDTO = date_create_from_format(DATE_FORMAT, $event['e.end']);
        $inRange = inRange($rStartDTO, $rEndDTO, $eStartDTO, $eEndDTO);
        if ($inRange == 0) {
            array_push($ret, $event);
        }
        $event = incrementEvent($event, $recurrenceRule, $count);
        $count++;
    }
    return $ret;
}
Exemplo n.º 4
0
function normRange($n, $a, $b, $default = NULL)
{
    //Normalizes $n to the range [$a,$b]; if $n is invalid it sets to $default.
    $i = inRange($n, $a, $b);
    if ($i === NULL) {
        return $default;
    }
    if ($i === -1) {
        return $a;
    }
    if ($i === 1) {
        return $b;
    }
    return $n;
}
Exemplo n.º 5
0
function barColor($current_bonus_currency)
{
    $color = '#00c100';
    switch ($current_bonus_currency) {
        case inRange($current_bonus_currency, 0, PHP_INT_MAX):
            $color = '#00c100';
            return $color;
            break;
        case inRange($current_bonus_currency, -301, -1):
            $color = '#ffe400';
            return $color;
            break;
        case inRange($current_bonus_currency, -601, -300):
            $color = '#ff6700';
            return $color;
            break;
        case inRange($current_bonus_currency, -901, -600):
            $color = '#cc0000';
            return $color;
            break;
        case inRange($current_bonus_currency, -PHP_INT_MAX, -900):
            $color = '#464646';
            return $color;
            break;
    }
    return $color;
}
Exemplo n.º 6
0
 public function addRand($QParts, $Subjects, $QTypes, $num)
 {
     //arrays of the numbers to include eg subj [0,1,4] for b,c,e
     global $MARK_AS_BAD_THRESHOLD, $ruleSet, $MAX_NUMQS, $DEFAULT_NUMQS;
     $num = normRange($num, 1, $MAX_NUMQS, $DEFAULT_NUMQS);
     $where = new WhereClause('and');
     $where->add('MarkBad<%i', $MARK_AS_BAD_THRESHOLD);
     $where->add('Deleted=0');
     $db = array("isB", "Subject", "isSA");
     foreach (array("QParts", "Subjects", "QTypes") as $i => $name) {
         if (!val('*i+', $indices = eval('$' . $name . ';'))) {
             continue;
         }
         //Fetches and verifies array of index values that the user may want.
         $indices = array_values(array_unique($indices));
         //Eliminates stupidity
         $sub = $where->addClause('or');
         foreach ($indices as $index) {
             if (inRange($index, 0, count($ruleSet[$name]) - 1)) {
                 //Make sure the index is correct.
                 $sub->add('%b=%i', $db[$i], $index);
             }
         }
         //Inserts the index into the proper DB field
     }
     $qresult = DB::queryRaw("SELECT * FROM questions WHERE %l ORDER BY TimesViewed ASC, " . SQLRAND('QID') . " LIMIT %i", $where, $num);
     //Order by TimesViewed, and then randomize within each TimesViewed value.
     //NOTE: TimesViewed is despite categories, and if you have something like 2 10 10 10, you'll get the 2 at least 8 times in a row.
     //The assumption that there is a large pool for _each_ possible classification (2*5*2=20 of them) eliminates this problem.
     if ($qresult->num_rows != $num) {
         $this->user_err("Not enough such questions exist.");
     }
     $this->addQResult($qresult);
     $this->updateIs(range(count($this->Questions) - $num, count($this->Questions) - 1), "TimesViewed=TimesViewed+1");
     //--todo-- do this in user-specific storage instead.
     return $this;
 }