/** * Method to bind an associative array or object to the JTable instance.This * method only binds properties that are publicly accessible and optionally * takes an array of properties to ignore when binding. * * @param mixed $src An associative array or object to bind to the JTable instance. * @param mixed $ignore An optional array or space separated list of properties to ignore while binding. * * @return boolean True on success. * * @since 11.1 * @throws InvalidArgumentException */ public function bind($src, $ignore = array()) { // If we have cmc_groups or cmc_intersts, than this would mean that we are coming from the form if (isset($src['cmc_groups']) || isset($src['cmc_interests'])) { $src['merges'] = CmcHelperList::mergeVars($src); } return parent::bind($src, $ignore); }
/** * Checks if the current user exists in the mailchimp database * * @throws Exception * * @return void */ public function exist() { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $chimp = new cmcHelperChimp(); $input = JFactory::getApplication()->input; $form = $input->get('jform', '', 'array'); $mergeVars = CmcHelperList::mergeVars($form); $email = $mergeVars['EMAIL']; $listId = $form['cmc']['listid']; // Check if the user is in the list already $userlists = $chimp->listsForEmail($email); if ($userlists && in_array($listId, $userlists)) { $exist = true; $url = JRoute::_('index.php?option=com_cmc&task=subscription.update&email=' . $email . '&listid=' . $listId); } else { $exist = false; $url = ''; } echo json_encode(array('exists' => $exist, 'url' => $url)); jexit(); }
/** * 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; }