/** * label convert to field * * @param string $label * @param string $productId * @param string $infoType * @param array */ private function fieldConv($label, $productId, $infoType) { $field = false; $isBasic = false; $clazz = ucfirst($infoType) . 'Info'; // $basicFields = $clazz::model()->attributeLabels(); $targetModel = new $clazz(); $basicFields = $targetModel->attributeLabels(); $customFields = FieldConfigService::getCustomFieldLabel($infoType, $productId); $notAllowFields = array('created_by', 'updated_by', 'created_by_name', 'updated_by_name', 'created_at', 'updated_at', 'modified_by', 'related_result'); foreach ($notAllowFields as $field) { if (isset($basicFields[$field])) { unset($basicFields[$field]); } } $field = array_search($label, $basicFields); if ($field) { // hard code for productmodule_id&module_name, assign_to&assign_to_name if ('assign_to' == $field) { $field = 'assign_to_name'; } if ('module_name' == $field) { $field = 'productmodule_id'; } $isBasic = true; } else { $field = array_search($label, $customFields); } return array($field, $isBasic); }
public static function getInfoActionForApi($type, $id, $productId) { $fieldLabelArr = FieldConfigService::getCustomFieldLabel($type, $productId); $actionInfos = Yii::app()->db->createCommand()->select('*')->from('{{' . $type . '_action' . '}}')->where($type . 'info_id = :id', array(':id' => $id))->order('id desc')->queryAll(); list($addFileInfos, $deleteFileInfos) = self::getFileEditInfos($type, $id); $actionCount = count($actionInfos); for ($i = 0; $i < $actionCount; $i++) { $actionInfos[$i]['action_note'] = CHtml::encode($actionInfos[$i]['action_note']); $actionInfos[$i]['created_by_name'] = CommonService::getUserRealName($actionInfos[$i]['created_by']); $actionInfos[$i]['action_history'] = self::getFieldEditInfoForApi($actionInfos[$i], $type, $fieldLabelArr); $actionInfos[$i]['added_file'] = array(); $actionInfos[$i]['deleted_file'] = array(); if (isset($addFileInfos[$actionInfos[$i]['id']])) { $actionInfos[$i]['added_file'] = $addFileInfos[$actionInfos[$i]['id']]; } if (isset($deleteFileInfos[$actionInfos[$i]['id']])) { $actionInfos[$i]['deleted_file'] = $deleteFileInfos[$actionInfos[$i]['id']]; } } return $actionInfos; }
/** * get message content * * @author youzhao.zxw<*****@*****.**> * @param array $basicInfo basic info * @param string $infoType bug,case or result * @param int $actionId action id * @param string $repeatStep repeat step * @param string $replyNote reply note * @return array message content */ private static function getMessageContent($basicInfo, $infoType, $actionId, $repeatStep, $replyNote) { $infoId = $basicInfo['id']; $absoluteUrl = Yii::app()->createAbsoluteUrl('info/edit', array('type' => $infoType, 'id' => $infoId)); $linkUrl = '<a target="blank" href="' . $absoluteUrl . '">[' . ucfirst($infoType) . ' #' . $infoId . ' => ' . CommonService::getUserRealName($basicInfo['assign_to']) . ']</a>'; $msgContent = $linkUrl; $fileEditInfos = ActionHistoryService::getFileEditInfos($infoType, $infoId); $actionInfo = Yii::app()->db->createCommand()->select('*')->from('{{' . $infoType . '_action' . '}}')->where('id = :id', array(':id' => $actionId))->queryRow(); $fieldLabelArr = FieldConfigService::getCustomFieldLabel($infoType, $basicInfo['product_id']); $msgContent .= ActionHistoryService::getSingleActionHistory($fileEditInfos, $actionInfo, $infoType, $infoId, $fieldLabelArr, $basicInfo['product_id']); if ('' != $repeatStep) { $msgContent .= "<br/><br/>" . str_repeat("-", 20) . "<br/><br/>" . $repeatStep; } $wangwangMsg = ''; if (Info::TYPE_BUG == $infoType) { $wangwangMsg .= 'Bug #' . $infoId . ':' . CommonService::sysSubStr($basicInfo['title'], 150, true) . "<br/>"; $wangwangMsg .= $linkUrl; if (BugInfo::ACTION_RESOLVE == $actionInfo['action_type']) { $wangwangMsg .= Yii::t('BugInfo', $actionInfo['action_type']) . ' as ' . $basicInfo['solution'] . ' by ' . CommonService::getUserRealName($actionInfo['created_by']); } else { $wangwangMsg .= Yii::t('BugInfo', $actionInfo['action_type']) . ' by ' . CommonService::getUserRealName($actionInfo['created_by']); } if ($replyNote != '') { $wangwangMsg .= "<br/>" . $replyNote; } } return array($msgContent, $wangwangMsg); }
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; }