コード例 #1
0
 public function actionDeleteRecipientList()
 {
     $this->requirePostRequest();
     $id = craft()->request->getRequiredPost('id');
     $model = null;
     if ($model = sproutEmailDefaultMailer()->getRecipientListById($id)) {
         if (!$model) {
             throw new Exception(Craft::t('Recipient list with id ({id}) was not found.', array('id' => $id)));
         }
         $vars = array('recipientListId' => $model->id);
         $deleted = SproutEmail_DefaultMailerRecipientListRecord::model()->deleteByPk($model->id);
         if ($deleted) {
             SproutEmail_DefaultMailerRecipientListRecipientRecord::model()->deleteAllByAttributes($vars);
             craft()->userSession->setNotice(Craft::t('Recipient list deleted successfully.'));
             if (craft()->request->isAjaxRequest()) {
                 $this->returnJson(array('success' => true));
             }
         } else {
             craft()->userSession->setNotice(Craft::t('Unable to delete recipient list.'));
             if (craft()->request->isAjaxRequest()) {
                 $this->returnErrorJson(Craft::t('Unable to delete recipient list.'));
             }
         }
         $this->redirectToPostedUrl($model);
     }
     throw new HttpException(404);
 }
コード例 #2
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;
 }