Exemplo n.º 1
0
 /**
  * add action notes
  *
  * @author                                  youzhao.zxw<*****@*****.**>
  * @param   string  $tableName              target table name
  * @param   string  $action                 edit action
  * @param   array   $newRecordAttributes    new record attributes
  * @param   array   $oldRecordAttributs     old record attributes
  * @return  array                           add action notes result
  */
 public static function addActionNotes($tableName, $action, $newRecordAttributes, $oldRecordAttributs)
 {
     $infoAction = new AdminAction();
     $infoAction->action_type = $action;
     $infoAction->target_table = $tableName;
     $infoAction->target_id = $newRecordAttributes['id'];
     if (!$infoAction->save()) {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $infoAction->getErrors();
         return $resultInfo;
     } else {
         if (!empty($oldRecordAttributs)) {
             $diffAttributeArr = self::compareRecord($oldRecordAttributs, $newRecordAttributes);
             foreach ($diffAttributeArr as $diffInfo) {
                 $actionHistory = new AdminHistory();
                 $actionHistory->action_field = $diffInfo[0];
                 $actionHistory->adminaction_id = $infoAction->id;
                 $actionHistory->old_value = $diffInfo[1];
                 $actionHistory->new_value = $diffInfo[2];
                 if (!$actionHistory->save()) {
                     $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
                     $resultInfo['detail'] = $actionHistory->getErrors();
                     return $resultInfo;
                 }
             }
         }
     }
     $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
     $resultInfo['detail'] = array('id' => $infoAction->id);
     return $resultInfo;
 }