Passed
Push — master ( 5f63ee...30b096 )
by Jean-Christophe
02:33
created

JsUtils::addViewElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 3
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Ajax\php\ubiquity;
4
5
use Ubiquity\controllers\Startup;
6
use Ubiquity\utils\http\URequest;
7
8
class JsUtils extends \Ajax\JsUtils{
9
10
	public function getUrl($url){
11
		return URequest::getUrl($url);
12
	}
13
14
	public function addViewElement($identifier,$content,&$view){
15
		$controls=$view->getVar("q");
16
		if (isset($controls) === false) {
17
			$controls=array ();
18
		}
19
		$controls[$identifier]=$content;
20
		$view->setVar("q", $controls);
21
	}
22
23
	public function createScriptVariable(&$view,$view_var, $output){
24
		$view->setVar($view_var,$output);
25
	}
26
27
	public function forward($initialController,$controller,$action,$params=array()){
28
		return $initialController->forward($controller,$action,$params,true,true,true);
29
	}
30
31
	public function renderContent($initialControllerInstance,$viewName, $params=NULL) {
32
		return $initialControllerInstance->loadView($viewName,$params,true);
33
	}
34
35
	public function fromDispatcher($dispatcher){
36
		return Startup::$urlParts;
37
	}
38
	
39
	/**
40
	 * Performs jQuery compilation and displays a view
41
	 * @param string $viewName
42
	 * @param mixed $parameters Variable or associative array to pass to the view <br> If a variable is passed, it will have the name <b> $ data </ b> in the view, <br>
43
	 * If an associative array is passed, the view retrieves variables from the table's key names
44
	 * @param boolean $asString If true, the view is not displayed but returned as a string (usable in a variable)
45
	 */
46
	public function renderView($viewName,$parameters=[],$asString=false){
47
		if(isset($this->injected)){
48
			$view=$this->injected->getView();
49
			$this->compile($view);
50
			if (isset($parameters))
51
				$view->setVars($parameters);
52
			return $view->render($viewName, $asString);
53
		}
54
		throw new \Exception(get_class()." instance is not properly instancied : you omitted the second parameter \$controller!");
55
	}
56
}
57