Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
Arquivo: cmc.php Projeto: fracting/cmc
 /**
  * Manupulates the registration form
  *
  * @param   string  &$data  - registration form data
  *
  * @return mixed
  */
 public function onUserRegisterFormDisplay(&$data)
 {
     // Load the funky stuff
     CompojoomHtmlBehavior::jquery();
     JHtml::stylesheet('media/plg_community_cmc/css/style.css');
     JHtml::script('media/plg_community_cmc/js/cmc.js');
     // Create the xml for JForm
     $builder = CmcHelperXmlbuilder::getInstance($this->params);
     $xml = $builder->build();
     $form = new JForm('myform');
     $form->addFieldPath(JPATH_ADMINISTRATOR . '/components/com_cmc/models/fields');
     $form->load($xml);
     $displayData = new stdClass();
     $displayData->form = $form;
     $layout = new CompojoomLayoutFile('newsletter.form', JPATH_BASE . '/plugins/community/cmc/layouts');
     $html = $layout->render($displayData);
     $pos = strrpos($data, '<div class="joms-form__group">');
     $data = substr($data, 0, $pos) . $html . substr($data, $pos);
 }
Exemplo n.º 3
0
 /**
  * Creates a JForm
  *
  * @param   int     $id      - the module id. We use it to create unique jform instance
  * @param   object  $params  - the module params
  *
  * @return object
  */
 public static function getForm($id, $params)
 {
     $renderer = CmcHelperXmlbuilder::getInstance($params);
     $user = JFactory::getUser();
     // Generate the xml for the form
     $xml = $renderer->build();
     $mapping = self::getMapping($params->get('mapfields'));
     try {
         JForm::addFieldPath(JPATH_ADMINISTRATOR . '/components/com_cmc/models/fields');
         $form = JForm::getInstance('mod_cmc_' . $id, $xml, array('control' => 'jform'));
         $form->bind($mapping);
         // If we are not dealing with a guest, try to load the already existing profile merges and add them to the form
         if (!$user->guest) {
             $subscriptionData = CmcHelperUsers::getSubscription($user->email, $params->get('listid'));
             if ($subscriptionData) {
                 $form->bind(CmcHelperSubscription::convertMergesToFormData($subscriptionData->merges));
             }
         }
     } catch (Exception $e) {
         return false;
     }
     return $form;
 }
Exemplo n.º 4
0
Arquivo: cmc.php Projeto: fracting/cmc
 /**
  * Subscribe a user to our list
  *
  * @param   JForm  $form  - the user form
  * @param   array  $data  - the user data
  *
  * @return bool
  *
  * @throws Exception
  */
 public function subscribe($form, $data)
 {
     $needToValidate = true;
     $input = JFactory::getApplication()->input;
     $task = $input->get('task');
     if (in_array($task, array('register', 'apply', 'save'))) {
         $requestData = JFactory::getApplication()->input->get('jform', array(), 'array');
         $needToValidate = isset($requestData['cmc']) && isset($requestData['cmc']['newsletter']);
     }
     if ($needToValidate) {
         $lang = JFactory::getLanguage();
         $lang->load('plg_user_cmc', JPATH_ADMINISTRATOR);
         CompojoomHtmlBehavior::jquery();
         JHtml::script('media/plg_user_cmc/js/cmc.js');
         $renderer = CmcHelperXmlbuilder::getInstance($this->params);
         // Render Content
         $html = $renderer->build();
         // Inject fields into the form
         $form->load($html, false);
     }
     return true;
 }
Exemplo n.º 5
0
Arquivo: cmc.php Projeto: fracting/cmc
 /**
  * Display our CMC fields at the registration
  *
  * @param   object  $tab       - The tab
  * @param   JUser   $user      - The user
  * @param   object  $ui        - The UI
  * @param   object  $postdata  - The postdata
  *
  * @return string
  */
 public function getDisplayRegistration($tab, $user, $ui, $postdata)
 {
     JHtml::_('stylesheet', JURI::root() . 'media/mod_cmc/css/cmc.css');
     CompojoomHtmlBehavior::jquery();
     $plugin = GetCmcTab::getPlugin();
     $listid = $plugin->params->get('listid', "");
     $interests = $plugin->params->get('interests', '');
     $fields = $plugin->params->get('fields', '');
     // Create the xml for JForm
     $builder = CmcHelperXmlbuilder::getInstance($plugin->params);
     // Load JS & Co
     JFactory::getDocument()->addScriptDeclaration("\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tvar \$ = jQuery;\n\n\t\t\t\t\$('#cmc_check_newsletter').on('click', function() {\n\t\t\t\t\tif(\$(this).prop('checked'))\n\t\t\t\t\t{\n\t\t\t\t\t\t\$('input.cmc_req').addClass('required');\n\t\t\t\t\t\t\$('#cmc_newsletter').show();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t\$('input.cmc_req').removeClass('required');\n\t\t\t\t\t\t\$('#cmc_newsletter').hide();\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\t\$('#cmc_newsletter').hide();\n\t\t\t});\n\t\t");
     // We have to set the fields / interests manually for cb because they are no array! See explode
     if (!empty($fields)) {
         $fields = explode("|*|", $plugin->params->get('fields', ''));
         $builder->fields = $fields;
     }
     if (!empty($interests)) {
         $interests = explode("|*|", $plugin->params->get('interests', ''));
         $builder->interests = $interests;
     }
     $xml = $builder->build();
     $form = new JForm('myform');
     $form->addFieldPath(JPATH_ADMINISTRATOR . '/components/com_cmc/models/fields');
     $form->load($xml);
     $fieldsets = $form->getFieldsets();
     $ret = '<div class="cbFieldsContentsTab">';
     $ret .= '<div class="sectiontableentry1 cbft_predefined cbtt_input form-group cb_form_line clearfix">';
     $ret .= '<label for="name" id="cblabname" class="control-label col-sm-3">' . JText::_('PLG_CMCCB_SUBSCRIPTION') . '</label>';
     $ret .= '<div class="cb_field col-sm-9">';
     $ret .= '<input type="checkbox" name="cmc[newsletter]" id="cmc_check_newsletter" value="1" /> ';
     $ret .= '<label for="cmc_check_newsletter" id="cmc_newsletter_lbl">' . JText::_('PLG_CMCCB_NEWSLETTER') . '</label>';
     $ret .= "</div>\n";
     $ret .= "</div>";
     $ret .= "<div id='cmc_td_newsletter' style='' class=\"cbFieldsContentsTab\">\n";
     $ret .= "<div id=\"cmc_newsletter\" style=\"display: block;\">\n";
     // Render Content
     foreach ($fieldsets as $key => $value) {
         if ($key != "cmc") {
             $ret .= '<div class="sectiontableentry1 cbft_predefined cbtt_input form-group cb_form_line clearfix">';
             $ret .= '<label class="col-sm-12">' . JText::_($value->label) . '</label>';
             $ret .= '</div>';
             $fields = $form->getFieldset($key);
             foreach ($fields as $field) {
                 $ret .= '<div class="sectiontableentry1 cbft_predefined cbtt_input form-group cb_form_line clearfix">';
                 $ret .= '<div class="control-label col-sm-3">' . $field->label . '</div>';
                 $ret .= '<div class="cb_field col-sm-9">';
                 $ret .= $field->input;
                 $ret .= '</div>';
                 $ret .= '</div>';
             }
         }
     }
     $ret .= '<input type="hidden" name="cmc[listid]" id="cmc_listid" value="' . $listid . '" />';
     // End open tables / divs
     $ret .= "</div>\n";
     $ret .= "</div>\n";
     return $ret;
 }