Ejemplo n.º 1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     $this->cm = BackendMailmotorCMHelper::getCM();
     $this->loadForm();
     $this->validateForm();
     $this->parse();
     $this->display();
 }
Ejemplo n.º 2
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $clientId = \SpoonFilter::getPostValue('client_id', null, '');
     // check input
     if (empty($clientId)) {
         $this->output(self::BAD_REQUEST);
     } else {
         // get basic details for this client
         $client = BackendMailmotorCMHelper::getCM()->getClient($clientId);
         // CM was successfully initialized
         $this->output(self::OK, $client);
     }
 }
Ejemplo n.º 3
0
 /**
  * Checks for external groups, and parses a message to import them.
  *
  * @return boolean Returns false if the user already made groups.
  */
 private function checkForExternalGroups()
 {
     // get all CM groups
     $externalGroups = BackendMailmotorCMHelper::getCM()->getListsByClientId();
     // return the result
     return !empty($externalGroups);
 }
Ejemplo n.º 4
0
 /**
  * Processes the subscriber import. Returns an array with failed subscribers.
  *
  * @param array $csv     The uploaded CSV file.
  * @param int   $groupID The group ID for which we're importing.
  * @return array A list with failed subscribers.
  */
 private function processImport($csv, $groupID)
 {
     // the CM list ID for the given group ID
     $listID = BackendMailmotorCMHelper::getCampaignMonitorID('list', $groupID);
     // reserve variables
     $subscribers = array();
     /*
         IMPORTANT NOTE: CM only allows a maximum amount of 100 subscribers for each import. So we have to batch
     */
     foreach ($csv as $key => $record) {
         // no e-mail address set means stop here
         if (empty($record['email'])) {
             continue;
         }
         // build record to insert
         $subscribers[$key] = $this->formatSubscriberCSVRow($record);
     }
     // divide the subscribers into batches of 100
     $batches = array_chunk($subscribers, 100);
     $failed = array();
     $feedback = array();
     $failedSubscribersCSV = array();
     // loop the batches
     foreach ($batches as $key => $batch) {
         // import every 100 subscribers
         $feedback[$key] = BackendMailmotorCMHelper::getCM()->importSubscribers($batch, $listID);
         // if the batch did not contain failed imports, we continue looping
         if (empty($feedback[$key])) {
             continue;
         }
         // merge the feedback results with the full failed set
         $failed = array_merge($failed, $feedback[$key]);
     }
     // now we have to loop all uploaded CSV rows in order to provide a .csv with all failed records.
     foreach ($csv as $row) {
         // the subscriber didn't fail the import, so we proceed to insert him in our database
         if (!in_array($row['email'], $failed)) {
             // build subscriber record
             $subscriber = array();
             $subscriber['email'] = $row['email'];
             $subscriber['source'] = 'import';
             $subscriber['created_on'] = BackendModel::getUTCDate();
             $subscriber['groups'] = $groupID;
             // unset the email (for the custom fields)
             unset($row['email']);
             // save the address in our database, with the assigned custom fields
             BackendMailmotorModel::saveAddress($subscriber, $groupID, $row);
             // continue looping
             continue;
         }
         // subscriber failed in import, so add his record to the fail-csv
         $failedSubscribersCSV[] = $row;
     }
     // return the failed subscribers
     return $failedSubscribersCSV;
 }