Exemplo n.º 1
0
 /**
  * When saving a profile, checking for the subscribed status should be after saving the fields as we want to
  * be able to retrieve the person's latest first and last name.
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 public function onEditAfterSaveFields(&$data, SocialUser $user)
 {
     $user->reloadFields();
     $subscribe = isset($data[$this->inputName]) ? $data[$this->inputName] : false;
     $name = $user->getFieldValue('JOOMLA_FULLNAME');
     // Get the app params
     $params = $this->field->getApp()->getParams();
     $fieldParams = $this->field->getParams();
     $defaultList = $params->get('listid');
     if (is_object($name)) {
         $firstName = $name->first;
         $lastName = !empty($name->last) ? $name->last : $name->mildde;
     } else {
         $name = explode(' ', $name);
         $firstName = $name[0];
         $lastName = isset($name[1]) ? $name[1] : '';
     }
     // Get the previous stored data
     if ($subscribe && $defaultList && $params->get('apikey')) {
         // Load up mailchimp's library.
         $mailchimp = FD::mailchimp($params->get('apikey'));
         // Determine if there's a custom list id.
         $listId = $fieldParams->get('custom_list_id', $defaultList);
         $mailchimp->subscribe($listId, $user->email, $firstName, $lastName, $fieldParams->get('welcome_email', true));
     }
 }