/** * 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); } } }
/** * 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); }
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)); }
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(); } }
/** * 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); }
/** * 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 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)); }