/** * 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; // create list $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::getDB(true)->update('mailmotor_groups', array('is_default' => 'N', 'language' => null), 'language = ?', $item['language']); } // insert in database $id = BackendMailmotorModel::insertGroup($item); // insert in campaignmonitor self::insertCampaignMonitorID('list', $cmId, $id); // return the group ID return (int) $id; } }