Difference between revisions of "MultiSelectWizard"

From Contao Community Documentation

(Created page with 'de:MultiSelectWizard')
 
 
(4 intermediate revisions by one user not shown)
Line 1: Line 1:
 
[[de:MultiSelectWizard]]
 
[[de:MultiSelectWizard]]
 +
[[Category:Extensions]]
 +
{{ExtInfo
 +
| Dev=Yanick Witschi
 +
| DevSite=http://www.certo-net.ch
 +
| ExtVersion=1.1.0
 +
| Version=2.9.0 - 2.9.3
 +
| TLVersion=2.7.0 - 2.8.4
 +
| ERLink=http://www.contao.org/extension-list/view/MultiSelectWizard.html
 +
| TrackerLink=http://contao-forge.org/projects/multiselectwizard
 +
}}
 +
 +
This widget is meant to define one or more select input fields side by side and as many rows as you want.
 +
 +
=Look=
 +
The widget looks exactly the same like the ModuleWizard of the Contao core. The problem with this wizard is that the sources (SELECT * FROM tl_module etc.) are all hardcoded and it's therefore useless for third party developers.
 +
[[File:MultiSelectWizard.png|MultiSelectWizard|frame|center]]
 +
 +
=Usage=
 +
There are two different ways of using the widget. Either by providing the data directly using "columnsData" in the "eval" array or with a callback.
 +
 +
==Providing columnsData==
 +
 +
<source lang="php">
 +
$GLOBALS['TL_DCA']['tl_table']['fields']['anything'] = array
 +
(
 +
'label'          => &$GLOBALS['TL_LANG']['tl_table']['anything'],
 +
'exclude' => true,
 +
'inputType' => 'multiSelectWizard',
 +
'eval' => array
 +
  (
 +
  'mandatory'=>true,
 +
  'columnsData'=> array
 +
(
 +
'columns' => array
 +
(
 +
'key' => 'language',
 +
'label' => $GLOBALS['TL_LANG']['MSC']['mylanguagelabel'],
 +
'source' => $this->getLanguages(),
 +
'style' => 'width:200px'
 +
),
 +
array
 +
(
 +
'key' => 'secondcolumn',
 +
'label' => $GLOBALS['TL_LANG']['MSC']['secondcolumn'],
 +
'source' => array
 +
(
 +
'option1' => $GLOBALS['TL_LANG']['MSC']['option1'],
 +
'option2' => $GLOBALS['TL_LANG']['MSC']['option2'],
 +
'option3' => $GLOBALS['TL_LANG']['MSC']['option3']
 +
),
 +
'style' => 'width:100px'
 +
),
 +
array
 +
(
 +
'key' => 'columnwithforeignkey',
 +
'label' => $GLOBALS['TL_LANG']['MSC']['columnwithforeignkey'],
 +
'source' => 'tl_table.column'
 +
)
 +
)
 +
)
 +
);
 +
</source>
 +
 +
==Providing data using the callback==
 +
<source lang="php">
 +
$GLOBALS['TL_DCA']['tl_table']['fields']['anything'] = array
 +
(
 +
'label'                => &$GLOBALS['TL_LANG']['tl_table']['anything'],
 +
'exclude' => true,
 +
'inputType' => 'multiSelectWizard',
 +
'eval' => array('mandatory'=>true,'columnsCallback'=>array('Class', 'Method'))
 +
 +
);
 +
</source>
 +
 +
Where obviously the return value of your method should be the same array as with the "columnsData" variant.
 +
 +
==Javascript-Fallback==
 +
In case there is no Javascript, the modifications (add, delete etc.) will be executed manually. A lot of widgets execute database operations which is in 99.9% of all cases correct although there are exceptions such as the storage in the localconfig.php.
 +
The MultiSelectWizard supports both, storage in the localconfig.php and any routine that can be defined using a callback.
 +
 +
===localconfig.php===
 +
<source lang="php">
 +
'eval' => array('storeInLocalConfig'=>true)
 +
</source>
 +
 +
===Any routine===
 +
<source lang="php">
 +
'eval' => array('storeCallback'=>array('MyClass','MyMethod'))
 +
</source>
 +
<source lang="php">
 +
class MyClass extends Backend
 +
{
 +
  public function MyMethod($objWidget)
 +
  {
 +
  }
 +
}
 +
</source>
 +
 +
==Helper methods==
 +
 +
The extension also provides helper methods every developer can make use of.
 +
 +
===getByKey===
 +
The easier method is using '''<code>MultiSelectWizard::getByKey($strSerialized, $strKey)</code>'''. Just provide the serialized value from the database and the desired key of the column (in the example above e.g. "language") and you get an array of all values of this column.
 +
<source lang="php">
 +
$arrLanguages = MultiSelectWizard::getByKey($obj->myField, 'language');
 +
</source>
 +
 +
===getFilteredByKey (AND condition)===
 +
The rather more sophisticated method is '''<code>MultiSelectWizard::getFilteredByKey($strSerialized, $strKey, $arrAnotherKey)</code>'''. The two first parameters are the same. You provide the serialized value and the key of the column you want the values of. Then there's a third parameter where you can filter your return values.
 +
Assuming you want to have all languages that use have the value "option2" in the column "secondcolumn" you can use this method as follows:
 +
<source lang="php">
 +
$arrLanguagesOption2 = MultiSelectWizard::getFilteredByKey($obj->myField, 'language', array('secondcolumn'=>'option2'));
 +
</source>
 +
 +
You can use multiple filter conditions. Just extend the $arrAnotherkey accordingly. You will get only the data that matches '''all''' of the provided filter conditions!

Latest revision as of 14:56, 21 March 2011


Extension-Overview
Name of the developer Yanick Witschi
Developer Website http://www.certo-net.ch
Version of the extension 1.1.0
Compatibility with Contao Version 2.9.0 - 2.9.3
Compatibility with TYPOlight Version 2.7.0 - 2.8.4
Link to Extension Repository http://www.contao.org/extension-list/view/MultiSelectWizard.html
Link to Tracker http://contao-forge.org/projects/multiselectwizard


This widget is meant to define one or more select input fields side by side and as many rows as you want.

Look

The widget looks exactly the same like the ModuleWizard of the Contao core. The problem with this wizard is that the sources (SELECT * FROM tl_module etc.) are all hardcoded and it's therefore useless for third party developers.

MultiSelectWizard

Usage

There are two different ways of using the widget. Either by providing the data directly using "columnsData" in the "eval" array or with a callback.

Providing columnsData

$GLOBALS['TL_DCA']['tl_table']['fields']['anything'] = array
(
	'label'          => &$GLOBALS['TL_LANG']['tl_table']['anything'],
	'exclude'	 => true,
	'inputType'	 => 'multiSelectWizard',
	'eval'		 => array
				   (
				   		'mandatory'=>true,
				   		'columnsData'=> array
						(
							'columns' => array
							(
								'key'	=> 'language',
								'label' => $GLOBALS['TL_LANG']['MSC']['mylanguagelabel'],
								'source' => $this->getLanguages(),
								'style' => 'width:200px'
							),
							array
							(
								'key'	=> 'secondcolumn',
								'label' => $GLOBALS['TL_LANG']['MSC']['secondcolumn'],
								'source' => array
								(
									'option1'	=> $GLOBALS['TL_LANG']['MSC']['option1'],
									'option2'	=> $GLOBALS['TL_LANG']['MSC']['option2'],
									'option3'	=> $GLOBALS['TL_LANG']['MSC']['option3']
								),
								'style' => 'width:100px'
							),
							array
							(
								'key'	=> 'columnwithforeignkey',
								'label' => $GLOBALS['TL_LANG']['MSC']['columnwithforeignkey'],
								'source' => 'tl_table.column'
							)
						)
					)
);

Providing data using the callback

$GLOBALS['TL_DCA']['tl_table']['fields']['anything'] = array
(
		'label'                 => &$GLOBALS['TL_LANG']['tl_table']['anything'],
		'exclude'		=> true,
		'inputType'		=> 'multiSelectWizard',
		'eval'			=> array('mandatory'=>true,'columnsCallback'=>array('Class', 'Method'))
 
);

Where obviously the return value of your method should be the same array as with the "columnsData" variant.

Javascript-Fallback

In case there is no Javascript, the modifications (add, delete etc.) will be executed manually. A lot of widgets execute database operations which is in 99.9% of all cases correct although there are exceptions such as the storage in the localconfig.php. The MultiSelectWizard supports both, storage in the localconfig.php and any routine that can be defined using a callback.

localconfig.php

'eval'	=> array('storeInLocalConfig'=>true)

Any routine

'eval'	=> array('storeCallback'=>array('MyClass','MyMethod'))
class MyClass extends Backend
{
   public function MyMethod($objWidget)
   {
   }
}

Helper methods

The extension also provides helper methods every developer can make use of.

getByKey

The easier method is using MultiSelectWizard::getByKey($strSerialized, $strKey). Just provide the serialized value from the database and the desired key of the column (in the example above e.g. "language") and you get an array of all values of this column.

$arrLanguages = MultiSelectWizard::getByKey($obj->myField, 'language');

getFilteredByKey (AND condition)

The rather more sophisticated method is MultiSelectWizard::getFilteredByKey($strSerialized, $strKey, $arrAnotherKey). The two first parameters are the same. You provide the serialized value and the key of the column you want the values of. Then there's a third parameter where you can filter your return values. Assuming you want to have all languages that use have the value "option2" in the column "secondcolumn" you can use this method as follows:

$arrLanguagesOption2 = MultiSelectWizard::getFilteredByKey($obj->myField, 'language', array('secondcolumn'=>'option2'));

You can use multiple filter conditions. Just extend the $arrAnotherkey accordingly. You will get only the data that matches all of the provided filter conditions!

Views
Personal tools

Contao Community Documentation

In other languages
Navigation
Discover
Understand
Enhance
Miscellaneous
Tools