PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/core/db/DbZone.php

http://zoop.googlecode.com/
PHP | 91 lines | 80 code | 11 blank | 0 comment | 17 complexity | 642b7bc77af88e088e4b81229447844e MD5 | raw file
 1<?php
 2class DbZone extends Object
 3{
 4	private $class;
 5	private $fieldInfo = array();
 6	private $orderby;
 7	private $conditions;
 8	
 9	public function init($params)
10	{
11		$this->getMixinOwner()->setBaseDir('dbzone');
12		$this->class = $params['class'];
13		if(isset($params['orderby']))
14			$this->orderby = $params['orderby'];
15		else
16			$this->orderby = 'id';
17		
18		if(isset($params['conditions']))
19			$this->conditions = $params['conditions'];
20		else
21			$this->conditions = null;
22	}
23	
24	public function setFieldType($field, $type)
25	{
26		$this->fieldInfo[$field]['type'] = $type;
27	}
28	
29	public function pageDefault($p, $z)
30	{
31		$this->redirect('list');
32	}
33	
34	public function pageList($p, $z)
35	{
36		$table = DbObject::_getTableSchema($this->class);
37		$objects = DbObject::_find($this->class, $this->conditions, array('orderby' => $this->orderby . ', id'));
38		$this->assign('table', $table);
39		$this->assign('objects', $objects);
40	}
41	
42	public function postList($p, $z)
43	{
44		$action = $_POST['action'];
45		if($action == 'edit')
46			$this->redirect('edit/' . $_POST['id']);
47		else if($action == 'view')
48			$this->redirect('view/' . $_POST['id']);
49		else if($action == 'add')
50			$this->redirect('edit');
51		else if($action == 'delete')
52		{
53			$object = new $this->class($_POST['id']);
54			$object->destroy();
55			Redirect();
56		}
57	}
58	
59	public function pageEdit($p, $z)
60	{
61		if(isset($p[1]) && $p[1])
62			$object = new $this->class($p[1]);
63		else
64			$object = new $this->class();
65		$object->forceFields();
66		$this->assign('object', $object);
67		$this->assign('fieldInfo', $this->fieldInfo);
68	}
69	
70	public function postEdit($p, $z)
71	{
72		if(isset($p[1]) && $p[1])
73			$object = new $this->class($p[1]);
74		else
75			$object = new $this->class();
76		
77		foreach($_POST['fields'] as $field => $value)
78			$object->$field = $value;
79		$object->save();
80		$this->redirect('list');
81	}
82	
83	public function pageView($p, $z)
84	{
85		$object = new $this->class($p[1]);
86		$object->forceFields();
87		$this->assign('object', $object);
88	}
89}
90
91AddTemplateDir(dirname(__file__) . '/templates');