CampaignMonitor::updateClientBasics PHP Method

updateClientBasics() public method

Updates a client's basic settings.
public updateClientBasics ( string $companyName, string $country, string $timezone, string[optional] $clientId = null ) : string
$companyName string The client company name.
$country string This client's country.
$timezone string Client timezone for tracking and reporting data.
$clientId string[optional]
return string
    public function updateClientBasics($companyName, $country, $timezone, $clientId = null)
    {
        // set ID
        $clientId = empty($clientId) ? $this->getClientId() : $clientId;
        // fetch the country list
        $countries = $this->getCountries();
        $timezones = $this->getTimezones();
        // check if $country is in the allowed country list
        if (!in_array($country, $countries)) {
            throw new CampaignMonitorException('No valid country provided');
        }
        // check if $timezone is in the allowed timezones list
        if (!in_array($timezone, $timezones)) {
            throw new CampaignMonitorException('No valid timezone provided');
        }
        // set parameters
        $parameters['CompanyName'] = (string) $companyName;
        $parameters['Country'] = (string) $country;
        $parameters['Timezone'] = (string) $timezone;
        // try and update the record
        return $this->doCall('clients/' . $clientId . '/setbasics', $parameters, 'PUT');
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Updates a client record.
  *
  * @return	mixed
  * @param	array $record		The client record to update.
  */
 private function updateClient($record)
 {
     // get the account settings
     $url = BackendModel::getModuleSetting($this->getModule(), 'cm_url');
     $username = BackendModel::getModuleSetting($this->getModule(), 'cm_username');
     $password = BackendModel::getModuleSetting($this->getModule(), 'cm_password');
     // try and update the client info
     try {
         // fetch complete list of timezones as pairs
         $timezones = BackendMailmotorCMHelper::getTimezonesAsPairs();
         // init CampaignMonitor object
         $cm = new CampaignMonitor($url, $username, $password, 10, $this->clientID);
         // update the client
         $cm->updateClientBasics($record['company_name'], $record['contact_name'], $record['contact_email'], $record['country'], $timezones[$record['timezone']]);
     } catch (Exception $e) {
         // add an error to the email field
         $this->redirect(BackendModel::createURLForAction('settings') . '&error=campaign-monitor-error&var=' . $e->getMessage() . '#tabSettingsClient');
     }
 }