/** * Method to get the field input markup. * * @return string */ public function getInput() { $listid = $this->form->getValue('listid', 'params'); $options = CmcHelperList::getMergeFields($listid); $key = 'tag'; $val = 'name'; $attribs = 'multiple="multiple" size="8" class="chzn-none chzn-done"'; if ($options) { $content = JHtml::_('select.genericlist', $options, 'jform[params][fields][]', $attribs, $key, $val, $this->value, $this->id); } else { $content = '<div style="float:left;">' . JText::_('MOD_CMC_NO_FIELDS') . '</div>'; } return $content; }
/** * Method to get the record form. * * @param array $data An optional array of data for the form to interogate. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * * @return JForm A JForm object on success, false on failure */ public function getForm($data = array(), $loadData = true) { // Get the form. $form = $this->loadForm('com_cmc.user', 'user', array('control' => 'jform', 'load_data' => $loadData)); $userData = $this->getItem(); // If the user data is stored in the session we are dealing with arrays, if we are loading from DB with object if (is_array($userData)) { $old = $userData; $userData = new JRegistry(); $userData->set('list_id', $old['list_id']); $userData->set('email', $old['cmc_groups']['email']); } elseif (is_object($userData) && !$userData->get('id')) { $userData = new JRegistry(); $userData->set('list_id', isset($data['list_id']) ? $data['list_id'] : ''); $userData->set('email', isset($data['cmc_groups']['EMAIL']) ? $data['cmc_groups']['EMAIL'] : ''); } $listId = $userData->get('list_id', JFactory::getApplication()->input->get('filter_list')); // Get the merge fields and create a new form if ($listId) { $params = new JRegistry(); $params->set('listid', $listId); $fields = array_map(function ($value) { return $value['tag']; }, CmcHelperList::getMergeFields($listId)); $interests = array_map(function ($value) { return $value['id']; }, CmcHelperList::getInterestsFields($listId)); $params->set('fields', $fields); $params->set('interests', $interests); $renderer = CmcHelperXmlbuilder::getInstance($params); // Generate the xml for the form $xml = $renderer->build(); $form->load($xml, true); $subscriptionData = CmcHelperUsers::getSubscription($userData->get('email'), $userData->get('list_id')); // Bind the data to the form if ($subscriptionData) { $form->bind(CmcHelperSubscription::convertMergesToFormData($subscriptionData->merges)); } } if (empty($form)) { return false; } return $form; }