Example #1
0
function generate_vars($section, &$vars)
{
    if (!$vars['is_logged'] || !$vars['is_admin']) {
        return;
    }
    $matches = Match::find_all();
    $vars['matches'] = $matches;
    $vars['arenas'] = Arena::filter('');
    if (isset($_POST['description0'])) {
        for ($i = 0; $i < count($matches); $i++) {
            $match = $matches[$i];
            if (isset($_POST['delete' . $i])) {
                $match->delete();
                continue;
            }
            if ($match->description != $_POST['description' . $i] || $match->date != $_POST['date' . $i] || $match->arena != $_POST['arena' . $i] || $match->prix != $_POST['prix' . $i]) {
                $match->description = $_POST['description' . $i];
                $match->date = $_POST['date' . $i];
                $match->arena = $_POST['arena' . $i];
                $match->prix = $_POST['prix' . $i];
                $match->save();
            }
        }
    }
    if (!empty($_POST['description-nouveau']) && !empty($_POST['date-nouveau']) && !empty($_POST['arena-nouveau']) && !empty($_POST['prix-nouveau'])) {
        $match = new Match();
        $match->description = $_POST['description-nouveau'];
        $match->date = $_POST['date-nouveau'];
        $match->arena = $_POST['arena-nouveau'];
        $match->prix = $_POST['prix-nouveau'];
        $match->save();
    }
    $matches = Match::find_all();
    $vars['matches'] = $matches;
}
Example #2
0
function test_save_delete()
{
    $obj = new Arena();
    $obj->sieges = 5;
    $old_count = count(Arena::filter(""));
    $obj->save();
    assert(isset($obj->id));
    $obj->sieges = 7;
    $obj->save();
    $obj->delete();
    assert($old_count == count(Arena::filter("")));
}