PageRenderTime 15ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/core/zone/GuiZone.php

http://zoop.googlecode.com/
PHP | 85 lines | 71 code | 13 blank | 1 comment | 11 complexity | c8d98a637b5bc53c84c83a4a13682065 MD5 | raw file
 1<?php
 2class GuiZone extends Zone
 3{
 4	protected $displayed = false;
 5	protected $baseDir = NULL;
 6	protected $guiClass, $guiDriver, $layout;
 7	private $assigns = array();
 8	
 9	public function init($requestInfo = NULL, $params = array())
10	{
11		parent::init($requestInfo, $params);
12	}
13	
14	public function setBaseDir($dir)
15	{
16		$this->baseDir = $dir;
17	}
18	
19	public function getBaseDir()
20	{
21		return $this->baseDir;
22	}
23	
24	protected function chooseGui($type)
25	{
26		//	if they want something different they need to extend this class
27		assert($type === NULL);
28		
29		if($this->guiClass)
30			$className = $this->guiClass;
31		else if(Config::get('zoop.gui.class'))
32			$className = Config::get('zoop.gui.class');
33		else if(class_exists('AppGui'))
34			$className = 'AppGui';
35		else
36			$className = 'Gui';
37		
38		return new $className($this->guiDriver);
39	}
40	
41	protected function getTemplateDir()
42	{
43		$className = get_class($this);
44		$zoneName = strtolower(substr($className, 4));
45		return $zoneName;
46	}
47	
48	function assign($name, $value)
49	{
50		$this->assigns[$name] = $value;
51	}
52	
53	function displayed()
54	{
55		return $this->displayed;
56	}
57	
58	function display($templateName, $guiType = NULL)
59	{
60		$gui = $this->chooseGui($guiType);
61		$gui->setLayout($this->layout);
62		
63		foreach($this->assigns as $name => $value)
64			$gui->assign($name, $value);
65		
66		if(defined('script_url'))
67			$gui->assign('scriptUrl', script_url);
68		if(defined('ssl_script_url'))
69			$gui->assign('sslScriptUrl', ssl_script_url);
70		if(defined('base_url'))
71			$gui->assign('baseUrl', base_url);
72		if(defined('virtual_url'))
73			$gui->assign('virtualUrl', virtual_url);
74		if(defined('ssl_virtual_url'))
75			$gui->assign('sslVirtualUrl', ssl_virtual_url);
76		$gui->assign('zoneUrl', $this->getUrl());
77 		
78		if(!$this->baseDir)
79			$dirName = $this->getTemplateDir();
80		else
81			$dirName = $this->baseDir;
82		$gui->display($dirName . '/'. $templateName . '.tpl');
83		$this->displayed = true;
84	}
85}