public static function getQueryConditionById($queryId) { $resultInfo = array(); $queryInfo = UserQuery::model()->findByPk($queryId); if ($queryInfo == null) { $resultInfo['status'] = CommonService::$ApiResult['FAIL']; $resultInfo['detail']['id'] = 'query not existed'; return $resultInfo; } else { $userAccessableProductIdArr = Yii::app()->user->getState('visit_product_id'); if (!in_array($queryInfo['product_id'], $userAccessableProductIdArr)) { $resultInfo['status'] = CommonService::$ApiResult['FAIL']; $resultInfo['detail']['id'] = 'has not visit right'; return $resultInfo; } } $parsedQueryInfo = array(); $parsedQueryInfo['product_id'] = $queryInfo['product_id']; $parsedQueryInfo['query_type'] = $queryInfo['query_type']; $parsedQueryInfo['title'] = $queryInfo['title']; $searchArr['leftParenthesesName'] = unserialize($queryInfo->left_parentheses); $searchArr['field'] = unserialize($queryInfo->fieldlist); $searchArr['operator'] = unserialize($queryInfo->operatorlist); $searchArr['value'] = unserialize($queryInfo->valuelist); $searchArr['rightParenthesesName'] = unserialize($queryInfo->right_parentheses); $searchArr['andor'] = unserialize($queryInfo->andorlist); $returnArr = array(); $fieldCount = count($searchArr['field']); $keyArr = array('leftParenthesesName', 'field', 'operator', 'value', 'rightParenthesesName', 'andor'); for ($i = 0; $i < $fieldCount; $i++) { $rowArr = array(); foreach ($keyArr as $key) { $rowArr[$key] = $searchArr[$key][$i]; } $returnArr[] = $rowArr; } $parsedQueryInfo['search_condition'] = $returnArr; $resultInfo['status'] = CommonService::$ApiResult['SUCCESS']; $resultInfo['detail'] = $parsedQueryInfo; return $resultInfo; }
public function actionDeleteTemplateOrQuery() { $id = $_GET['id']; $type = $_GET['type']; if ('template' == $type) { $tmpInfo = UserTemplate::model()->findByAttributes(array('id' => $id, 'created_by' => Yii::app()->user->id)); } elseif ('query' == $type) { $tmpInfo = UserQuery::model()->findByAttributes(array('id' => $id, 'created_by' => Yii::app()->user->id)); } if ($tmpInfo !== null) { $tmpInfo->delete(); } echo CommonService::$ApiResult['SUCCESS']; }