本文整理汇总了PHP中X2Model::afterUpdate方法的典型用法代码示例。如果您正苦于以下问题:PHP X2Model::afterUpdate方法的具体用法?PHP X2Model::afterUpdate怎么用?PHP X2Model::afterUpdate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类X2Model
的用法示例。
在下文中一共展示了X2Model::afterUpdate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterUpdate
/**
* Responds when {@link X2Model::afterUpdate()} is called (record saved, but
* not a new record). Sends a notification to anyone subscribed to this contact.
*
* Before executing this, the model must check whether the contact has the
* "changelog" behavior. That is because the behavior is disabled
* when checking for duplicates in {@link ContactsController}
*/
public function afterUpdate()
{
if (!Yii::app()->params->noSession && $this->asa('changelog') && $this->asa('changelog')->enabled) {
//$this->scenario != 'noChangelog') {
// send subscribe emails if anyone has subscribed to this contact
$result = Yii::app()->db->createCommand()->select('user_id')->from('x2_subscribe_contacts')->where('contact_id=:id', array(':id' => $this->id))->queryColumn();
$datetime = Formatter::formatLongDateTime(time());
$modelLink = CHtml::link($this->name, Yii::app()->controller->createAbsoluteUrl('/contacts/' . $this->id));
$subject = 'X2Engine: ' . $this->name . ' updated';
$message = "Hello,<br>\n<br>\n";
$message .= 'You are receiving this email because you are subscribed to changes made to the contact ' . $modelLink . ' in X2Engine. ';
$message .= 'The following changes were made on ' . $datetime . ":<br>\n<br>\n";
foreach ($this->getChanges() as $attribute => $change) {
if ($attribute != 'lastActivity') {
$old = $change[0] == '' ? '-----' : $change[0];
$new = $change[1] == '' ? '-----' : $change[1];
$label = $this->getAttributeLabel($attribute);
$message .= "{$label}: {$old} => {$new}<br>\n";
}
}
$message .= "<br>\nYou can unsubscribe to these messages by going to {$modelLink} and clicking Unsubscribe.<br>\n<br>\n";
$adminProfile = Yii::app()->params->adminProfile;
foreach ($result as $subscription) {
$subscription = array();
if (isset($subscription['user_id'])) {
$profile = X2Model::model('Profile')->findByPk($subscription['user_id']);
if ($profile && $profile->emailAddress && $adminProfile && $adminProfile->emailAddress) {
$to = array('to' => array(array($profile->fullName, $profile->emailAddress)));
Yii::app()->controller->sendUserEmail($to, $subject, $message, null, Credentials::$sysUseId['systemNotificationEmail']);
}
}
}
}
parent::afterUpdate();
}