PageRenderTime 30ms CodeModel.GetById 24ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/core/db/DbTable.php

http://zoop.googlecode.com/
PHP | 78 lines | 55 code | 12 blank | 11 comment | 1 complexity | a2d2762030504e813631271ffce0ba2a MD5 | raw file
 1<?php
 2class DbTable extends Object implements Iterator
 3{
 4	public $name;
 5	private $fields;
 6	private $conn;
 7	
 8	function __construct($conn, $name)
 9	{
10		// var_dump($conn) . '<br>';
11		$this->conn = $conn;
12		// var_dump($this->conn);
13		$this->name = $name;
14		
15		//	get rid of fields and just use columns
16		$this->addGetter('fields');
17		$this->addGetter('columns');
18	}
19	
20	//	change this to getColumns
21	public function getFields()
22	{
23		if(!$this->fields)
24		{
25			$this->fields = array();
26			foreach($this->conn->getTableFieldInfo($this->name) as $fieldInfo)
27			{
28				$this->fields[] = new DbField($fieldInfo);
29			}
30		}
31		
32		return $this->fields;
33	}
34	
35	//	alias for getColumns (this is the prefered method to use)
36	public function getColumns()
37	{
38		return $this->getFields();
39	}
40	
41	//
42	//	begin iterator functions
43	//
44	
45	public function rewind()
46	{
47		$this->getFields();
48		reset($this->fields);
49	}
50
51	public function current()
52	{
53		$var = current($this->fields);
54		return $var;
55	}
56
57	public function key()
58	{
59		$var = key($this->fields);
60		return $var;
61	}
62
63	public function next()
64	{
65		$var = next($this->fields);
66		return $var;
67	}
68
69	public function valid()
70	{
71		$var = $this->current() !== false;
72		return $var;
73	}
74	
75	//
76	//	end iterator functions
77	//
78}