Difference between revisions of "MultiSelectWizard"

From Contao Community Documentation

Line 7: Line 7:
 
| Version=2.9.0 - 2.9.3
 
| Version=2.9.0 - 2.9.3
 
| TLVersion=2.7.0 - 2.8.4
 
| TLVersion=2.7.0 - 2.8.4
| ERLink=http://www.contao.org/erweiterungsliste/view/MultiSelectWizard.html
+
| ERLink=http://www.contao.org/extension-list/view/MultiSelectWizard.html
 
| TrackerLink=http://contao-forge.org/projects/multiselectwizard
 
| 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.
 +
[[Datei: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'
 +
)
 +
)
 +
)
 +
);
 +
</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.
 +
 +
==Helper methods==
 +
 +
In der Erweiterung wurden auch Helper-Methoden eingebaut, die man verwenden kann.
 +
 +
===getByKey===
 +
Die einfachere Methode ist mittels '''<code>MultiSelectWizard::getByKey($strSerialized, $strKey)</code>'''. Einfach den serialisierten Wert aus der Datenbank plus den gewünschten Key mitgeben (im obigen Beispiel z.B. "language") und man bekommt ein aggregiertes Array mit allen Werten von dieser Spalte.
 +
<source lang="php">
 +
$arrLanguages = MultiSelectWizard::getByKey($obj->myField, 'language');
 +
</source>
 +
 +
===getFilteredByKey===
 +
Die etwas kompliziertere Methode ist mit '''<code>MultiSelectWizard::getFilteredByKey($strSerialized, $strKey, $arrAnotherKey)</code>'''. Der Anfang ist genau gleich: Man übergibt einen serialisierter Wert und Key. Dann kommt ein Array, mit dessen Hilfe man Return-Werte filtern kann.
 +
Wenn man also alle Sprachen möchte, die in der "secondcolumn" den Wert "option2" haben, nutzt man die Methode wie folgt:
 +
<source lang="php">
 +
$arrLanguagesOption2 = MultiSelectWizard::getFilteredByKey($obj->myField, 'language', array('secondcolumn'=>'option2'));
 +
</source>
 +
 +
Selbstverständlich kann man auch mehrere Filterangaben mitgeben. Einfach immer im Stil von "column_key" => "source_value".

Revision as of 10:30, 25 February 2011


Extension-Overview
Name of the developer Yanick Witschi
Developer Website http://www.certo-net.ch
Version of the extension 1.0.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|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

$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'
							)
						)
					)
);

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.

Helper methods

In der Erweiterung wurden auch Helper-Methoden eingebaut, die man verwenden kann.

getByKey

Die einfachere Methode ist mittels MultiSelectWizard::getByKey($strSerialized, $strKey). Einfach den serialisierten Wert aus der Datenbank plus den gewünschten Key mitgeben (im obigen Beispiel z.B. "language") und man bekommt ein aggregiertes Array mit allen Werten von dieser Spalte.

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

getFilteredByKey

Die etwas kompliziertere Methode ist mit MultiSelectWizard::getFilteredByKey($strSerialized, $strKey, $arrAnotherKey). Der Anfang ist genau gleich: Man übergibt einen serialisierter Wert und Key. Dann kommt ein Array, mit dessen Hilfe man Return-Werte filtern kann. Wenn man also alle Sprachen möchte, die in der "secondcolumn" den Wert "option2" haben, nutzt man die Methode wie folgt:

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

Selbstverständlich kann man auch mehrere Filterangaben mitgeben. Einfach immer im Stil von "column_key" => "source_value".

Views
Personal tools

Contao Community Documentation

In other languages
Navigation
Discover
Understand
Enhance
Miscellaneous
Tools