Example #1
0
 /**
  * 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);
 }
Example #2
0
 public function actionGetAcValue()
 {
     $dataStr = $_GET['data'];
     $q = $_GET['q'];
     $limit = $_GET['limit'];
     $valueStr = FieldConfigService::getAutoCompleteValueStr($dataStr, $q, $limit);
     $valueArr = CommonService::splitStringToArray(',', $valueStr);
     $returnStr = '';
     $i = 0;
     foreach ($valueArr as $valueTmp) {
         if ($i < $limit) {
             if ('' == $q || false !== strpos(strtolower($valueTmp), strtolower($q))) {
                 $returnStr .= $valueTmp . '|' . $valueTmp . "\n";
                 $i++;
             }
         } else {
             break;
         }
     }
     echo $returnStr;
 }
Example #3
0
 public function actionEdit()
 {
     self::checkEditable();
     $productId = $_GET['product_id'];
     $productInfo = Product::model()->findByPk($productId);
     $type = $_GET['type'];
     $model = new FieldConfig();
     $actionName = Yii::t('FieldConfig', 'Add Field');
     if (isset($_GET['id'])) {
         $model = FieldConfigService::loadModel($_GET['id']);
         $actionName = Yii::t('FieldConfig', 'Edit Field');
     }
     $this->breadcrumbs = array(Yii::t('Product', 'Back To Product List') => array('/product/index'), $productInfo->name . ' [' . ucfirst($_GET['type']) . Yii::t('Common', 'Manage Fields') . ']' => array('index', 'product_id' => $productId, 'type' => $type), $actionName);
     $model->type = $type;
     $model->scenario = $type;
     if (isset($_POST['FieldConfig'])) {
         $model->attributes = $_POST['FieldConfig'];
         $fieldConfigInfo = $_POST['FieldConfig'];
         if (isset($_GET['id'])) {
             $fieldConfigInfo['id'] = $_GET['id'];
         }
         $fieldConfigInfo['type'] = $type;
         $fieldConfigInfo['product_id'] = $productId;
         $editResult = FieldConfigService::editFieldConfig($fieldConfigInfo);
         $returnJson['status'] = $editResult['status'];
         $returnJson['detail'] = $editResult['detail'];
         if ($editResult['status'] == CommonService::$ApiResult['SUCCESS']) {
             if (isset($_GET['id'])) {
                 $returnJson['detail'] = Yii::t('FieldConfig', 'Field edited successfully');
             } else {
                 $returnJson['detail'] = Yii::t('FieldConfig', 'Field added successfully');
             }
         }
         echo json_encode($returnJson);
         return;
     }
     $this->render('edit', array('model' => $model, 'actionName' => $actionName, 'returnUrl' => Yii::app()->createUrl('fieldConfig/index', array('product_id' => $productId, 'type' => $type))));
 }
Example #4
0
 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;
 }
Example #5
0
 /**
  * load info object
  *
  * @author                                    youzhao.zxw<*****@*****.**>
  * @param   string          $infoType         bug,case or result
  * @param   int             $id               info object id
  * @return  array                             load data result
  */
 public static function loadRawData($infoType, $id)
 {
     $resultInfo = array();
     $mixedInfo = new MixInfo();
     $infoType = strtolower($infoType);
     $className = ucfirst($infoType) . 'InfoView';
     $targetModel = new $className();
     $model = $targetModel->model()->findByPk((int) $id);
     if (null === $model) {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = Yii::t('Common', 'Requested object does not exist');
         return $resultInfo;
     }
     $modelProductId = $model->product_id;
     if (!Info::isProductAccessable($modelProductId)) {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = Yii::t('Common', 'No access right');
         return $resultInfo;
     } else {
         $fileInfo = TestFileService::getRelatedFileInfos($infoType, $id);
         $model->attachment_file = $fileInfo;
         $mixedInfo->setBasicInfo($model);
         $customInfo = FieldConfigService::getCustomFieldValue($model->product_id, $infoType, $id);
         if (false === $customInfo) {
             $customInfo = array();
         }
         $mixedInfo->setCustomInfo($customInfo);
     }
     $model->assign_to_name = CommonService::getUserRealName($model->assign_to);
     $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
     $resultInfo['detail'] = $mixedInfo;
     return $resultInfo;
 }
Example #6
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;
 }
Example #7
0
 public static function getSearchableCostomField($type, $productId)
 {
     $searchCustomFieldArr = array();
     $customFieldArr = self::getProductAllFieldInfo($type, $productId);
     $searchOperatorArr = FieldConfigService::getFieldTypeOperatorMapping();
     foreach ($customFieldArr as $fieldInfo) {
         $searchCustomFieldArr[$fieldInfo['field_name']] = array('label' => $fieldInfo['field_label'], 'type' => $searchOperatorArr[$fieldInfo['field_type']], 'isBasic' => false);
         if (FieldConfig::FIELD_TYPE_MULTISELECT == $fieldInfo['field_type'] || FieldConfig::FIELD_TYPE_SINGLESELECT == $fieldInfo['field_type']) {
             $searchCustomFieldArr[$fieldInfo['field_name']]['value'] = FieldConfigService::getSelectOption($fieldInfo['field_value']);
             array_unshift($searchCustomFieldArr[$fieldInfo['field_name']]['value'], '');
         }
     }
     return $searchCustomFieldArr;
 }