source: trunk/web/addons/job_monarch/lib/extjs-30/examples/writer/remote/lib/session_db.php @ 625

Last change on this file since 625 was 625, checked in by ramonb, 15 years ago

lib/extjs-30:

  • new ExtJS 3.0
File size: 1.5 KB
Line 
1<?php
2 /**
3 * @class SessionDB
4 * Fake Database.  Stores records in $_SESSION
5 */
6class SessionDB {
7    public function __construct() {
8        if (!isset($_SESSION['pk'])) {
9            $_SESSION['pk'] = 10;           // <-- start fake pks at 10
10            $_SESSION['rs'] = getData();    // <-- populate $_SESSION with data.
11        }
12    }
13    // fake a database pk
14    public function pk() {
15        return $_SESSION['pk']++;
16    }
17    // fake a resultset
18    public function rs() {
19        return $_SESSION['rs'];
20    }
21    public function insert($rec) {
22        array_push($_SESSION['rs'], $rec);
23    }
24    public function update($idx, $attributes) {
25        $_SESSION['rs'][$idx] = $attributes;
26    }
27    public function destroy($idx) {
28        return array_shift(array_splice($_SESSION['rs'], $idx, 1));
29    }
30}
31
32// Sample data.
33function getData() {
34    return array(
35        array('id' => 1, 'first' => "Fred", 'last' => 'Flintstone', 'email' => 'fred@flintstone.com'),
36        array('id' => 2, 'first' => "Wilma", 'last' => 'Flintstone', 'email' => 'wilma@flintstone.com'),
37        array('id' => 3, 'first' => "Pebbles", 'last' => 'Flintstone', 'email' => 'pebbles@flintstone.com'),
38        array('id' => 4, 'first' => "Barney", 'last' => 'Rubble', 'email' => 'barney@rubble.com'),
39        array('id' => 5, 'first' => "Betty", 'last' => 'Rubble', 'email' => 'betty@rubble.com'),
40        array('id' => 6, 'first' => "BamBam", 'last' => 'Rubble', 'email' => 'bambam@rubble.com')
41    );
42}
Note: See TracBrowser for help on using the repository browser.