/** * Test new list + add to list super mass actions */ public function testSuperExecute() { X2List::model()->deleteAllByAttributes(array('name' => 'test')); $_SESSION = array(); $newList = new NewListFromSelection(); $addToList = new MassAddToList(); TestingAuxLib::suLogin('admin'); Yii::app()->user; // initializes $_SESSION superglobal Yii::app()->controller = new ContactsController('contacts', new ContactsModule('contacts', null)); $idChecksum = SmartActiveDataProvider::calculateChecksumFromIds(Yii::app()->db->createCommand("\n SELECT id\n FROM x2_contacts\n ORDER BY lastUpdated DESC, id DESC\n ")->queryColumn()); // perform super mass actions in batches, ensuring that after each batch, the id queue // in the session matches the remaining records to be updated. Call the new list from // selection mass action on the first batch and the mass add to list on all subsequent // batches to simulate behavior of grid view $_POST['modelType'] = 'Contacts'; $_POST['listName'] = 'test'; $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['SERVER_NAME'] = 'localhost'; $updated = 0; $uid = null; $listId = null; while (true) { ob_start(); if (!isset($listId)) { $newList->superExecute($uid, 24, $idChecksum); } else { $_POST['listId'] = $listId; $addToList->superExecute($uid, 24, $idChecksum); } $retVal = CJSON::decode(ob_get_contents()); ob_clean(); $this->assertTrue(!isset($retVal['errorCode'])); $uid = $retVal['uid']; if (isset($retVal['listId'])) { $listId = $retVal['listId']; } // get ids of contacts not in new list $remainingIds = Yii::app()->db->createCommand(' SELECT t.id FROM x2_contacts AS t WHERE t.id NOT IN ( SELECT contactId FROM x2_list_items AS t2 JOIN x2_lists AS t3 ON t3.id = t2.listId WHERE t.id = t2.contactId AND t3.name="test" ) ')->queryColumn(); if (isset($retVal['complete'])) { $this->assertEquals(0, count($remainingIds)); $this->assertTrue(!isset($_SESSION[MassAction::SESSION_KEY_PREFIX . $uid])); break; } else { $storedIds = $_SESSION[MassAction::SESSION_KEY_PREFIX . $uid]; sort($storedIds); $this->assertEquals($remainingIds, $storedIds); } } }
public function execute(array $gvSelection) { if (Yii::app()->controller->modelClass !== 'Contacts' || !isset($_POST['listName']) || $_POST['listName'] === '') { throw new CHttpException(400, Yii::t('app', 'Bad Request')); } if (!Yii::app()->params->isAdmin && !Yii::app()->user->checkAccess('ContactsCreateListFromSelection')) { return -1; } $listName = $_POST['listName']; foreach ($gvSelection as &$contactId) { if (!ctype_digit((string) $contactId)) { throw new CHttpException(400, Yii::t('app', 'Invalid selection.')); } } $list = new X2List(); $list->name = $_POST['listName']; $list->modelName = 'Contacts'; $list->type = 'static'; $list->assignedTo = Yii::app()->user->getName(); $list->visibility = 1; $list->createDate = time(); $list->lastUpdated = time(); $itemModel = X2Model::model('Contacts'); $success = true; if ($list->save()) { // if the list is valid save it so we can get the ID $count = 0; foreach ($gvSelection as &$itemId) { if ($itemModel->exists('id="' . $itemId . '"')) { // check if contact exists $item = new X2ListItem(); $item->contactId = $itemId; $item->listId = $list->id; if ($item->save()) { // add all the things! $count++; } } } $list->count = $count; $this->listId = $list->id; if ($list->save()) { self::$successFlashes[] = Yii::t('app', '{count} record' . ($count === 1 ? '' : 's') . ' added to new list "{list}"', array('{count}' => $count, '{list}' => $list->name)); } else { self::$errorFlashes[] = Yii::t('app', 'List created but records could not be added to it'); } } else { $success = false; self::$errorFlashes[] = Yii::t('app', 'List could not be created'); } return $success ? $count : -1; }
/** * Super mass update firstName and lastName for fixture records */ public function testSuperExecute() { X2List::model()->deleteAllByAttributes(array('name' => 'test')); $_SESSION = array(); $newList = new NewListFromSelection(); TestingAuxLib::suLogin('admin'); Yii::app()->user; // initializes $_SESSION superglobal Yii::app()->controller = new ContactsController('contacts', new ContactsModule('contacts', null)); // perform super mass actions in batches, ensuring that after each batch, the id queue // in the session matches the remaining records to be updated $_POST['modelType'] = 'Contacts'; $_POST['listName'] = 'test'; $_SERVER['REQUEST_METHOD'] = 'POST'; $_SERVER['SERVER_NAME'] = 'localhost'; $idChecksum = SmartActiveDataProvider::calculateChecksumFromIds(Yii::app()->db->createCommand("\n SELECT id\n FROM x2_contacts\n ORDER BY lastUpdated DESC, id DESC\n ")->queryColumn()); $updated = 0; $uid = null; while (true) { $this->obStart(); $newList->superExecute($uid, 24, $idChecksum); $retVal = CJSON::decode(ob_get_contents()); $this->obEndClean(); $this->assertTrue(!isset($retVal['errorCode'])); $uid = $retVal['uid']; // get ids of contacts not in new list $remainingIds = Yii::app()->db->createCommand(' SELECT t.id FROM x2_contacts AS t WHERE t.id NOT IN ( SELECT contactId FROM x2_list_items AS t2 JOIN x2_lists AS t3 ON t3.id = t2.listId WHERE t.id = t2.contactId AND t3.name="test" ) ')->queryColumn(); $storedIds = $_SESSION[MassAction::SESSION_KEY_PREFIX . $uid]; sort($storedIds); $this->assertEquals($remainingIds, $storedIds); // new list from selection mass action should only ever get run on the first batch. // subsequent batches get added to the list (mass action swapping is handled // client-side) break; } }
public static function getAllStaticListNames($controller) { $listNames = array(); // get all static lists foreach (X2List::model()->findAllByAttributes(array('type' => 'static')) as $list) { if ($controller->checkPermissions($list, 'edit')) { // check permissions $listNames[$list->id] = $list->name; } } return $listNames; }
/** * Returns the static model of the specified AR class. * @return ContactList the static model class */ public static function model($className = __CLASS__) { return parent::model($className); }
/** * Create a campaign for all contacts with a certain tag. * * This action will create and save the campaign and redirect the user to * edit screen to fill in the email message, etc. It is intended to provide * a fast workflow from tags to campaigns. * * @param string $tag */ public function actionCreateFromTag($tag) { //enusre tag sanity if (empty($tag) || strlen(trim($tag)) == 0) { Yii::app()->user->setFlash('error', Yii::t('marketing', 'Invalid tag value')); $this->redirect(Yii::app()->request->getUrlReferrer()); } //ensure sacred hash if (substr($tag, 0, 1) != '#') { $tag = '#' . $tag; } //only works for contacts $modelType = 'Contacts'; $now = time(); //get all contact ids from tags $ids = Yii::app()->db->createCommand()->select('itemId')->from('x2_tags')->where('type=:type AND tag=:tag')->group('itemId')->order('itemId ASC')->bindValues(array(':type' => $modelType, ':tag' => $tag))->queryColumn(); //create static list $list = new X2List(); $list->name = Yii::t('marketing', 'Contacts for tag') . ' ' . $tag; $list->modelName = $modelType; $list->type = 'campaign'; $list->count = count($ids); $list->visibility = 1; $list->assignedTo = Yii::app()->user->getName(); $list->createDate = $now; $list->lastUpdated = $now; //create campaign $campaign = new Campaign(); $campaign->name = Yii::t('marketing', 'Mailing for tag') . ' ' . $tag; $campaign->type = 'Email'; $campaign->visibility = 1; $campaign->assignedTo = Yii::app()->user->getName(); $campaign->createdBy = Yii::app()->user->getName(); $campaign->updatedBy = Yii::app()->user->getName(); $campaign->createDate = $now; $campaign->lastUpdated = $now; $transaction = Yii::app()->db->beginTransaction(); try { if (!$list->save()) { throw new Exception(array_shift(array_shift($list->getErrors()))); } $campaign->listId = $list->nameId; if (!$campaign->save()) { throw new Exception(array_shift(array_shift($campaign->getErrors()))); } foreach ($ids as $id) { $listItem = new X2ListItem(); $listItem->listId = $list->id; $listItem->contactId = $id; if (!$listItem->save()) { throw new Exception(array_shift(array_shift($listItem->getErrors()))); } } $transaction->commit(); $this->redirect($this->createUrl('update', array('id' => $campaign->id))); } catch (Exception $e) { $transaction->rollBack(); Yii::app()->user->setFlash('error', Yii::t('marketing', 'Could not create mailing') . ': ' . $e->getMessage()); $this->redirect(Yii::app()->request->getUrlReferrer()); } }
public function searchList($id, $pageSize = null) { $list = X2List::model()->findByPk($id); if (isset($list)) { $search = $list->queryCriteria(); $this->compareAttributes($search); return new SmartActiveDataProvider('Accounts', array('criteria' => $search, 'sort' => array('defaultOrder' => 't.lastUpdated DESC'), 'pagination' => array('pageSize' => isset($pageSize) ? $pageSize : Profile::getResultsPerPage()))); } else { //if list is not working, return all contacts return $this->searchBase(); } }
/** * Export records from a model */ public function actionExportModels($listId = null) { unset($_SESSION['modelExportFile'], $_SESSION['exportModelCriteria'], $_SESSION['modelExportMeta']); $modelList = Modules::getExportableModules(); // Determine the model selected by the user if (isset($_GET['model']) || isset($_POST['model'])) { $model = isset($_GET['model']) ? $_GET['model'] : $_POST['model']; $modelName = str_replace(' ', '', $model); } if (isset($model) && in_array($modelName, array_keys($modelList))) { $staticModel = X2Model::model($modelName); $modulePath = '/' . $staticModel->module; $modulePath .= $modulePath; if (is_null($listId) || $model != 'Contacts') { $file = "records_export.csv"; $listName = CHtml::link(Yii::t('admin', 'All {model}', array('{model}' => $model)), array($modulePath . '/index'), array('style' => 'text-decoration:none;')); // Forcefully disable eager loading so it doesn't go super-slow) $_SESSION['exportModelCriteria'] = new CDbCriteria(); $_SESSION['exportModelCriteria']->with = array(); } else { $list = X2List::load($listId); $_SESSION['exportModelCriteria'] = $list->queryCriteria(); $file = "list" . $listId . ".csv"; $listName = CHtml::link(Yii::t('admin', 'List') . " {$listId}: " . $list->name, array($modulePath . '/list', 'id' => $listId), array('style' => 'text-decoration:none;')); } $filePath = $this->safePath($file); $_SESSION['modelExportFile'] = $file; $attributes = X2Model::model($modelName)->attributes; if ($modelName === 'Actions') { // Make sure the ActionText is exported too $attributes = array_merge($attributes, array('actionDescription' => null)); } $meta = array_keys($attributes); if (isset($list)) { // Figure out gridview settings to export those columns $gridviewSettings = json_decode(Yii::app()->params->profile->gridviewSettings, true); if (isset($gridviewSettings['contacts_list' . $listId])) { $tempMeta = array_keys($gridviewSettings['contacts_list' . $listId]); $meta = array_intersect($tempMeta, $meta); } } // Set up metadata $_SESSION['modelExportMeta'] = $meta; $fp = fopen($filePath, 'w+'); fputcsv($fp, $meta); fclose($fp); } else { // If an invalid model was chosen, unset it so that the model list // will be displayed instead. if (isset($model)) { unset($model); } } $viewParam = array('modelList' => $modelList, 'listId' => $listId, 'model' => ''); if (isset($model)) { $viewParam['model'] = $model; if ($model == 'Contacts') { $viewParam['listName'] = $listName; } } $this->render('exportModels', $viewParam); }
/** * Creates, saves, and returns a duplicate static list containing the same items. */ public function staticDuplicate() { $dup = new X2List(); $dup->attributes = $this->attributes; $dup->id = null; $dup->type = 'static'; $dup->createDate = $dup->lastUpdated = time(); $dup->isNewRecord = true; if (!$dup->save()) { return; } $count = 0; $itemIds = $this->dbCommand()->select('id')->queryColumn(); //generate some sql, because I can't find a yii way to insert many records in one query $values = ''; foreach ($itemIds as $id) { if ($count !== 0) { $values .= ','; } $values .= '(' . $id . ',' . $dup->id . ')'; $count++; } $sql = 'INSERT into x2_list_items (contactId, listId) VALUES ' . $values . ';'; Yii::app()->db->createCommand($sql)->execute(); $dup->count = $count; $dup->save(); return $dup; }
/** * Gets a list of contacts. */ public function actionList() { $listId = $_POST['id']; $list = X2List::model()->findByPk($listId); if (isset($list)) { //$list=X2List::load($listId); } else { $list = X2List::model()->findByAttributes(array('name' => $listId)); if (isset($list)) { $listId = $list->id; //$list=X2List::load($listId); } else { $this->_sendResponse(404, 'No list found with id: ' . $_POST['id']); } } $model = new Contacts('search'); $dataProvider = $model->searchList($listId, 10); $data = $dataProvider->getData(); $this->_sendResponse(200, json_encode($data), true); }
if (!empty($order)) { $vcrDataProvider->criteria->order = $order; } // run SQL to get VCR links $vcrData = X2List::getVcrLinks($vcrDataProvider, $model->id); // if this contact isn't on the list, default to All Contacts (unless we already tried that) if ($vcrData === false && $listId !== 'index') { $listLink = CHtml::link(Yii::t('contacts', 'All {module}', array('{module}' => $moduleTitle)), array('/contacts/' . $path)); $vcrDataProvider = $searchModel->searchAll(); if (empty($order)) { $order = $vcrDataProvider->sort->getOrderBy(); } if (!empty($order)) { $vcrDataProvider->criteria->order = $order; } $vcrData = X2List::getVcrLinks($vcrDataProvider, $model->id); } if (is_array($vcrData) && count($vcrData)) { ?> <div class="vcrPager"> <div class="summary"> <?php if (isset($listLink)) { echo $listLink; } echo Yii::t('contacts', '<b>{m}</b> of <b>{n}</b>', array('{m}' => $vcrData['index'], '{n}' => $vcrData['count'])); ?> </div> <div class='x2-button-group'> <?php //echo CHtml::tag('ul',array('class'=>'vcrPager'),$vcrData['prev']."\n".$vcrData['next']);
/** * Renders the mass action dialog, if applicable * @param string $gridId id of grid view */ public function renderDialog($gridId, $modelName) { $listNames = X2List::getAllStaticListNames(Yii::app()->controller); echo "\n <div class='mass-action-dialog' id='" . $this->getDialogId($gridId) . "' \n style='display: none;'>\n <span>" . Yii::t('app', 'Select a list to which the selected records will be added.') . "\n </span>" . (empty($listNames) ? '<br><br>' . Yii::t('app', 'There are no static lists to which ' . 'contacts can be added.') . ' ' . CHtml::link(Yii::t('contacts', 'Create a List'), array('/contacts/contacts/createList')) : CHtml::dropDownList('addToListTarget', null, $listNames)) . "\n </div>"; }
/** * Returns a DataProvider for all the contacts in the specified list, * using this Contact model's attributes as a search filter */ public function searchList($id, $pageSize = null) { $list = X2List::model()->findByPk($id); if (isset($list)) { $search = $list->dbCriteria(); $search->compare('name', $this->name, true); $search->compare('firstName', $this->firstName, true); $search->compare('lastName', $this->lastName, true); $search->compare('title', $this->title, true); $search->compare('company', $this->company, true); $search->compare('phone', $this->phone, true); $search->compare('phone2', $this->phone2, true); $search->compare('email', $this->email, true); $search->compare('website', $this->website, true); $search->compare('address', $this->address, true); $search->compare('city', $this->city, true); $search->compare('state', $this->state, true); $search->compare('zipcode', $this->zipcode, true); $search->compare('country', $this->country, true); $search->compare('visibility', $this->visibility); $search->compare('assignedTo', $this->assignedTo, true); $search->compare('backgroundInfo', $this->backgroundInfo, true); $search->compare('twitter', $this->twitter, true); $search->compare('linkedin', $this->linkedin, true); $search->compare('skype', $this->skype, true); $search->compare('googleplus', $this->googleplus, true); // $search->compare('lastUpdated',$this->lastUpdated,true); $search->compare('updatedBy', $this->updatedBy, true); $search->compare('priority', $this->priority, true); $search->compare('leadSource', $this->leadSource, true); $search->compare('rating', $this->rating); return new CActiveDataProvider('Contacts', array('criteria' => $search, 'sort' => array('defaultOrder' => 'lastupdated DESC'), 'pagination' => array('pageSize' => isset($pageSize) ? $pageSize : ProfileChild::getResultsPerPage()))); } else { //if list is not working, return all contacts return new CActiveDataProvider('Contacts', array('sort' => array('defaultOrder' => 'createDate DESC'), 'pagination' => array('pageSize' => ProfileChild::getResultsPerPage()))); } }
<?php /* $this->renderPartial('_search',array( 'model'=>$model, 'users'=>UserChild::getNames(), )); */ ?> </div><!-- search-form --> <?php $this->widget('application.components.X2GridView', array('id' => 'contacts-grid', 'baseScriptUrl' => Yii::app()->request->baseUrl . '/themes/' . Yii::app()->theme->name . '/css/gridview', 'template' => '<h2>' . $heading . '</h2><div class="title-bar">' . CHtml::link(Yii::t('app', 'Clear Filters'), array(Yii::app()->controller->action->id, 'clearFilters' => 1)) . ' | ' . CHtml::link(Yii::t('app', 'Export'), array('/contacts/exportList/' . $listModel->id)) . ' | ' . CHtml::link(Yii::t('app', 'Columns'), 'javascript:void(0);', array('class' => 'column-selector-link')) . '{summary}</div>{items}{pager}', 'dataProvider' => $dataProvider, 'modelName' => 'Contacts', 'viewName' => 'contacts_list' . $listModel->id, 'defaultGvSettings' => array('gvCheckbox' => 35, 'name' => 180, 'phone' => 101, 'lastUpdated' => 94, 'leadSource' => 101, 'gvControls' => 74), 'selectableRows' => 2, 'specialColumns' => array('name' => array('name' => 'lastName', 'header' => Yii::t('contacts', 'Name'), 'value' => 'CHtml::link($data->firstName." ".$data->lastName,array("view","id"=>$data->id))', 'type' => 'raw')), 'enableControls' => true, 'enableTags' => true)); ?> <span class="list-actions"> <?php echo CHtml::link(Yii::t('app', 'New List From Selection'), '#', array('id' => 'createList', 'class' => 'list-action')); $listNames = array(); $lists = X2List::model()->findAll(); foreach ($lists as &$list) { if ($editPermissions) { // check permissions $listNames[$list->id] = $list->name; } } unset($list); unset($listNames[$listModel->id]); if ($editPermissions && $listModel->type == 'static') { echo ' | ' . CHtml::link(Yii::t('contacts', 'Remove From List'), '#', array('id' => 'removeFromList', 'class' => 'list-action')); } if (!empty($listNames)) { echo ' | ' . CHtml::link(Yii::t('app', 'Add to list:'), '#', array('id' => 'addToList', 'class' => 'list-action')); echo CHtml::dropDownList('addToListTarget', null, $listNames, array()); }
public function actionRemoveFromList() { if (isset($_POST['gvSelection'], $_POST['listId']) && !empty($_POST['gvSelection']) && is_array($_POST['gvSelection'])) { foreach ($_POST['gvSelection'] as $contactId) { if (!ctype_digit($contactId)) { throw new CHttpException(400, Yii::t('app', 'Invalid selection.')); } } $list = X2List::model()->findByPk($_POST['listId']); // check permissions if (isset($list) && $list->type == 'static' && $this->checkPermissions($list, 'edit')) { X2ListItem::model()->deleteAllByAttributes(array('listId' => $list->id), 'contactId IN (' . implode(',', $_POST['gvSelection']) . ')'); // delete all the things! $list->count = X2ListItem::model()->countByAttributes(array('listId' => $list->id)); $list->save(); } echo 'success'; } }
public function actionUpdateList($id) { $list = X2List::model()->findByPk($id); if (!isset($list)) { throw new CHttpException(400, Yii::t('app', 'This list cannot be found.')); } if (!$this->checkPermissions($list, 'edit')) { throw new CHttpException(403, Yii::t('app', 'You do not have permission to modify this list.')); } $contactModel = new Contacts(); $comparisonList = X2List::getComparisonList(); $fields = $contactModel->getFields(true); if ($list->type == 'dynamic') { $criteriaModels = X2ListCriterion::model()->findAllByAttributes(array('listId' => $list->id), new CDbCriteria(array('order' => 'id ASC'))); if (isset($_POST['X2List'], $_POST['X2List']['attribute'], $_POST['X2List']['comparison'], $_POST['X2List']['value'])) { $attributes =& $_POST['X2List']['attribute']; $comparisons =& $_POST['X2List']['comparison']; $values =& $_POST['X2List']['value']; if (count($attributes) > 0 && count($attributes) == count($comparisons) && count($comparisons) == count($values)) { $list->attributes = $_POST['X2List']; $list->modelName = 'Contacts'; $list->lastUpdated = time(); if ($list->save()) { $this->redirect(array('/contacts/contacts/list', 'id' => $list->id)); } } } } else { //static or campaign lists if (isset($_POST['X2List'])) { $list->attributes = $_POST['X2List']; $list->modelName = 'Contacts'; $list->lastUpdated = time(); $list->save(); $this->redirect(array('/contacts/contacts/list', 'id' => $list->id)); } } if (empty($criteriaModels)) { $default = new X2ListCriterion(); $default->value = ''; $default->attribute = ''; $default->comparison = 'contains'; $criteriaModels[] = $default; } else { if ($list->type = 'dynamic') { foreach ($criteriaModels as $criM) { if (isset($fields[$criM->attribute])) { if ($fields[$criM->attribute]->type == 'link') { $criM->value = implode(',', array_map(function ($c) { list($name, $id) = Fields::nameAndId($c); return $name; }, explode(',', $criM->value))); } } } } } $this->render('updateList', array('model' => $list, 'criteriaModels' => $criteriaModels, 'users' => User::getNames(), 'comparisonList' => $comparisonList, 'listTypes' => array('dynamic' => Yii::t('contacts', 'Dynamic'), 'static' => Yii::t('contacts', 'Static')), 'itemModel' => $contactModel)); }
/** * Export records from a model */ public function actionExportModels($listId = null) { unset($_SESSION['modelExportFile'], $_SESSION['exportModelCriteria'], $_SESSION['modelExportMeta'], $_SESSION['exportModelListId']); $modelList = Modules::getExportableModules(); // Determine the model selected by the user if (isset($_GET['model']) || isset($_POST['model'])) { $model = isset($_GET['model']) ? $_GET['model'] : $_POST['model']; $modelName = str_replace(' ', '', $model); } if (isset($model) && in_array($modelName, array_keys($modelList))) { $staticModel = X2Model::model($modelName); $modulePath = '/' . $staticModel->module; $modulePath .= $modulePath; if (is_null($listId) || $model != 'Contacts') { $file = "records_export.csv"; $listName = CHtml::link(Yii::t('admin', 'All {model}', array('{model}' => $model)), array($modulePath . '/index'), array('style' => 'text-decoration:none;')); // Forcefully disable eager loading so it doesn't go super-slow) $_SESSION['exportModelCriteria'] = new CDbCriteria(); $_SESSION['exportModelCriteria']->with = array(); } else { $list = X2List::load($listId); $_SESSION['exportModelListId'] = $listId; $_SESSION['exportModelCriteria'] = $list->queryCriteria(); $file = "list" . $listId . ".csv"; $listName = CHtml::link(Yii::t('admin', 'List') . " {$listId}: " . $list->name, array($modulePath . '/list', 'id' => $listId), array('style' => 'text-decoration:none;')); } $_SESSION['modelExportFile'] = $file; } else { // If an invalid model was chosen, unset it so that the model list // will be displayed instead. if (isset($model)) { unset($model); } } $viewParam = array('modelList' => $modelList, 'listId' => $listId, 'model' => ''); if (isset($model)) { $viewParam['model'] = $model; if ($model == 'Contacts') { $viewParam['listName'] = $listName; } } $this->render('exportModels', $viewParam); }
public function actionLaunch($id) { $messages = ''; $status = ''; $errors = array(); $campaign = $this->loadModel($id); if (!isset($campaign)) { throw new CHttpException(404, 'The requested page does not exist.'); } if (!ctype_digit($campaign->listId)) { $errors[] = Yii::t('app', 'This campaign has no target contact list.'); $this->render('view', array('model' => $campaign, 'errors' => $errors)); } $list = X2List::model()->findByPk($campaign->listId); //already launched if ($campaign->launched) { $errors[] = Yii::t('app', 'This campaign has already been launched.'); $this->render('view', array('model' => $campaign, 'errors' => $errors, 'contactList' => $list)); return; } if (CActiveRecord::model($list->modelName)->count($list->dbCriteria()) < 1) { $errors[] = Yii::t('app', 'The contacts list is empty.'); $this->render('view', array('model' => $campaign, 'errors' => $errors)); return; } if (empty($campaign->subject)) { $errors[] = Yii::t('app', 'The subject is empty.'); $this->render('view', array('model' => $campaign, 'errors' => $errors)); return; } //Campaign is launching, a point of no return //After launching, the campaign becomes read only //Duplicate the list for campaign tracking, leave original untouched $campaignList = $list->staticDuplicate(); $campaignList->type = 'campaign'; //give each item a uniqueId for tracking $campaignList->save(); $campaign->listId = $campaignList->id; //TODO: modify to support future launching $campaign->launched = 1; $campaign->launchDate = time(); $campaign->save(); $this->render('view', array('model' => $campaign, 'errors' => $errors, 'contactList' => $campaignList)); }