From 4c0f2a8bc54cfe1e979794b99c45678f288aed7d Mon Sep 17 00:00:00 2001 From: Bui Sy Nguyen Date: Mon, 24 Aug 2015 14:14:22 +0700 Subject: [PATCH] Improve ActivityNoticeSerializer and ActivityNoticeManager: support more cases for batch-delete actions --- fproject/amqp/ActivityNoticeManager.php | 28 ++++++++++++++-------- fproject/amqp/ActivityNoticeSerializer.php | 2 ++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/fproject/amqp/ActivityNoticeManager.php b/fproject/amqp/ActivityNoticeManager.php index 16de0eb..270a25b 100644 --- a/fproject/amqp/ActivityNoticeManager.php +++ b/fproject/amqp/ActivityNoticeManager.php @@ -69,17 +69,20 @@ public function getSerializer() * The default implementation does nothing. * You may override this method to do postprocessing after record saving. * - * @param mixed $model The model - * @param mixed $configType the instance of class that is configured in 'config/activityNotice.php' + * @param mixed $data The model or action's data + * @param mixed $configType the class name or instance of class that is configured in 'config/activityNotice.php' * @param string $action the action, the possible values: "add", "update", "batch" * @param mixed $attributeNames the attributes - * @param array $modelList1 if $action is "batch", this will be the inserted models, if action is "delete" and + * @param array $modelList1 if $action is "batchSave", this will be the inserted models, if action is "batchDelete" and * there's multiple deletion executed, this will be the deleted models - * @param array $modelList2 if $action is "batch", this will be the updated models, if action is "delete", this parameter is ignored. + * @param array $modelList2 if $action is "batchSave", this will be the updated models, if action is "batchDelete", this parameter is ignored. */ - public function noticeAfterModelAction($model, $configType, $action, $attributeNames=null, $modelList1=null, $modelList2=null) + public function noticeAfterModelAction($data, $configType, $action, $attributeNames=null, $modelList1=null, $modelList2=null) { - $classId = get_class($configType); + if(is_object($configType)) + $classId = get_class($configType); + else + $classId = $configType; $noticeAction = ($action === 'delete' && isset($modelList1)) ? 'batchDelete' : $action; @@ -116,11 +119,16 @@ public function noticeAfterModelAction($model, $configType, $action, $attributeN } else { - $notice->action = $action; - if($action==='delete' && isset($modelList1)) - $notice->content = $serializer->getSerializeListData($modelList1, $config); + $notice->action = $noticeAction; + if($noticeAction==='batchDelete') + { + if(isset($modelList1)) + $notice->content = $serializer->getSerializeListData($modelList1, $config); + else + $notice->content = $data; + } else - $notice->content = $serializer->getSerializeData($model, $config); + $notice->content = $serializer->getSerializeData($data, $config); $this->sendActivityNotice($notice); } } diff --git a/fproject/amqp/ActivityNoticeSerializer.php b/fproject/amqp/ActivityNoticeSerializer.php index d3c648d..af3549c 100644 --- a/fproject/amqp/ActivityNoticeSerializer.php +++ b/fproject/amqp/ActivityNoticeSerializer.php @@ -259,6 +259,8 @@ public function getSerializeData($data, $config) { if(is_null($config) || !is_array($config)) return null; + elseif(is_string($data)) + return $data; if(isset($config['serializeAttributes'])) $serializeAttributes = $config['serializeAttributes'];