14 changed files with 558 additions and 534 deletions
			
			
		| @ -0,0 +1,28 @@ | ||||
| { | ||||
| 	"name": "yiisoft/yii2-smarty", | ||||
| 	"description": "The Smarty integration for the Yii framework", | ||||
| 	"keywords": ["yii", "smarty", "renderer"], | ||||
| 	"type": "library", | ||||
| 	"license": "BSD-3-Clause", | ||||
| 	"support": { | ||||
| 		"issues": "https://github.com/yiisoft/yii2/issues?state=open", | ||||
| 		"forum": "http://www.yiiframework.com/forum/", | ||||
| 		"wiki": "http://www.yiiframework.com/wiki/", | ||||
| 		"irc": "irc://irc.freenode.net/yii", | ||||
| 		"source": "https://github.com/yiisoft/yii2" | ||||
| 	}, | ||||
| 	"authors": [ | ||||
| 		{ | ||||
| 			"name": "Alenxader Makarov", | ||||
| 			"email": "sam@rmcreative.ru" | ||||
| 		} | ||||
| 	], | ||||
| 	"minimum-stability": "dev", | ||||
| 	"require": { | ||||
| 		"yiisoft/yii2": "*", | ||||
| 		"smarty/smarty": "v3.1.13" | ||||
| 	}, | ||||
| 	"autoload": { | ||||
| 		"psr-0": { "yii\\smarty": "" } | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,28 @@ | ||||
| { | ||||
| 	"name": "yiisoft/yii2-twig", | ||||
| 	"description": "The Twig integration for the Yii framework", | ||||
| 	"keywords": ["yii", "twig", "renderer"], | ||||
| 	"type": "library", | ||||
| 	"license": "BSD-3-Clause", | ||||
| 	"support": { | ||||
| 		"issues": "https://github.com/yiisoft/yii2/issues?state=open", | ||||
| 		"forum": "http://www.yiiframework.com/forum/", | ||||
| 		"wiki": "http://www.yiiframework.com/wiki/", | ||||
| 		"irc": "irc://irc.freenode.net/yii", | ||||
| 		"source": "https://github.com/yiisoft/yii2" | ||||
| 	}, | ||||
| 	"authors": [ | ||||
| 		{ | ||||
| 			"name": "Alenxader Makarov", | ||||
| 			"email": "sam@rmcreative.ru" | ||||
| 		} | ||||
| 	], | ||||
| 	"minimum-stability": "dev", | ||||
| 	"require": { | ||||
| 		"yiisoft/yii2": "*", | ||||
| 		"twig/twig": "v1.13.0" | ||||
| 	}, | ||||
| 	"autoload": { | ||||
| 		"psr-0": { "yii\\twig": "" } | ||||
| 	} | ||||
| } | ||||
| @ -1,316 +0,0 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\console\controllers; | ||||
| 
 | ||||
| use yii\console\Controller; | ||||
| use yii\base\Exception; | ||||
| 
 | ||||
| /** | ||||
|  * This command creates an Yii Web application at the specified location. | ||||
|  * | ||||
|  * @author Qiang Xue <qiang.xue@gmail.com> | ||||
|  * @author Alexander Makarov <sam@rmcreative.ru> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class AppController extends Controller | ||||
| { | ||||
| 	private $_rootPath; | ||||
| 	private $_config; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @var string custom template path. If specified, templates will be | ||||
| 	 * searched there additionally to `framework/console/webapp`. | ||||
| 	 */ | ||||
| 	public $templatesPath; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @var string application type. If not specified default application | ||||
| 	 * skeleton will be used. | ||||
| 	 */ | ||||
| 	public $type = 'default'; | ||||
| 
 | ||||
| 	public function init() | ||||
| 	{ | ||||
| 		parent::init(); | ||||
| 
 | ||||
| 		if ($this->templatesPath && !is_dir($this->templatesPath)) { | ||||
| 			throw new Exception('--templatesPath "'.$this->templatesPath.'" does not exist or can not be read.'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	public function globalOptions() | ||||
| 	{ | ||||
| 		return array('templatesPath', 'type'); | ||||
| 	} | ||||
| 
 | ||||
| 	public function actionIndex() | ||||
| 	{ | ||||
| 		$this->forward('help/index', array('-args' => array('app/create'))); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Generates Yii application at the path specified via appPath parameter. | ||||
| 	 * | ||||
| 	 * @param string $path the directory where the new application will be created. | ||||
| 	 * If the directory does not exist, it will be created. After the application | ||||
| 	 * is created, please make sure the directory has enough permissions. | ||||
| 	 * | ||||
| 	 * @throws \yii\base\Exception if path specified is not valid | ||||
| 	 * @return integer the exit status | ||||
| 	 */ | ||||
| 	public function actionCreate($path) | ||||
| 	{ | ||||
| 		$path = strtr($path, '/\\', DIRECTORY_SEPARATOR); | ||||
| 		if (strpos($path, DIRECTORY_SEPARATOR) === false) { | ||||
| 			$path = '.'.DIRECTORY_SEPARATOR.$path; | ||||
| 		} | ||||
| 		$dir = rtrim(realpath(dirname($path)), '\\/'); | ||||
| 		if ($dir === false || !is_dir($dir)) { | ||||
| 			throw new Exception("The directory '$path' is not valid. Please make sure the parent directory exists."); | ||||
| 		} | ||||
| 
 | ||||
| 		if (basename($path) === '.') { | ||||
| 			$this->_rootPath = $path = $dir; | ||||
| 		} else { | ||||
| 			$this->_rootPath = $path = $dir.DIRECTORY_SEPARATOR.basename($path); | ||||
| 		} | ||||
| 
 | ||||
| 		if ($this->confirm("Create \"$this->type\" application under '$path'?")) { | ||||
| 			$sourceDir = $this->getSourceDir(); | ||||
| 			$config = $this->getConfig(); | ||||
| 
 | ||||
| 			$list = $this->buildFileList($sourceDir, $path); | ||||
| 
 | ||||
| 			if (is_array($config)) { | ||||
| 				foreach ($config as $file => $settings) { | ||||
| 					if (isset($settings['handler'])) { | ||||
| 						$list[$file]['callback'] = $settings['handler']; | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			$this->copyFiles($list); | ||||
| 
 | ||||
| 			if (is_array($config)) { | ||||
| 				foreach ($config as $file => $settings) { | ||||
| 					if (isset($settings['permissions'])) { | ||||
| 						@chmod($path.'/'.$file, $settings['permissions']); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			echo "\nYour application has been created successfully under {$path}.\n"; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @throws \yii\base\Exception if source directory wasn't located | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	protected function getSourceDir() | ||||
| 	{ | ||||
| 		$customSource = realpath($this->templatesPath.'/'.$this->type); | ||||
| 		$defaultSource = realpath($this->getDefaultTemplatesPath().'/'.$this->type); | ||||
| 
 | ||||
| 		if ($customSource) { | ||||
| 			return $customSource; | ||||
| 		} elseif ($defaultSource) { | ||||
| 			return $defaultSource; | ||||
| 		} else { | ||||
| 			throw new Exception('Unable to locate the source directory for "'.$this->type.'".'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @return string default templates path | ||||
| 	 */ | ||||
| 	protected function getDefaultTemplatesPath() | ||||
| 	{ | ||||
| 		return realpath(__DIR__.'/../webapp'); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @return array|null template configuration | ||||
| 	 */ | ||||
| 	protected function getConfig() | ||||
| 	{ | ||||
| 		if ($this->_config === null) { | ||||
| 			$this->_config = require $this->getDefaultTemplatesPath() . '/config.php'; | ||||
| 			if ($this->templatesPath && file_exists($this->templatesPath)) { | ||||
| 				$this->_config = array_merge($this->_config, require $this->templatesPath . '/config.php'); | ||||
| 			} | ||||
| 		} | ||||
| 		if (isset($this->_config[$this->type])) { | ||||
| 			return $this->_config[$this->type]; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param string $source path to source file | ||||
| 	 * @param string $pathTo path to file we want to get relative path for | ||||
| 	 * @param string $varName variable name w/o $ to replace value with relative path for | ||||
| 	 * | ||||
| 	 * @return string target file contents | ||||
| 	 */ | ||||
| 	public function replaceRelativePath($source, $pathTo, $varName) | ||||
| 	{ | ||||
| 		$content = file_get_contents($source); | ||||
| 		$relativeFile = str_replace($this->getSourceDir(), '', $source); | ||||
| 
 | ||||
| 		$relativePath = $this->getRelativePath($pathTo, $this->_rootPath.$relativeFile); | ||||
| 		$relativePath = str_replace('\\', '\\\\', $relativePath); | ||||
| 
 | ||||
| 		return preg_replace('/\$'.$varName.'\s*=(.*?);/', "\$".$varName."=$relativePath;", $content); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param string $path1 absolute path | ||||
| 	 * @param string $path2 absolute path | ||||
| 	 * | ||||
| 	 * @return string relative path | ||||
| 	 */ | ||||
| 	protected function getRelativePath($path1, $path2) | ||||
| 	{ | ||||
| 		$segs1 = explode(DIRECTORY_SEPARATOR, $path1); | ||||
| 		$segs2 = explode(DIRECTORY_SEPARATOR, $path2); | ||||
| 		$n1 = count($segs1); | ||||
| 		$n2 = count($segs2); | ||||
| 
 | ||||
| 		for ($i = 0; $i < $n1 && $i < $n2; ++$i) { | ||||
| 			if ($segs1[$i] !== $segs2[$i]) { | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		if ($i === 0) { | ||||
| 			return "'" . $path1 . "'"; | ||||
| 		} | ||||
| 		$up = ''; | ||||
| 		for ($j = $i; $j < $n2 - 1; ++$j) { | ||||
| 			$up .= '/..'; | ||||
| 		} | ||||
| 		for(; $i < $n1 - 1; ++$i) { | ||||
| 			$up .= '/' . $segs1[$i]; | ||||
| 		} | ||||
| 
 | ||||
| 		return '__DIR__.\'' . $up . '/' . basename($path1) . '\''; | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Copies a list of files from one place to another. | ||||
| 	 * @param array $fileList the list of files to be copied (name => spec). | ||||
| 	 * The array keys are names displayed during the copy process, and array values are specifications | ||||
| 	 * for files to be copied. Each array value must be an array of the following structure: | ||||
| 	 * <ul> | ||||
| 	 * <li>source: required, the full path of the file/directory to be copied from</li> | ||||
| 	 * <li>target: required, the full path of the file/directory to be copied to</li> | ||||
| 	 * <li>callback: optional, the callback to be invoked when copying a file. The callback function | ||||
| 	 *   should be declared as follows: | ||||
| 	 *   <pre> | ||||
| 	 *   function foo($source, $params) | ||||
| 	 *   </pre> | ||||
| 	 *   where $source parameter is the source file path, and the content returned | ||||
| 	 *   by the function will be saved into the target file.</li> | ||||
| 	 * <li>params: optional, the parameters to be passed to the callback</li> | ||||
| 	 * </ul> | ||||
| 	 * @see buildFileList | ||||
| 	 */ | ||||
| 	protected function copyFiles($fileList) | ||||
| 	{ | ||||
| 		$overwriteAll = false; | ||||
| 		foreach ($fileList as $name => $file) { | ||||
| 			$source = strtr($file['source'], '/\\', DIRECTORY_SEPARATOR); | ||||
| 			$target = strtr($file['target'], '/\\', DIRECTORY_SEPARATOR); | ||||
| 			$callback = isset($file['callback']) ? $file['callback'] : null; | ||||
| 			$params = isset($file['params']) ? $file['params'] : null; | ||||
| 
 | ||||
| 			if (is_dir($source)) { | ||||
| 				if (!is_dir($target)) { | ||||
| 					mkdir($target, 0777, true); | ||||
| 				} | ||||
| 				continue; | ||||
| 			} | ||||
| 
 | ||||
| 			if ($callback !== null) { | ||||
| 				$content = call_user_func($callback, $source, $params); | ||||
| 			} else { | ||||
| 				$content = file_get_contents($source); | ||||
| 			} | ||||
| 			if (is_file($target)) { | ||||
| 				if ($content === file_get_contents($target)) { | ||||
| 					echo "  unchanged $name\n"; | ||||
| 					continue; | ||||
| 				} | ||||
| 				if ($overwriteAll) { | ||||
| 					echo "  overwrite $name\n"; | ||||
| 				} | ||||
| 				else { | ||||
| 					echo "      exist $name\n"; | ||||
| 					echo "            ...overwrite? [Yes|No|All|Quit] "; | ||||
| 					$answer = trim(fgets(STDIN)); | ||||
| 					if (!strncasecmp($answer, 'q', 1)) { | ||||
| 						return; | ||||
| 					} elseif (!strncasecmp($answer, 'y', 1)) { | ||||
| 						echo "  overwrite $name\n"; | ||||
| 					} elseif (!strncasecmp($answer, 'a', 1)) { | ||||
| 						echo "  overwrite $name\n"; | ||||
| 						$overwriteAll = true; | ||||
| 					} else { | ||||
| 						echo "       skip $name\n"; | ||||
| 						continue; | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 			else { | ||||
| 				if (!is_dir(dirname($target))) { | ||||
| 					mkdir(dirname($target), 0777, true); | ||||
| 				} | ||||
| 				echo "   generate $name\n"; | ||||
| 			} | ||||
| 			file_put_contents($target, $content); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Builds the file list of a directory. | ||||
| 	 * This method traverses through the specified directory and builds | ||||
| 	 * a list of files and subdirectories that the directory contains. | ||||
| 	 * The result of this function can be passed to {@link copyFiles}. | ||||
| 	 * @param string $sourceDir the source directory | ||||
| 	 * @param string $targetDir the target directory | ||||
| 	 * @param string $baseDir base directory | ||||
| 	 * @param array $ignoreFiles list of the names of files that should | ||||
| 	 * be ignored in list building process. | ||||
| 	 * @param array $renameMap hash array of file names that should be | ||||
| 	 * renamed. Example value: array('1.old.txt' => '2.new.txt'). | ||||
| 	 * @return array the file list (see {@link copyFiles}) | ||||
| 	 */ | ||||
| 	protected function buildFileList($sourceDir, $targetDir, $baseDir='', $ignoreFiles=array(), $renameMap=array()) | ||||
| 	{ | ||||
| 		$list = array(); | ||||
| 		$handle = opendir($sourceDir); | ||||
| 		while (($file = readdir($handle)) !== false) { | ||||
| 			if (in_array($file, array('.', '..', '.svn', '.gitignore', '.hgignore')) || in_array($file, $ignoreFiles)) { | ||||
| 				continue; | ||||
| 			} | ||||
| 			$sourcePath = $sourceDir.DIRECTORY_SEPARATOR.$file; | ||||
| 			$targetPath = $targetDir.DIRECTORY_SEPARATOR.strtr($file, $renameMap); | ||||
| 			$name = $baseDir === '' ? $file : $baseDir.'/'.$file; | ||||
| 			$list[$name] = array( | ||||
| 				'source' => $sourcePath, | ||||
| 				'target' => $targetPath, | ||||
| 			); | ||||
| 			if (is_dir($sourcePath)) { | ||||
| 				$list = array_merge($list, self::buildFileList($sourcePath, $targetPath, $name, $ignoreFiles, $renameMap)); | ||||
| 			} | ||||
| 		} | ||||
| 		closedir($handle); | ||||
| 		return $list; | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,53 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\jui; | ||||
| 
 | ||||
| use yii\helpers\base\ArrayHelper; | ||||
| use yii\helpers\Html; | ||||
| 
 | ||||
| /** | ||||
|  * Dialog renders an dialog jQuery UI widget. | ||||
|  * | ||||
|  * For example: | ||||
|  * | ||||
|  * ```php | ||||
|  * Dialog::begin(array( | ||||
|  *     'clientOptions' => array( | ||||
|  *         'modal' => true, | ||||
|  *     ), | ||||
|  * )); | ||||
|  * | ||||
|  * echo 'Dialog contents here...'; | ||||
|  * | ||||
|  * Dialog::end(); | ||||
|  * ``` | ||||
|  * | ||||
|  * @see http://api.jqueryui.com/dialog/ | ||||
|  * @author Alexander Kochetov <creocoder@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class Dialog extends Widget | ||||
| { | ||||
| 	/** | ||||
| 	 * Initializes the widget. | ||||
| 	 */ | ||||
| 	public function init() | ||||
| 	{ | ||||
| 		parent::init(); | ||||
| 		echo Html::beginTag('div', $this->options) . "\n"; | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders the widget. | ||||
| 	 */ | ||||
| 	public function run() | ||||
| 	{ | ||||
| 		echo Html::endTag('div') . "\n"; | ||||
| 		$this->registerWidget('dialog'); | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,86 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\jui; | ||||
| 
 | ||||
| use Yii; | ||||
| use yii\base\View; | ||||
| use yii\helpers\Json; | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Menu renders a menu jQuery UI widget. | ||||
|  * | ||||
|  * @see http://api.jqueryui.com/menu/ | ||||
|  * @author Alexander Kochetov <creocoder@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class Menu extends \yii\widgets\Menu | ||||
| { | ||||
| 	/** | ||||
| 	 * @var array the options for the underlying jQuery UI widget. | ||||
| 	 * Please refer to the corresponding jQuery UI widget Web page for possible options. | ||||
| 	 * For example, [this page](http://api.jqueryui.com/accordion/) shows | ||||
| 	 * how to use the "Accordion" widget and the supported options (e.g. "header"). | ||||
| 	 */ | ||||
| 	public $clientOptions = array(); | ||||
| 	/** | ||||
| 	 * @var array the event handlers for the underlying jQuery UI widget. | ||||
| 	 * Please refer to the corresponding jQuery UI widget Web page for possible events. | ||||
| 	 * For example, [this page](http://api.jqueryui.com/accordion/) shows | ||||
| 	 * how to use the "Accordion" widget and the supported events (e.g. "create"). | ||||
| 	 */ | ||||
| 	public $clientEvents = array(); | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Initializes the widget. | ||||
| 	 * If you override this method, make sure you call the parent implementation first. | ||||
| 	 */ | ||||
| 	public function init() | ||||
| 	{ | ||||
| 		parent::init(); | ||||
| 		if (!isset($this->options['id'])) { | ||||
| 			$this->options['id'] = $this->getId(); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders the widget. | ||||
| 	 */ | ||||
| 	public function run() | ||||
| 	{ | ||||
| 		parent::run(); | ||||
| 		$this->registerWidget('menu'); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Registers a specific jQuery UI widget and the related events | ||||
| 	 * @param string $name the name of the jQuery UI widget | ||||
| 	 */ | ||||
| 	protected function registerWidget($name) | ||||
| 	{ | ||||
| 		$id = $this->options['id']; | ||||
| 		$view = $this->getView(); | ||||
| 		$view->registerAssetBundle("yii/jui/$name"); | ||||
| 		$view->registerAssetBundle(Widget::$theme . "/$name"); | ||||
| 
 | ||||
| 		if ($this->clientOptions !== false) { | ||||
| 			$options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions); | ||||
| 			$js = "jQuery('#$id').$name($options);"; | ||||
| 			$view->registerJs($js); | ||||
| 		} | ||||
| 
 | ||||
| 		if (!empty($this->clientEvents)) { | ||||
| 			$js = array(); | ||||
| 			foreach ($this->clientEvents as $event => $handler) { | ||||
| 				$js[] = "jQuery('#$id').on('$name$event', $handler);"; | ||||
| 			} | ||||
| 			$view->registerJs(implode("\n", $js)); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,116 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @link http://www.yiiframework.com/ | ||||
|  * @copyright Copyright (c) 2008 Yii Software LLC | ||||
|  * @license http://www.yiiframework.com/license/ | ||||
|  */ | ||||
| 
 | ||||
| namespace yii\jui; | ||||
| 
 | ||||
| use yii\base\InvalidConfigException; | ||||
| use yii\helpers\base\ArrayHelper; | ||||
| use yii\helpers\Html; | ||||
| 
 | ||||
| /** | ||||
|  * Tabs renders a tabs jQuery UI widget. | ||||
|  * | ||||
|  * For example: | ||||
|  * | ||||
|  * ```php | ||||
|  * echo Tabs::widget(array( | ||||
|  *     'items' => array( | ||||
|  *         array( | ||||
|  *             'header' => 'One', | ||||
|  *             'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', | ||||
|  *         ), | ||||
|  *         array( | ||||
|  *             'header' => 'Two', | ||||
|  *             'headerOptions' => array(...), | ||||
|  *             'content' => 'Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus...', | ||||
|  *             'options' => array(...), | ||||
|  *         ), | ||||
|  *     ), | ||||
|  * )); | ||||
|  * ``` | ||||
|  * | ||||
|  * @see http://api.jqueryui.com/tabs/ | ||||
|  * @author Alexander Kochetov <creocoder@gmail.com> | ||||
|  * @since 2.0 | ||||
|  */ | ||||
| class Tabs extends Widget | ||||
| { | ||||
| 	/** | ||||
| 	 * @var array list of tabs in the tabs widget. Each array element represents a single | ||||
| 	 * tab with the following structure: | ||||
| 	 * | ||||
| 	 * ```php | ||||
| 	 * array( | ||||
| 	 *     // required, the header (HTML) of the tab | ||||
| 	 *     'header' => 'Tab label', | ||||
| 	 *     // required, the content (HTML) of the tab | ||||
| 	 *     'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', | ||||
| 	 *     // optional the HTML attributes of the tab content container | ||||
| 	 *     'options'=> array(...), | ||||
| 	 *     // optional the HTML attributes of the tab header container | ||||
| 	 *     'headerOptions'=> array(...), | ||||
| 	 * ) | ||||
| 	 * ``` | ||||
| 	 */ | ||||
| 	public $items = array(); | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders the widget. | ||||
| 	 */ | ||||
| 	public function run() | ||||
| 	{ | ||||
| 		echo Html::beginTag('div', $this->options) . "\n"; | ||||
| 		echo $this->renderHeaders() . "\n"; | ||||
| 		echo $this->renderContents() . "\n"; | ||||
| 		echo Html::endTag('div') . "\n"; | ||||
| 		$this->registerWidget('tabs'); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders tabs headers as specified on [[items]]. | ||||
| 	 * @return string the rendering result. | ||||
| 	 * @throws InvalidConfigException. | ||||
| 	 */ | ||||
| 	protected function renderHeaders() | ||||
| 	{ | ||||
| 		$headers = array(); | ||||
| 		foreach ($this->items as $n => $item) { | ||||
| 			if (!isset($item['header'])) { | ||||
| 				throw new InvalidConfigException("The 'header' option is required."); | ||||
| 			} | ||||
| 			$options = ArrayHelper::getValue($item, 'options', array()); | ||||
| 			$id = isset($options['id']) ? $options['id'] : $this->options['id'] . '-tab' . $n; | ||||
| 			$headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); | ||||
| 			$headers[] = Html::tag('li', Html::a($item['header'], "#$id"), $headerOptions); | ||||
| 		} | ||||
| 
 | ||||
| 		return Html::tag('ul', implode("\n", $headers)); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Renders tabs contents as specified on [[items]]. | ||||
| 	 * @return string the rendering result. | ||||
| 	 * @throws InvalidConfigException. | ||||
| 	 */ | ||||
| 	protected function renderContents() | ||||
| 	{ | ||||
| 		$contents = array(); | ||||
| 		foreach ($this->items as $n => $item) { | ||||
| 			if (!isset($item['content'])) { | ||||
| 				throw new InvalidConfigException("The 'content' option is required."); | ||||
| 			} | ||||
| 			$options = ArrayHelper::getValue($item, 'options', array()); | ||||
| 			if (!isset($options['id'])) { | ||||
| 				$options['id'] = $this->options['id'] . '-tab' . $n; | ||||
| 			} | ||||
| 			$contents[] = Html::tag('div', $item['content'], $options); | ||||
| 		} | ||||
| 
 | ||||
| 		return implode("\n", $contents); | ||||
| 	} | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue