コード例 #1
0
 /**
  * @param int $recipientId
  * @param array $recipientListIds
  *
  * @throws Exception
  *
  * @return bool
  */
 public function saveRecipientListRecipientRelations($recipientId, array $recipientListIds = array())
 {
     try {
         SproutEmail_DefaultMailerRecipientListRecipientRecord::model()->deleteAll('recipientId = :recipientId', array(':recipientId' => $recipientId));
     } catch (Exception $e) {
         sproutEmail()->error($e->getMessage());
     }
     if (count($recipientListIds)) {
         foreach ($recipientListIds as $listId) {
             $list = $this->getRecipientListById($listId);
             if ($list) {
                 $relation = new SproutEmail_DefaultMailerRecipientListRecipientRecord();
                 $relation->recipientId = $recipientId;
                 $relation->recipientListId = $list->id;
                 if (!$relation->save(false)) {
                     throw new Exception(print_r($relation->getErrors(), true));
                 }
             } else {
                 throw new Exception(Craft::t('The recipient list with id {listId} does not exists.', array('listId' => $listId)));
             }
         }
     }
     return true;
 }