Ejemplo n.º 1
0
 private static function getExportComment($infoType, $dataArr, $productId)
 {
     $infoIdArr = array();
     $fieldLabelArr = FieldConfigService::getCustomFieldLabel($infoType, $productId);
     foreach ($dataArr as $data) {
         $infoIdArr[] = $data['id'];
     }
     $historyChangeArr = array();
     if (!empty($infoIdArr)) {
         $getActionNoteSql = 'select * from {{' . $infoType . '_action}} where ' . $infoType . 'info_id in (' . join(',', $infoIdArr) . ') order by ' . $infoType . 'info_id desc, created_at desc';
         $actionNoteInfos = Yii::app()->db->createCommand($getActionNoteSql)->queryAll();
         $actionIdArr = array();
         foreach ($actionNoteInfos as $noteInfo) {
             $actionIdArr[] = $noteInfo['id'];
         }
         if (!empty($actionIdArr)) {
             $actionIdKey = $infoType . 'action_id';
             $historySql = 'select * from {{' . $infoType . '_history}} where ' . $actionIdKey . ' in (' . join(',', $actionIdArr) . ') order by ' . $actionIdKey . ',id asc';
             $historyInfos = Yii::app()->db->createCommand($historySql)->queryAll();
             $historyChangeArr = array();
             foreach ($historyInfos as $historyInfo) {
                 if (empty($historyChangeArr[$historyInfo[$actionIdKey]])) {
                     $historyChangeArr[$historyInfo[$actionIdKey]] = array();
                 }
                 $historyChangeArr[$historyInfo[$actionIdKey]][] = $historyInfo;
             }
         }
         $infoCommentArr = array();
         foreach ($actionNoteInfos as $noteInfo) {
             if (!empty($historyChangeArr[$noteInfo['id']])) {
                 $singleChangeArr = $historyChangeArr[$noteInfo['id']];
             } else {
                 $singleChangeArr = array();
             }
             $historyStr = '';
             foreach ($singleChangeArr as $historyInfo) {
                 $historyStr .= '<br/>' . ActionHistoryService::getSingleHistoryStr($fieldLabelArr, $infoType, $productId, $historyInfo);
             }
             $singleActionStr = ActionHistoryService::getActionCleanContent($noteInfo, $infoType, $noteInfo[$infoType . 'info_id']);
             if ('' != $historyStr) {
                 $singleActionStr .= $historyStr;
             }
             if (!in_array($noteInfo['action_note'], array('', '<br />', '<br/>', '<br>'))) {
                 $singleActionStr .= '<br/><br/>' . ActionHistoryService::handDuplicateIdStr($noteInfo['action_note']);
             }
             if (empty($infoCommentArr[$noteInfo[$infoType . 'info_id']])) {
                 $infoCommentArr[$noteInfo[$infoType . 'info_id']] = array();
             }
             $infoCommentArr[$noteInfo[$infoType . 'info_id']][] = $singleActionStr;
         }
     }
     $dataCount = count($dataArr);
     for ($i = 0; $i < $dataCount; $i++) {
         $dataArr[$i]['action_note'] = join("<br/><br/><br/>", $infoCommentArr[$dataArr[$i]['id']]);
     }
     return $dataArr;
 }