Example #1
0
 /**
  * Creates a list in campaignmonitor and inserts the group record in the database. Returns the group ID
  *
  * @param array $item The group record to insert.
  * @return int
  */
 public static function insertGroup(array $item)
 {
     // build unsubscribe link for this list
     $unsubscribeLink = SITE_URL . BackendModel::getURLForBlock('Mailmotor', 'unsubscribe', BL::getWorkingLanguage());
     // predict the next insert ID for the mailmotor_groups table
     $groupId = BackendMailmotorModel::getMaximumIdForGroups() + 1;
     $cmId = self::getCM()->createList($item['name'], $unsubscribeLink . '/?group=' . $groupId . '&email=[email]');
     // a list was created
     if ($cmId) {
         // check if we have a default group set
         if ($item['is_default'] === 'Y' && $item['language'] != '0') {
             // set all defaults to N.
             BackendModel::getContainer()->get('database')->update('mailmotor_groups', array('is_default' => 'N', 'language' => null), 'language = ?', $item['language']);
         }
         $id = BackendMailmotorModel::insertGroup($item);
         self::insertCampaignMonitorID('list', $cmId, $id);
         return (int) $id;
     }
 }