本文整理汇总了PHP中X2Model::setX2Fields方法的典型用法代码示例。如果您正苦于以下问题:PHP X2Model::setX2Fields方法的具体用法?PHP X2Model::setX2Fields怎么用?PHP X2Model::setX2Fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类X2Model
的用法示例。
在下文中一共展示了X2Model::setX2Fields方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setX2Fields
/**
* Override of {@link X2Model::setX2Fields}
*
* Skips HTML purification for the content so that tracking links will work.
*/
public function setX2Fields(&$data, $filter = false, $bypassPermissions = false)
{
$originalContent = isset($data['content']) ? $data['content'] : null;
parent::setX2Fields($data, $filter, $bypassPermissions);
$this->content = $originalContent;
}
示例2: handleWebleadFormSubmission
private function handleWebleadFormSubmission(X2Model $model, $extractedParams)
{
$newRecord = $model->isNewRecord;
if (isset($_POST['Contacts'])) {
$model->createEvent = false;
$model->setX2Fields($_POST['Contacts'], true);
// Extra sanitizing
$p = Fields::getPurifier();
foreach ($model->attributes as $name => $value) {
if ($name != $model->primaryKey() && !empty($value)) {
$model->{$name} = $p->purify($value);
}
}
$now = time();
//require email field, check format
/*if(preg_match(
"/[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/",
$_POST['Contacts']['email']) == 0) {
$this->renderPartial('application.components.views.webFormSubmit',
array (
'type' => 'weblead',
'error' => Yii::t('contacts', 'Invalid Email Address')
)
);
return;
}*/
if (empty($model->visibility)) {
$model->visibility = 1;
}
$model->validate(null, false);
if (!$model->hasErrors()) {
$duplicates = array();
if (!empty($model->email)) {
//find any existing contacts with the same contact info
$criteria = new CDbCriteria();
$criteria->compare('email', $model->email, false, "OR");
$emailFields = Yii::app()->db->createCommand()->select('fieldName')->from('x2_fields')->where('modelName = "Contacts" AND type = "email"')->queryColumn();
foreach ($emailFields as $field) {
$criteria->compare($field, $model->email, false, "OR");
}
$duplicates = $model->findAll($criteria);
}
if (count($duplicates) > 0) {
//use existing record, update background info
$newBgInfo = $model->backgroundInfo;
$model = $duplicates[0];
$oldBgInfo = $model->backgroundInfo;
if ($newBgInfo !== $oldBgInfo) {
$model->backgroundInfo .= ($oldBgInfo && $newBgInfo ? "\n" : '') . $newBgInfo;
}
$success = $model->save();
} else {
//create new record
$model->assignedTo = $this->controller->getNextAssignee();
$model->visibility = 1;
$model->createDate = $now;
$model->lastUpdated = $now;
$model->updatedBy = 'admin';
$success = $model->save();
//TODO: upload profile picture url from webleadfb
}
if ($success) {
if ($extractedParams['generateLead']) {
self::generateLead($model, $extractedParams['leadSource']);
}
if ($extractedParams['generateAccount']) {
self::generateAccount($model);
}
self::addTags($model);
$tags = !isset($_POST['tags']) || empty($_POST['tags']) ? array() : explode(',', $_POST['tags']);
if ($newRecord) {
X2Flow::trigger('WebleadTrigger', array('model' => $model, 'tags' => $tags));
}
//use the submitted info to create an action
$action = new Actions();
$action->actionDescription = Yii::t('contacts', 'Web Lead') . "\n\n" . Yii::t('contacts', 'Name') . ': ' . CHtml::decode($model->firstName) . " " . CHtml::decode($model->lastName) . "\n" . Yii::t('contacts', 'Email') . ": " . CHtml::decode($model->email) . "\n" . Yii::t('contacts', 'Phone') . ": " . CHtml::decode($model->phone) . "\n" . Yii::t('contacts', 'Background Info') . ": " . CHtml::decode($model->backgroundInfo);
// create action
$action->type = 'note';
$action->assignedTo = $model->assignedTo;
$action->visibility = '1';
$action->associationType = 'contacts';
$action->associationId = $model->id;
$action->associationName = $model->name;
$action->createDate = $now;
$action->lastUpdated = $now;
$action->completeDate = $now;
$action->complete = 'Yes';
$action->updatedBy = 'admin';
$action->save();
// create a notification if the record is assigned to someone
$event = new Events();
$event->associationType = 'Contacts';
$event->associationId = $model->id;
$event->user = $model->assignedTo;
$event->type = 'weblead_create';
$event->save();
if ($model->assignedTo != 'Anyone' && $model->assignedTo != '') {
$notif = new Notification();
$notif->user = $model->assignedTo;
$notif->createdBy = 'API';
//.........这里部分代码省略.........
示例3: setX2Fields
public function setX2Fields(&$data, $filter = false, $bypassPermissions = false)
{
if (isset($data['lineitem'])) {
$this->setActionLineItems($data['lineitem']);
}
return parent::setX2Fields($data, $filter, $bypassPermissions);
}
示例4: handleWebleadFormSubmission
private function handleWebleadFormSubmission(X2Model $model, $extractedParams)
{
$newRecord = $model->isNewRecord;
if (isset($_POST['Contacts'])) {
$model->createEvent = false;
$model->setX2Fields($_POST['Contacts'], true);
// Extra sanitizing
$p = Fields::getPurifier();
foreach ($model->attributes as $name => $value) {
if ($name != $model->primaryKey() && !empty($value)) {
$model->{$name} = $p->purify($value);
}
}
$now = time();
$model->visibility = 1;
$model->validate(null, false);
if (!$model->hasErrors()) {
$model->lastUpdated = $now;
$model->updatedBy = 'admin';
if ($model->asa('X2DuplicateBehavior') && $model->checkForDuplicates()) {
$duplicates = $model->getDuplicates();
$oldest = $duplicates[0];
$fields = $model->getFields(true);
foreach ($fields as $field) {
if (!in_array($field->fieldName, $model->X2MergeableBehavior->restrictedFields) && !is_null($model->{$field->fieldName})) {
if ($field->type === 'text' && !empty($oldest->{$field->fieldName})) {
$oldest->{$field->fieldName} .= "\n--\n" . $model->{$field->fieldName};
} else {
$oldest->{$field->fieldName} = $model->{$field->fieldName};
}
}
}
$model = $oldest;
$newRecord = $model->isNewRecord;
}
if ($newRecord) {
$model->createDate = $now;
$model->assignedTo = $this->controller->getNextAssignee();
}
$success = $model->save();
//TODO: upload profile picture url from webleadfb
if ($success) {
if ($extractedParams['generateLead']) {
self::generateLead($model, $extractedParams['leadSource']);
}
if ($extractedParams['generateAccount']) {
self::generateAccount($model);
}
self::addTags($model);
$tags = !isset($_POST['tags']) || empty($_POST['tags']) ? array() : explode(',', $_POST['tags']);
if ($newRecord) {
X2Flow::trigger('WebleadTrigger', array('model' => $model, 'tags' => $tags));
}
//use the submitted info to create an action
Actions::associateAction($model, array('actionDescription' => Yii::t('contacts', 'Web Lead') . "\n\n" . Yii::t('contacts', 'Name') . ': ' . CHtml::decode($model->firstName) . " " . CHtml::decode($model->lastName) . "\n" . Yii::t('contacts', 'Email') . ": " . CHtml::decode($model->email) . "\n" . Yii::t('contacts', 'Phone') . ": " . CHtml::decode($model->phone) . "\n" . Yii::t('contacts', 'Background Info') . ": " . CHtml::decode($model->backgroundInfo), 'type' => 'note'));
// create a notification if the record is assigned to someone
$event = new Events();
$event->associationType = 'Contacts';
$event->associationId = $model->id;
$event->user = $model->assignedTo;
$event->type = 'weblead_create';
$event->save();
if ($model->assignedTo != 'Anyone' && $model->assignedTo != '') {
$notif = new Notification();
$notif->user = $model->assignedTo;
$notif->createdBy = 'API';
$notif->createDate = time();
$notif->type = 'weblead';
$notif->modelType = 'Contacts';
$notif->modelId = $model->id;
$notif->save();
$profile = Profile::model()->findByAttributes(array('username' => $model->assignedTo));
/* send user that's assigned to this weblead an email if the user's email
address is set and this weblead has a user email template */
if ($profile !== null && !empty($profile->emailAddress)) {
$subject = Yii::t('marketing', 'New Web Lead');
$message = Yii::t('marketing', 'A new web lead has been assigned to you: ') . CHtml::link($model->firstName . ' ' . $model->lastName, array('/contacts/contacts/view', 'id' => $model->id)) . '.';
$address = array('to' => array(array('', $profile->emailAddress)));
$emailFrom = Credentials::model()->getDefaultUserAccount(Credentials::$sysUseId['systemNotificationEmail'], 'email');
if ($emailFrom == Credentials::LEGACY_ID) {
$emailFrom = array('name' => $profile->fullName, 'address' => $profile->emailAddress);
}
$status = $this->controller->sendUserEmail($address, $subject, $message, null, $emailFrom);
}
}
} else {
$errMsg = 'Error: WebListenerAction.php: model failed to save';
/**/
AuxLib::debugLog($errMsg);
Yii::log($errMsg, '', 'application.debug');
}
$this->controller->renderPartial('application.components.views.webFormSubmit', array('type' => 'weblead', 'redirectUrl' => $extractedParams['redirectUrl']));
Yii::app()->end();
// success!
}
}
$sanitizedGetParams = self::sanitizeGetParams();
$this->controller->renderPartial('application.components.views.webForm', array_merge(array('type' => 'weblead'), $sanitizedGetParams));
}