Create code needed for source selection.
public static source ( array $data ) : string | ||
$data | array | Data items:
'mainlabel' - (string) Main label. 'no_up' - (boolean) [OPTIONAL] Disable movement of selected items up/down. 'selectlabel' - (array) Selected label. 'sourcelabel' - (string) [OPTIONAL] Source selection label. 'sources' - (array) List of sources - keys are source names. Each source is an array with the entries: 'label', 'selected' and 'unselected'. 'unselectlabel' - (array) Unselected label. |
Результат | string | HTML UI code. |
/** */ public function display(Horde_Core_Prefs_Ui $ui) { $sources = array(); foreach (Gollem_Auth::getBackend() as $source => $info) { $selected = $unselected = array(); $selected_list = array_flip(Gollem::getColumns($source)); foreach ($info['attributes'] as $column) { if (isset($selected_list[$column])) { $selected[$column] = $column; } else { $unselected[$column] = $column; } } $sources[$source] = array('label' => $info['name'], 'selected' => $selected, 'unselected' => $unselected); } return Horde_Core_Prefs_Ui_Widgets::source(array('mainlabel' => _("Choose which columns to display, and in what order:"), 'selectlabel' => _("These columns will display in this order:"), 'sourcelabel' => _("Select a backend:"), 'sources' => $sources, 'unselectlabel' => _("Columns that will not be displayed:"))); }
/** * Create code needed for addressbook selection. * * @param array $data Data items: * <pre> * 'fields' - (array) Hash containing addressbook sources as keys and an * array of search fields as values. * 'sources' - (array) List of selected addressbooks. * </pre> * * @return string HTML UI code. */ public static function addressbooks($data) { global $registry; $selected = $unselected = array(); $out = ''; if (!$registry->hasMethod('contacts/sources')) { return; } $t = $GLOBALS['injector']->createInstance('Horde_Template'); $t->setOption('gettext', true); try { $readable = $registry->call('contacts/sources'); } catch (Horde_Exception $e) { $readable = array(); } try { $writeable = $registry->call('contacts/sources', array(true)); } catch (Horde_Exception $e) { $writeable = array(); } if (count($readable) == 1) { // Only one source, no need to display the selection widget $data['sources'] = array_keys($readable); } foreach ($data['sources'] as $source) { if (!empty($readable[$source])) { $selected[$source] = $readable[$source]; } } foreach (array_diff(array_keys($readable), $data['sources']) as $val) { $unselected[$val] = $readable[$val]; } if (!empty($selected) || !empty($unselected)) { $out = Horde_Core_Prefs_Ui_Widgets::source(array('mainlabel' => Horde_Core_Translation::t("Choose the order of address books to search when expanding addresses."), 'selectlabel' => Horde_Core_Translation::t("Selected address books:"), 'sources' => array(array('selected' => $selected, 'unselected' => $unselected)), 'unselectlabel' => Horde_Core_Translation::t("Available address books:"))); $t->set('selected', count($unselected) > 1); $js = array(); foreach (array_keys($readable) as $source) { $tmp = $tmpsel = array(); try { foreach ($registry->call('contacts/fields', array($source)) as $field) { if ($field['search']) { $tmp[] = array('name' => $field['name'], 'label' => $field['label']); if (isset($data['fields'][$source]) && in_array($field['name'], $data['fields'][$source])) { $tmpsel[] = $field['name']; } } } } catch (Horde_Exception $e) { } $js[$source] = array('entries' => $tmp, 'selected' => $tmpsel); } $GLOBALS['injector']->getInstance('Horde_PageOutput')->addInlineJsVars(array('HordeAddressbooksPrefs.fields' => $js, 'HordeAddressbooksPrefs.nonetext' => Horde_Core_Translation::t("No address book selected."))); } return $out . $t->fetch($GLOBALS['registry']->get('templates', 'horde') . '/prefs/addressbooks.html'); }