Example #1
0
 /**
  * Create new lead on Joomla user registration
  *
  * For debug is better to switch function to:
  * public function onUserBeforeSave($success, $isNew, $user)
  *
  * @param array 	$user 		array with user information
  * @param boolean 	$isNew 		whether the user is new
  * @param boolean 	$success 	whether the user was saved successfully
  * @param string 	$msg 		error message
  */
 public function onUserAfterSave($user, $isNew, $success, $msg = '')
 {
     $this->log('onUserAfterSave method called.', JLog::INFO);
     $this->log('onUserAfterSave::isNew: ' . var_export($isNew, true), JLog::INFO);
     $this->log('onUserAfterSave::success: ' . var_export($success, true), JLog::INFO);
     $this->log('onUserAfterSave::send_registered: ' . var_export($this->params->get('send_registered'), true), JLog::INFO);
     if ($isNew && $success && $this->params->get('send_registered') == 1) {
         $this->log('onUserAfterSave: Send the user to Mautic.', JLog::INFO);
         try {
             $apiHelper = $this->getMauticApiHelper();
             $mauticBaseUrl = $apiHelper->getMauticBaseUrl();
             $auth = $apiHelper->getMauticAuth();
             $leadApi = \Mautic\MauticApi::getContext("leads", $auth, $mauticBaseUrl . '/api/');
             $ip = $this->getUserIP();
             $name = explode(' ', $user['name']);
             $mauticUser = array('ipAddress' => $ip, 'firstname' => isset($name[0]) ? $name[0] : '', 'lastname' => isset($name[1]) ? $name[1] : '', 'email' => $user['email']);
             $this->log('onUserAfterSave::mauticUser: '******'error'])) {
                 $this->log('onUserAfterSave::leadApi::create - response: ' . $result['error']['code'] . ": " . $result['error']['message'], JLog::ERROR);
             } elseif (!empty($result['lead']['id'])) {
                 $this->log('onUserAfterSave: Mautic lead was successfully created with ID ' . $result['lead']['id'], JLog::INFO);
             } else {
                 $this->log('onUserAfterSave: Mautic lead was NOT successfully created. ' . var_export($result, true), JLog::ERROR);
             }
         } catch (Exception $e) {
             $this->log($e->getMessage(), JLog::ERROR);
         }
     } else {
         $this->log('onUserAfterSave: Do not send the user to Mautic.', JLog::INFO);
     }
 }
Example #2
0
 protected function getContext($context)
 {
     list($auth, $apiUrl) = $this->getAuth();
     return MauticApi::getContext($context, $auth, $apiUrl);
 }