/** * Saves the registration information * * @param object $tab - The tab * @param JUser &$user - The JUser * @param object $ui - The UI * @param object $postdata - The postdata * * @return void */ function saveRegistrationTab($tab, &$user, $ui, $postdata) { // Save User to temporary table- not active here if (!empty($postdata['cmc']['newsletter'])) { // For the hidden field $listId = $postdata['cmc']['listid']; $plugin = GetCmcTab::getPlugin(); $mappedData = $this->getMapping($plugin->params->get('mapfields'), $postdata); if (count($mappedData)) { $mergedGroups = array_merge($mappedData, $postdata['cmc_groups']); $postdata = array_merge($postdata, array('cmc_groups' => $mergedGroups)); } $updated = CmcHelperRegistration::isSubscribed($listId, $user->email); if ($updated) { // Update users subscription with the new data CmcHelperRegistration::updateSubscription($user, $postdata); } else { // Temporary save user in cmc database CmcHelperRegistration::saveTempUser($user, $postdata, _CPLG_CB); } } }
/** * Prepares the form * * @param array $data - the users data * @param boolean $isNew - is the user new * @param object $result - the db result * @param string $error - the error message * * @return boolean */ public function onUserAfterSave($data, $isNew, $result, $error) { $userId = ArrayHelper::getValue($data, 'id', 0, 'int'); $input = JFactory::getApplication()->input; $task = $input->get('task'); if (in_array($task, array('register', 'activate'))) { if ($userId && $result && isset($data['cmc']) && count($data['cmc'])) { if ($data["cmc"]["newsletter"] != "1" && $isNew != false) { // Abort if Newsletter is not checked return true; } $mappedData = $this->getMapping($this->params->get('mapfields'), $data); if (count($mappedData)) { $mergedGroups = array_merge($mappedData, $data['cmc_groups']); $data = array_merge($data, array('cmc_groups' => $mergedGroups)); } $user = JFactory::getUser($data["id"]); if ($data["block"] == 1) { // Temporary save user CmcHelperRegistration::saveTempUser($user, $data, _CPLG_JOOMLA); } else { if (!$isNew) { // Activate User to Mailchimp CmcHelperRegistration::activateTempUser($user); } else { // Directly activate user $activated = CmcHelperRegistration::activateDirectUser($user, $data["cmc"], _CPLG_JOOMLA); if ($activated) { JFactory::getApplication()->enqueueMessage(JText::_('COM_CMC_YOU_VE_BEEN_SUBSCRIBED_BUT_CONFIRMATION_IS_NEEDED')); } } } } else { // We only do something if the user is unblocked if ($data["block"] == 0) { // Checking if user exists etc. is taken place in activate function CmcHelperRegistration::activateTempUser(JFactory::getUser($data["id"])); } } } if (in_array($task, array('apply', 'save'))) { if ($userId && $result && isset($data['cmc']) && count($data['cmc'])) { if ($data["cmc"]["newsletter"] != "1") { // Abort if Newsletter is not checked return true; } $mappedData = $this->getMapping($this->params->get('mapfields'), $data); if (count($mappedData)) { $mergedGroups = array_merge($mappedData, $data['cmc_groups']); $data = array_merge($data, array('cmc_groups' => $mergedGroups)); } } $subscription = CmcHelperUsers::getSubscription($data['email'], $data['cmc']['listid']); // Updating it to mailchimp $update = $subscription ? true : false; CmcHelperList::subscribe($data['cmc']['listid'], $data['email'], $data['cmc_groups']['FNAME'], $data['cmc_groups']['LNAME'], CmcHelperList::mergeVars($data), 'html', $update, true); } return true; }
/** * Saves a temporary subscription if necessary * * @param array $data - post data * * @return bool */ public function onRegisterValidate($data) { // If newsletter was selected - save the user data! if (isset($data['cmc']) && (int) $data['cmc']['newsletter'] === 1) { // Jomsocial doesn't create a user_id until the very last step // that's why we will save the user token for referrence later on $token = $this->getUserToken($data['authkey']); $user = new stdClass(); $user->id = $token; $postData = array(); $mappedData = $this->getMapping($this->params->get('mapfields'), $data); if (count($mappedData)) { $mergedGroups = array_merge($mappedData, $data['cmc_groups']); $data = array_merge($data, array('cmc_groups' => $mergedGroups)); } $postData['cmc']['listid'] = $data['cmc']['listid']; $postData['cmc_groups'] = $data['cmc_groups']; $postData['cmc_interests'] = $data['cmc_interests']; CmcHelperRegistration::saveTempUser($user, $postData, _CPLG_JOMSOCIAL); } }