/** * vkgroups * * @param string $selected The key that is selected * @param string $name The name for the field * @param array $attribs Additional HTML attributes for the <select> tag* * @param string $access_token Params * @param int $channel_id Params * * @return string HTML */ public static function vkgroups($selected = null, $name = 'xtform[vkgroup_id]', $attribs = array(), $access_token = null, $channel_id = null) { $options = array(); $attribs = array(); if (!empty($access_token) && !empty($channel_id)) { $options[] = JHTML::_('select.option', null, '-' . JText::_('JSELECT') . '-'); try { $ch = F0FTable::getAnInstance('Channel', 'AutoTweetTable'); $result = $ch->load($channel_id); if (!$result) { break; } $params = $ch->params; $registry = new JRegistry(); $registry->loadString($params); $registry->set('access_token', $access_token); $ch->bind(array('params' => (string) $registry)); $vkChannelHelper = new VkChannelHelper($ch); $result = $vkChannelHelper->getGroups(); if ($result['status']) { $groups = $result['items']; $icon = F0FModel::getTmpInstance('Channeltypes', 'AutoTweetModel')->getIcon(AutotweetModelChanneltypes::TYPE_VK_CHANNEL); foreach ($groups as $group) { $nm = $group['name']; if (empty($nm) || $nm == 'null') { $nm = $group['gid']; } $attr = 'social_url="' . $group['url'] . '" social_icon="' . $icon . '"'; $attrs = array('attr' => $attr, 'option.attr' => 'social_url', 'option.key' => 'value', 'option.text' => 'text', 'disable' => false); $opt = JHTML::_('select.option', $group['gid'], $nm, $attrs); $options[] = $opt; } } $attribs['id'] = $name; $attribs['list.attr'] = null; $attribs['list.translate'] = false; $attribs['option.key'] = 'value'; $attribs['option.text'] = 'text'; $attribs['option.attr'] = 'social_url'; $attribs['list.select'] = $selected; return EHtmlSelect::genericlist($options, $name, $attribs); } catch (Exception $e) { $error_message = $e->getMessage(); $options[] = JHTML::_('select.option', '', $error_message); } } else { $options[] = JHTML::_('select.option', null, '-' . JText::_('JSELECT') . '-'); } return EHtmlSelect::customGenericList($options, $name, $attribs, $selected, $name, array('option.attr' => 'access_token')); }