Skip to content

Commit

Permalink
Improve ActivityNoticeSerializer and ActivityNoticeManager: support m…
Browse files Browse the repository at this point in the history
…ore cases for batch-delete actions
  • Loading branch information
Bui Sy Nguyen committed Aug 24, 2015
1 parent 8e38713 commit 4c0f2a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 18 additions & 10 deletions fproject/amqp/ActivityNoticeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions fproject/amqp/ActivityNoticeSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down

0 comments on commit 4c0f2a8

Please sign in to comment.