コード例 #1
0
function validate_event_creation($ticker, $code)
{
    validate_ticker_passcode($ticker, $code);
    if (check_ticker_finished($ticker)) {
        throw new Exception();
    }
    if (!check_ticker_running($ticker)) {
        throw new Exception();
    }
}
コード例 #2
0
/**
 * @param int id The liveticker's id.
 * @param string code The passcode for the liveticker.
 * @return bool Whether or not the ticker is running after the toggle, or null if toggling failed.
 */
function toggle_ticker_running($id, $code)
{
    //this is only possible under the following circumstances:
    //
    //1. The current event hasn't started yet. In this case, the first half will be started.
    //
    //2. The current event is in overtime (either first or second half). in this case,
    //	 the event is going to be stopped. If it's in the second half's overtime, the
    //	 event is going to be marked as finished. TODO: if tie, ask for match extension
    //
    //3. the current event is in the half time break. In this case, the second half will be started.
    global $con;
    if (check_ticker_finished($id)) {
        error_log("ticker finished");
        return null;
        //disallow if finished
    }
    $curtime = get_current_time($id);
    if (check_ticker_running($id)) {
        //if ticker is running, it can only be toggled if in overtime
        if ($curtime["overtime"] == 0) {
            error_log("not in overtime");
            return null;
        }
    }
    $running = check_ticker_running($id);
    $new_running = !$running;
    $timestamp = time();
    $sql = "INSERT INTO timer VALUES (?, ?, ?)";
    $stmt = $con->prepare($sql);
    $stmt->bindParam(1, $id);
    $stmt->bindParam(2, $timestamp);
    $stmt->bindParam(3, $new_running);
    $stmt->execute();
    if (sizeof(get_timing_values($id)) >= 4) {
        $sql = "UPDATE tickers SET finished=1 WHERE id=?";
        $stmt = $con->prepare($sql);
        $stmt->bindParam(1, $id);
        $stmt->execute();
    }
    $sql = "UPDATE tickers SET running=? WHERE id=?";
    $stmt = $con->prepare($sql);
    $stmt->bindParam(1, $new_running);
    $stmt->bindParam(2, $id);
    $stmt->execute();
    error_log("ne running " . $new_running);
    return $new_running;
}