本文整理汇总了PHP中Actions::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Actions::save方法的具体用法?PHP Actions::save怎么用?PHP Actions::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Actions
的用法示例。
在下文中一共展示了Actions::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionUpdate
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
$users = User::getNames();
$fields = Fields::model()->findAllByAttributes(array('modelName' => 'Product'));
foreach ($fields as $field) {
if ($field->type == 'link') {
$fieldName = $field->fieldName;
$type = ucfirst($field->linkType);
if (is_numeric($model->{$fieldName}) && $model->{$fieldName} != 0) {
eval("\$lookupModel={$type}::model()->findByPk(" . $model->{$fieldName} . ");");
if (isset($lookupModel)) {
$model->{$fieldName} = $lookupModel->name;
}
}
}
}
if (isset($_POST['Product'])) {
$temp = $model->attributes;
$model->setX2Fields($_POST['Product']);
// generate history
$action = new Actions();
$action->associationType = 'product';
$action->associationId = $model->id;
$action->associationName = $model->name;
$action->assignedTo = Yii::app()->user->getName();
$action->completedBy = Yii::app()->user->getName();
$action->dueDate = time();
$action->completeDate = time();
$action->visibility = 1;
$action->complete = 'Yes';
$action->actionDescription = "Update: {$model->name}\n Type: {$model->type}\n Price: {$model->price}\n Currency: {$model->currency}\n Inventory: {$model->inventory}";
$action->save();
parent::update($model, $temp, '0');
}
$this->render('update', array('model' => $model, 'users' => $users));
}
示例2: associateAction
/**
* Add note to model
* @param X2Model $model model to which note should be added
* @param string $note
*/
public static function associateAction(X2Model $model, array $attributes)
{
$now = time();
$action = new Actions();
$action->setAttributes(array_merge(array('assignedTo' => $model->assignedTo, 'visibility' => '1', 'associationType' => X2Model::getAssociationType(get_class($model)), 'associationId' => $model->id, 'associationName' => $model->name, 'createDate' => $now, 'lastUpdated' => $now, 'completeDate' => $now, 'complete' => 'Yes', 'updatedBy' => 'admin'), $attributes), false);
return $action->save();
}
示例3: execute
public function execute(&$params)
{
$model = new Actions();
$model->type = 'note';
$model->complete = 'Yes';
$model->associationId = $params['model']->id;
$model->associationType = $params['model']->module;
$model->actionDescription = $this->parseOption('comment', $params);
$model->assignedTo = $this->parseOption('assignedTo', $params);
$model->completedBy = $this->parseOption('assignedTo', $params);
if (empty($model->assignedTo) && $params['model']->hasAttribute('assignedTo')) {
$model->assignedTo = $params['model']->assignedTo;
$model->completedBy = $params['model']->assignedTo;
}
if ($params['model']->hasAttribute('visibility')) {
$model->visibility = $params['model']->visibility;
}
$model->createDate = time();
$model->completeDate = time();
if ($model->save()) {
return array(true, Yii::t('studio', 'View created action: ') . $model->getLink());
} else {
$errors = $model->getErrors();
return array(false, array_shift($errors));
}
}
示例4: testMergeActions
public function testMergeActions()
{
$contact = $this->contact('testAnyone');
$action = new Actions();
$action->actionDescription = "TEST";
$action->visibility = 1;
$action->associationType = "contacts";
$action->associationId = $contact->id;
$action->save();
$model = new Contacts();
foreach ($contact->attributes as $key => $val) {
if ($key != 'id' && $key != 'nameId') {
$model->{$key} = $val;
}
}
$model->save();
$this->assertEquals(0, Yii::app()->db->createCommand()->select('COUNT(*)')->from('x2_actions')->where('associationType = "contacts" AND associationId = :id', array(':id' => $model->id))->queryScalar());
$this->assertEquals(1, Yii::app()->db->createCommand()->select('COUNT(*)')->from('x2_actions')->where('associationType = "contacts" AND associationId = :id', array(':id' => $contact->id))->queryScalar());
$mergeData = $model->mergeActions($contact, true);
$this->assertEquals(1, Yii::app()->db->createCommand()->select('COUNT(*)')->from('x2_actions')->where('associationType = "contacts" AND associationId = :id', array(':id' => $model->id))->queryScalar());
$this->assertEquals(0, Yii::app()->db->createCommand()->select('COUNT(*)')->from('x2_actions')->where('associationType = "contacts" AND associationId = :id', array(':id' => $contact->id))->queryScalar());
$model->unmergeActions($contact->id, $mergeData);
$this->assertEquals(1, Yii::app()->db->createCommand()->select('COUNT(*)')->from('x2_actions')->where('associationType = "contacts" AND associationId = :id', array(':id' => $contact->id))->queryScalar());
$this->assertEquals(0, Yii::app()->db->createCommand()->select('COUNT(*)')->from('x2_actions')->where('associationType = "contacts" AND associationId = :id', array(':id' => $model->id))->queryScalar());
}
示例5: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Actions();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Actions'])) {
$model->attributes = $_POST['Actions'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例6: execute
public function execute(&$params)
{
$options = $this->config['options'];
$action = new Actions();
$action->subject = $this->parseOption('subject', $params);
$action->dueDate = $this->parseOption('dueDate', $params);
$action->actionDescription = $this->parseOption('description', $params);
$action->priority = $this->parseOption('priority', $params);
$action->visibility = $this->parseOption('visibility', $params);
if (isset($params['model'])) {
$action->assignedTo = $this->parseOption('assignedTo', $params);
}
// if(isset($this->config['attributes']))
// $this->setModelAttributes($action,$this->config['attributes'],$params);
if ($action->save()) {
return array(true, Yii::t('studio', "View created action: ") . $action->getLink());
} else {
$errors = $action->getErrors();
return array(false, array_shift($errors));
}
// if($this->parseOption('reminder',$params)) {
// $notif=new Notification;
// $notif->modelType='Actions';
// $notif->createdBy=Yii::app()->user->getName();
// $notif->modelId=$model->id;
// if($_POST['notificationUsers']=='me'){
// $notif->user=Yii::app()->user->getName();
// }else{
// $notif->user=$model->assignedTo;
// }
// $notif->createDate=$model->dueDate-($_POST['notificationTime']*60);
// $notif->type='action_reminder';
// $notif->save();
// if($_POST['notificationUsers']=='both' && Yii::app()->user->getName()!=$model->assignedTo){
// $notif2=new Notification;
// $notif2->modelType='Actions';
// $notif2->createdBy=Yii::app()->user->getName();
// $notif2->modelId=$model->id;
// $notif2->user=Yii::app()->user->getName();
// $notif2->createDate=$model->dueDate-($_POST['notificationTime']*60);
// $notif2->type='action_reminder';
// $notif2->save();
// }
// }
}
示例7: execute
public function execute(&$params)
{
$action = new Actions();
$action->associationType = lcfirst(get_class($params['model']));
$action->associationId = $params['model']->id;
$action->subject = $this->parseOption('subject', $params);
$action->actionDescription = $this->parseOption('description', $params);
if ($params['model']->hasAttribute('assignedTo')) {
$action->assignedTo = $params['model']->assignedTo;
}
if ($params['model']->hasAttribute('priority')) {
$action->priority = $params['model']->priority;
}
if ($params['model']->hasAttribute('visibility')) {
$action->visibility = $params['model']->visibility;
}
if ($action->save()) {
return array(true, Yii::t('studio', "View created action: ") . $action->getLink());
} else {
return array(false, array_shift($action->getErrors()));
}
}
示例8: testQuoteEmailOpen
public function testQuoteEmailOpen()
{
$quote = $this->quote('docsTest');
$this->assertNullEmailOpenAction($quote);
$quoteInitialActionCount = Yii::app()->db->createCommand()->select('COUNT(*)')->from('x2_actions')->where('associationType = :type AND associationId = :id', array(':type' => $quote->module, ':id' => $quote->id))->queryScalar();
$action = new Actions();
$action->completedBy = 'admin';
$action->createDate = time();
$action->dueDate = time();
$action->subject = 'Test Subject';
$action->completeDate = time();
$action->complete = 'Yes';
$action->actionDescription = 'Test Body';
// These attributes are context-sensitive and subject to change:
$action->associationId = $quote->id;
$action->associationType = $quote->module;
$action->type = 'email';
$action->visibility = 1;
$action->assignedTo = 'admin';
$action->save();
$track = new TrackEmail();
$track->actionId = $action->id;
$track->uniqueId = md5(uniqid(rand(), true));
$this->assertSaves($track);
$this->assertEquals($quoteInitialActionCount + 1, Yii::app()->db->createCommand()->select('COUNT(*)')->from('x2_actions')->where('associationType = :type AND associationId = :id', array(':type' => $quote->module, ':id' => $quote->id))->queryScalar());
$track->recordEmailOpen();
$this->assertEquals($quoteInitialActionCount + 2, Yii::app()->db->createCommand()->select('COUNT(*)')->from('x2_actions')->where('associationType = :type AND associationId = :id', array(':type' => $quote->module, ':id' => $quote->id))->queryScalar());
$this->assertEmailOpenAction($quote);
}
示例9: beforeDelete
/**
* Clear out records associated with this quote before deletion.
*/
public function beforeDelete()
{
QuoteProduct::model()->deleteAllByAttributes(array('quoteId' => $this->id));
// for old relationships generated with incorrect type name
Relationships::model()->deleteAllByAttributes(array('firstType' => 'quotes', 'firstId' => $this->id));
// generate action record for history
$contact = $this->contact;
if (!empty($contact)) {
$action = new Actions();
$action->associationType = 'contacts';
$action->type = 'quotesDeleted';
$action->associationId = $contact->id;
$action->associationName = $contact->name;
$action->assignedTo = Yii::app()->getSuModel()->username;
$action->completedBy = Yii::app()->getSuModel()->username;
$action->createDate = time();
$action->dueDate = time();
$action->completeDate = time();
$action->visibility = 1;
$action->complete = 'Yes';
$action->actionDescription = "Deleted Quote: <span style=\"font-weight:bold;\">{$this->id}</span> {$this->name}";
// Save after deletion of the model so that this action itself doensn't get deleted
$action->save();
}
return parent::beforeDelete();
}
示例10: actionClick
/**
* Track when an email is viewed, a link is clicked, or the recipient unsubscribes
*
* Campaign emails include an img tag to a blank image to track when the message was opened,
* an unsubscribe link, and converted links to track when a recipient clicks a link.
* All those links are handled by this action.
*
* @param integer $uid The unique id of the recipient
* @param string $type 'open', 'click', or 'unsub'
* @param string $url For click types, this is the urlencoded URL to redirect to
* @param string $email For unsub types, this is the urlencoded email address
* of the person unsubscribing
*/
public function actionClick($uid, $type, $url = null, $email = null)
{
$now = time();
$item = CActiveRecord::model('X2ListItem')->with('contact', 'list')->findByAttributes(array('uniqueId' => $uid));
// It should never happen that we have a list item without a campaign,
// but it WILL happen on any old db where x2_list_items does not cascade on delete
// we can't track anything if the listitem was deleted, but at least prevent breaking links
if ($item === null || $item->list->campaign === null) {
if ($type == 'click') {
// campaign redirect link click
$this->redirect(urldecode($url));
} elseif ($type == 'open') {
//return a one pixel transparent gif
header('Content-Type: image/gif');
echo base64_decode('R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
} elseif ($type == 'unsub' && !empty($email)) {
Contacts::model()->updateAll(array('doNotEmail' => true), 'email=:email', array(':email' => $email));
X2ListItem::model()->updateAll(array('unsubscribed' => time()), 'emailAddress=:email AND unsubscribed=0', array('email' => $email));
$message = Yii::t('marketing', 'You have been unsubscribed');
echo '<html><head><title>' . $message . '</title></head><body>' . $message . '</body></html>';
}
return;
}
$contact = $item->contact;
$list = $item->list;
$event = new Events();
$notif = new Notification();
$action = new Actions();
$action->completeDate = $now;
$action->complete = 'Yes';
$action->updatedBy = 'API';
$skipActionEvent = true;
if ($contact !== null) {
$skipActionEvent = false;
if ($email === null) {
$email = $contact->email;
}
$action->associationType = 'contacts';
$action->associationId = $contact->id;
$action->associationName = $contact->name;
$action->visibility = $contact->visibility;
$action->assignedTo = $contact->assignedTo;
$event->associationId = $action->associationId;
$event->associationType = 'Contacts';
if ($action->assignedTo !== '' && $action->assignedTo !== 'Anyone') {
$notif->user = $contact->assignedTo;
$notif->modelType = 'Contacts';
$notif->modelId = $contact->id;
$notif->createDate = $now;
$notif->value = $item->list->campaign->getLink();
}
} elseif ($list !== null) {
$action = new Actions();
$action->type = 'note';
$action->createDate = $now;
$action->lastUpdated = $now;
$action->completeDate = $now;
$action->complete = 'Yes';
$action->updatedBy = 'admin';
$action->associationType = 'X2List';
$action->associationId = $list->id;
$action->associationName = $list->name;
$action->visibility = $list->visibility;
$action->assignedTo = $list->assignedTo;
}
if ($type == 'unsub') {
$item->unsubscribe();
// find any weblists associated with the email address and create unsubscribe actions
// for each of them
$sql = 'SELECT t.*
FROM x2_lists as t
JOIN x2_list_items as li ON t.id=li.listId
WHERE li.emailAddress=:email AND t.type="weblist";';
$weblists = Yii::app()->db->createCommand($sql)->queryAll(true, array('email' => $email));
foreach ($weblists as $weblist) {
$weblistAction = new Actions();
$weblistAction->disableBehavior('changelog');
//$weblistAction->id = 0; // this causes primary key contraint violation errors
$weblistAction->isNewRecord = true;
$weblistAction->type = 'email_unsubscribed';
$weblistAction->associationType = 'X2List';
$weblistAction->associationId = $weblist['id'];
$weblistAction->associationName = $weblist['name'];
$weblistAction->visibility = $weblist['visibility'];
$weblistAction->assignedTo = $weblist['assignedTo'];
$weblistAction->actionDescription = Yii::t('marketing', 'Campaign') . ': ' . $item->list->campaign->name . "\n\n" . $email . " " . Yii::t('marketing', 'has unsubscribed') . ".";
$weblistAction->save();
//.........这里部分代码省略.........
示例11: actionUpdate
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model = $this->loadModel($id);
$users = User::getNames();
$fields = Fields::model()->findAllByAttributes(array('modelName' => "Products"));
foreach ($fields as $field) {
if ($field->type == 'link') {
$fieldName = $field->fieldName;
$type = ucfirst($field->linkType);
if (is_numeric($model->{$fieldName}) && $model->{$fieldName} != 0) {
eval("\$lookupModel={$type}::model()->findByPk(" . $model->{$fieldName} . ");");
if (isset($lookupModel)) {
$model->{$fieldName} = $lookupModel->name;
}
}
}
}
if (isset($_POST['Product'])) {
$temp = $model->attributes;
foreach ($_POST['Product'] as $name => $value) {
if ($value == $model->getAttributeLabel($name)) {
$_POST['Product'][$name] = '';
}
}
foreach ($_POST as $key => $arr) {
$pieces = explode("_", $key);
if (isset($pieces[0]) && $pieces[0] == 'autoselect') {
$newKey = $pieces[1];
if (isset($_POST[$newKey . "_id"]) && $_POST[$newKey . "_id"] != "") {
$val = $_POST[$newKey . "_id"];
} else {
$field = Fields::model()->findByAttributes(array('fieldName' => $newKey));
if (isset($field)) {
$type = ucfirst($field->linkType);
if ($type != "Contacts") {
eval("\$lookupModel={$type}::model()->findByAttributes(array('name'=>'{$arr}'));");
} else {
$names = explode(" ", $arr);
$lookupModel = Contacts::model()->findByAttributes(array('firstName' => $names[0], 'lastName' => $names[1]));
}
if (isset($lookupModel)) {
$val = $lookupModel->id;
} else {
$val = $arr;
}
}
}
$model->{$newKey} = $val;
}
}
foreach (array_keys($model->attributes) as $field) {
if (isset($_POST['Product'][$field])) {
$model->{$field} = $_POST['Product'][$field];
$fieldData = Fields::model()->findByAttributes(array('modelName' => 'Products', 'fieldName' => $field));
if ($fieldData->type == 'assignment' && $fieldData->linkType == 'multiple') {
$model->{$field} = Accounts::parseUsers($model->{$field});
} elseif ($fieldData->type == 'date') {
$model->{$field} = strtotime($model->{$field});
}
}
}
// generate history
$action = new Actions();
$action->associationType = 'product';
$action->associationId = $model->id;
$action->associationName = $model->name;
$action->assignedTo = Yii::app()->user->getName();
$action->completedBy = Yii::app()->user->getName();
$action->dueDate = time();
$action->completeDate = time();
$action->visibility = 1;
$action->complete = 'Yes';
$action->actionDescription = "Update: <b>{$model->name}</b>\n\t\t\t\tType: <b>{$model->type}</b>\n\t\t\t\tPrice: <b>{$model->price}</b>\n\t\t\t\tCurrency: <b>{$model->currency}</b>\n\t\t\t\tInventory: <b>{$model->inventory}</b>";
$action->save();
parent::update($model, $temp, '0');
}
$this->render('update', array('model' => $model, 'users' => $users));
}
示例12: actionCompleteStage
public function actionCompleteStage($workflowId, $stageNumber, $modelId, $type, $comment = '')
{
if (!(is_numeric($workflowId) && is_numeric($stageNumber) && is_numeric($modelId) && ctype_alpha($type))) {
return;
}
$comment = trim($comment);
$workflowStatus = Workflow::getWorkflowStatus($workflowId, $modelId, $type);
$stageCount = count($workflowStatus) - 1;
$stage =& $workflowStatus[$stageNumber];
if (isset($stage['createDate']) && empty($stage['completeDate'])) {
$previousCheck = true;
if ($workflowStatus[$stageNumber]['requirePrevious'] == 1) {
// check if all stages before this one are complete
for ($i = 1; $i < $stageNumber; $i++) {
if (empty($workflowStatus[$i]['complete'])) {
$previousCheck = false;
break;
}
}
} else {
if ($workflowStatus[$stageNumber]['requirePrevious'] < 0) {
// or just check if the specified stage is complete
if (empty($workflowStatus[-1 * $workflowStatus[$stageNumber]['requirePrevious']]['complete'])) {
$previousCheck = false;
}
}
}
// is this stage is OK to complete? if a comment is required, then is $comment empty?
if ($previousCheck && (!$stage['requireComment'] || $stage['requireComment'] && !empty($comment))) {
// find selected stage (and duplicates)
$actionModels = CActiveRecord::model('Actions')->findAllByAttributes(array('associationId' => $modelId, 'associationType' => $type, 'type' => 'workflow', 'workflowId' => $workflowId, 'stageNumber' => $stageNumber), new CDbCriteria(array('order' => 'createDate DESC')));
if (count($actionModels) > 1) {
// if there is more than 1 action for this stage,
for ($i = 1; $i < count($actionModels); $i++) {
// delete all but the most recent one
$actionModels[$i]->delete();
}
}
$actionModels[0]->setScenario('workflow');
$actionModels[0]->completeDate = time();
// set completeDate and save model
$actionModels[0]->complete = 'Yes';
$actionModels[0]->completedBy = Yii::app()->user->getName();
// $actionModels[0]->actionDescription = $workflowId.':'.$stageNumber.$comment;
$actionModels[0]->actionDescription = $comment;
$actionModels[0]->save();
$this->updateWorkflowChangelog($actionModels[0], 'complete');
for ($i = 0; $i <= $stageCount; $i++) {
if ($i != $stageNumber && empty($workflowStatus[$i]['completeDate']) && !empty($workflowStatus[$i]['createDate'])) {
break;
}
if (empty($workflowStatus[$i]['createDate'])) {
$nextAction = new Actions('workflow');
// start the next one (unless there is already one)
$nextAction->associationId = $modelId;
$nextAction->associationType = $type;
$nextAction->assignedTo = Yii::app()->user->getName();
$nextAction->type = 'workflow';
$nextAction->complete = 'No';
$nextAction->visibility = 1;
$nextAction->createDate = time();
$nextAction->workflowId = $workflowId;
$nextAction->stageNumber = $i;
// $nextAction->actionDescription = $comment;
$nextAction->save();
$this->updateWorkflowChangelog($nextAction, 'start');
// $changes=$this->calculateChanges($oldAttributes, $model->attributes, $model);
// $this->updateChangelog($model,$changes);
break;
}
}
// if($stageNumber < $stageCount && empty($workflowStatus[$stageNumber+1]['createDate'])) { // if this isn't the final stage,
// }
$workflowStatus = Workflow::getWorkflowStatus($workflowId, $modelId, $type);
// refresh the workflow status
}
}
echo Workflow::renderWorkflow($workflowStatus);
}
示例13: testMigration
public function testMigration()
{
$model = $this->contacts('contact935');
$workflowActions = Actions::model()->findAllByAttributes(array('associationType' => 'contacts', 'associationId' => $model->id, 'type' => 'workflow'));
$this->assertEquals(4, count($workflowActions));
$stage1 = $this->workflowStages('stage1');
$stage1Action = Actions::model()->findByAttributes(array('associationType' => 'contacts', 'associationId' => $model->id, 'type' => 'workflow', 'workflowId' => 2, 'stageNumber' => 1));
$this->assertInstanceOf('Actions', $stage1Action);
$this->assertEquals($stage1->workflowId, $stage1Action->workflowId);
$this->assertEquals($stage1->stageNumber, $stage1Action->stageNumber);
//Confirm that saving an action with non-existent stageNumber is okay
$badAction = new Actions();
$badAction->type = 'workflow';
$badAction->workflowId = 2;
$badAction->stageNumber = -1;
$badAction->associationType = 'contacts';
$badAction->associationId = $model->id;
$this->assertSaves($badAction);
//Confirm that saving an action with non-existent workflowId is okay
$badAction->stageNumber = 1;
$badAction->workflowId = -1;
$this->assertSaves($badAction);
//Confirm that saving an action with non-existent workflowId and stageNumber is okay
$badAction->stageNumber = -1;
$this->assertSaves($badAction);
//Confirm that saving duplicate workflow stages is okay
$badAction2 = new Actions();
$badAction2->type = 'workflow';
$badAction2->workflowId = -1;
$badAction2->stageNumber = -1;
$badAction2->associationType = 'contacts';
$badAction2->associationId = $model->id;
$this->assertSaves($badAction2);
//Non-duplicate action to confirm deletion of actions with bad workflowId
$badAction3 = new Actions();
$badAction3->type = 'workflow';
$badAction3->workflowId = -99;
$badAction3->stageNumber = 1;
$badAction3->associationType = 'contacts';
$badAction3->associationId = $model->id;
$this->assertSaves($badAction3);
//Non-duplicate action to confirm deletion of actions with bad stageNumber
$badAction4 = new Actions();
$badAction4->type = 'workflow';
$badAction4->workflowId = 2;
$badAction4->stageNumber = -99;
$badAction4->associationType = 'contacts';
$badAction4->associationId = $model->id;
$this->assertSaves($badAction4);
$workflowActions = Actions::model()->findAllByAttributes(array('associationType' => 'contacts', 'associationId' => $model->id, 'type' => 'workflow'));
$this->assertEquals(8, count($workflowActions));
$this->runMigrationScript();
$workflowActions = Actions::model()->findAllByAttributes(array('associationType' => 'contacts', 'associationId' => $model->id, 'type' => 'workflow'));
$this->assertEquals(4, count($workflowActions));
$this->assertNull(Actions::model()->findByPk($badAction->id));
$this->assertNull(Actions::model()->findByPk($badAction2->id));
$this->assertNull(Actions::model()->findByPk($badAction3->id));
$this->assertNull(Actions::model()->findByPk($badAction4->id));
$stage1ActionPostMigrate = Actions::model()->findByPK($stage1Action->id);
$this->assertEquals($stage1->workflowId, $stage1ActionPostMigrate->workflowId);
$this->assertEquals($stage1->id, $stage1ActionPostMigrate->stageNumber);
//Fails new foreign key constraint
$badAction5 = new Actions();
$badAction5->type = 'workflow';
$badAction5->workflowId = 2;
$badAction5->stageNumber = -1;
$badAction5->associationType = 'contacts';
$badAction5->associationId = $model->id;
try {
$badAction5->save();
$this->assertFalse(true);
} catch (CDbException $e) {
$this->assertTrue(true);
}
//Fails new unique constraint
$badAction6 = new Actions();
$badAction6->type = 'workflow';
$badAction6->workflowId = 2;
$badAction6->stageNumber = 5;
$badAction6->associationType = 'contacts';
$badAction6->associationId = $model->id;
try {
$badAction6->save();
$this->assertFalse(true);
} catch (CDbException $e) {
$this->assertTrue(true);
}
}
示例14: run
public function run()
{
$preview = false;
$emailBody = '';
$signature = '';
$template = null;
if (!isset($this->model)) {
$this->model = new InlineEmail();
}
if (isset($_POST['InlineEmail'])) {
if (isset($_GET['preview']) || isset($_POST['InlineEmail']['submit']) && $_POST['InlineEmail']['submit'] == Yii::t('app', 'Preview')) {
$preview = true;
}
$this->model->attributes = $_POST['InlineEmail'];
// if the user specified a template, look it up and use it for the message
if ($this->model->template != 0) {
$matches = array();
if (preg_match('/<!--BeginSig-->(.*)<!--EndSig-->/u', $this->model->message, $matches) && count($matches) > 1) {
// extract signature
$signature = $matches[1];
}
$this->model->message = preg_replace('/<!--BeginSig-->(.*)<!--EndSig-->/u', '', $this->model->message);
// remove signatures
$matches = array();
if (preg_match('/<!--BeginMsg-->(.*)<!--EndMsg-->/u', $this->model->message, $matches) && count($matches) > 1) {
$this->model->message = $matches[1];
}
if (empty($signature)) {
$signature = Yii::app()->params->profile->getSignature(true);
}
// load default signature if empty
$template = CActiveRecord::model('Docs')->findByPk($this->model->template);
if (isset($template)) {
$this->model->message = str_replace('\\\\', '\\\\\\', $this->model->message);
$this->model->message = str_replace('$', '\\$', $this->model->message);
$emailBody = preg_replace('/{content}/u', '<!--BeginMsg-->' . $this->model->message . '<!--EndMsg-->', $template->text);
$emailBody = preg_replace('/{signature}/u', '<!--BeginSig-->' . $signature . '<!--EndSig-->', $emailBody);
// check if subject is empty, or is from another template
if (empty($this->model->subject) || CActiveRecord::model('Docs')->countByAttributes(array('type' => 'email', 'title' => $this->model->subject))) {
$this->model->subject = $template->title;
}
if (isset($this->model->modelName, $this->model->modelId)) {
// if there is a model name/id available, look it up and use its attributes
$targetModel = CActiveRecord::model($this->model->modelName)->findByPk($this->model->modelId);
if (isset($targetModel)) {
$attributes = $targetModel->getAttributes();
$attributeNames = array_keys($attributes);
$attributeNames[] = 'content';
$attributes = array_values($attributes);
$attributes[] = $this->model->message;
foreach ($attributeNames as &$name) {
$name = '/{' . $name . '}/';
}
unset($name);
$emailBody = preg_replace($attributeNames, $attributes, $emailBody);
}
}
// $this->model->template = 0;
$this->model->message = $emailBody;
}
} elseif (!empty($this->model->message)) {
// if no template, use the user's custom message, and include a signature
$emailBody = $this->model->message;
// } elseif(!empty($this->model->message)) { // if no template, use the user's custom message, and include a signature
// $emailBody = $this->model->message.'<br><br>'.Yii::app()->params->profile->getSignature(true);
}
if ($this->model->template == 0) {
$this->model->setScenario('custom');
}
if ($this->model->validate() && !$preview) {
$this->model->status = $this->controller->sendUserEmail($this->model->mailingList, $this->model->subject, $emailBody);
if (in_array('200', $this->model->status)) {
foreach ($this->model->mailingList['to'] as &$target) {
$contact = Contacts::model()->findByAttributes(array('email' => $target[1]));
if (isset($contact)) {
$action = new Actions();
$action->associationType = 'contacts';
$action->associationId = $contact->id;
$action->associationName = $contact->name;
$action->visibility = $contact->visibility;
$action->complete = 'Yes';
$action->type = 'email';
$action->completedBy = Yii::app()->user->getName();
$action->assignedTo = $contact->assignedTo;
$action->createDate = time();
$action->dueDate = time();
$action->completeDate = time();
if ($template == null) {
$action->actionDescription = '<b>' . $this->model->subject . "</b>\n\n" . $this->model->message;
} else {
$action->actionDescription = CHtml::link($template->title, array('/docs/' . $template->id));
}
if ($action->save()) {
}
// $message="2";
// $email=$toEmail;
// $id=$contact['id'];
// $note.="\n\nSent to Contact";
}
}
//.........这里部分代码省略.........
示例15: createAttachmentAction
private function createAttachmentAction($model)
{
if (!empty($model->associationType) && !empty($model->associationId) && is_numeric($model->associationId)) {
$note = new Actions();
$note->createDate = time();
$note->dueDate = time();
$note->completeDate = time();
$note->complete = 'Yes';
$note->visibility = '1';
$note->completedBy = Yii::app()->user->getName();
if ($model->private) {
$note->assignedTo = Yii::app()->user->getName();
$note->visibility = '0';
} else {
$note->assignedTo = 'Anyone';
}
$note->type = 'attachment';
$note->associationId = $model->associationId;
$note->associationType = $model->associationType;
if ($modelName = X2Model::getModelName($model->associationType)) {
$association = X2Model::model($modelName)->findByPk($model->associationId);
if ($association != null) {
$note->associationName = $association->name;
}
}
$note->actionDescription = $model->fileName . ':' . $model->id;
return $note->save();
}
return false;
}