Mokuji /www/app/AdminModule/components/PageControl/Item.php

Language PHP Lines 147
MD5 Hash bdfbb36f4cf9df302de89700c3bd4530
Repository https://github.com/bazo/Mokuji.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php

/**
 * This source file is subject to the "New BSD License".
 *
 * For more information please see http://nettephp.com
 *
 * @author     Jan Kuchař
 * @copyright  Copyright (c) 2009 Jan Kuchař (http://mujserver.net)
 * @license    New BSD License
 * @link       http://nettephp.com/extras/tabcontrol
 */



/**
 * Tab class
 *
  * show off @property, @property-read, @property-write
 * @property mixed $content Content of the tab
 */
class Item extends Control {

	/**************************************************************************/
	/*                               Variables                                */
	/**************************************************************************/

	/**
	 * Tab content factory
	 * @var array
	 */
	public $contentFactory = array();

	/**
	 * Tab content renderer
	 * @var array
	 */
	public $contentRenderer;

	/**
	 * Created component
	 * @var IComponent
	 */
	private $content;

	/**
	 * Has content some snippets?
	 * ! This parameter is very important when you use ajax!
	 * @var bool
	 */
	public $hasSnippets= false;

	function  __construct(Page $parent,$name) {
		parent::__construct($parent, $name);
		$this->contentRenderer = array($this,"renderContent"); // Default renderer
	}



	/**************************************************************************/
	/*                            Main methods                                */
	/**************************************************************************/

	/**
	 * Factory for components
	 * @param string $name
	 */
	function createComponent($name) {
		$this->getContent(); // This will also create content Components
	}

	/**
	 * Default renderer
	 */
	function renderContent() {
		$content = $this->getContent();
		if($content instanceof IComponent or $content instanceof ITemplate) {
			$content->render();
		}
		else
			echo (string)$content;
	}

	/**
	 * Creates (if need) content and returns
	 * @return IComponent
	 */
	function getContent() {
		if($this->content === null) {
			if(is_callable($this->contentFactory, FALSE)) {
				// Callback
				$component = call_user_func_array($this->contentFactory, array($this->name, $this));

				if($component instanceof IComponent) {
					$name = $this->name;
					if($component->name !== null) $name = $component->name;

					if($component->parent === null)
						$this->addComponent($component, $name);
					if($component->parent !== $this)
						throw new InvalidStateException("Component must be registred to \"Item\" control");
				}
				$this->content = $component;
			}
			else
				throw new InvalidStateException("Factory callback is not callable!");
		}
		return $this->content;
	}



	function setContent($content) {
		$this->content = $content;
	}



	/**
	 * Renders component
	 */
	function render() {
		if (SnippetHelper::$outputAllowed OR $this->hasSnippets) {
			if(is_callable($this->contentRenderer, FALSE)) {
				call_user_func_array($this->contentRenderer, array($this));
			}
			else throw new InvalidStateException("Renderer callback is not callable!");
		}
	}

	/**
	 * Generates URL to presenter, action or signal.
	 *
	 * This will try to generate URL on $this component. If fails try to generate url on handlerComponent.
	 * @param  string   destination in format "[[module:]presenter:]action" or "signal!"
	 * @param  array|mixed
	 * @return string
	 * @throws InvalidLinkException
	 */
	public function link($destination, $args = array()) {
		if (!is_array($args)) {
			$args = func_get_args();
			array_shift($args);
		}
		return $this->parent->handlerComponent->link($destination, $args);
	}
}
Back to Top