/**
  * View Questionnaire by questionnaire.
  *
  * <b>Request Type</b>: GET<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/api/questionnaire/{questionnaireId}&channelId={channelId}&openId={openId}br/><br/>
  * <b>Response Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for viewing questionnaire.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *    id, string<br/>
  *    channelId, string<br/>
  *    openId, string<br/>
  *
  * <b>Response Example:</b><br/>
  *     {
  *           "_id": "55d6cb8be9c2fb022c8b4579",
  *           "name": "name",
  *           "startTime": "1429000112193",
  *           "endTime": "1429000116193",
  *           "description": "good",
  *           "question": [
  *               {
  *                   "id": "55d6cb8be9c2fb022c8b4577",
  *                   "title": "math",
  *                   "type": "radio",
  *                   "order": 0,
  *                   "options": [
  *                       {
  *                           "icon": "support",
  *                           "content": "A option"
  *                       },
  *                       {
  *                           "icon": "support",
  *                           "content": "B option"
  *                       }
  *                   ]
  *               },
  *               {
  *                   "id": "55d6cb8be9c2fb022c8b4577",
  *                   "type": "input",
  *                   "title": "This is a problem",
  *                   "order": 1
  *               }
  *           ],
  *           "isPublished": false,
  *           "answerTime": "2015-08-26 10:28:55",
  *           "isAnswered": false
  *     }
  * <pre>
  * </pre>
  */
 public function actionView($id)
 {
     $channelId = $this->getQuery('channelId');
     $openId = $this->getQuery('openId');
     $isAnswered = false;
     $question = [];
     $answerTime = '';
     $questionnaire = [];
     $user = ["channelId" => $channelId, "openId" => $openId];
     $questionnaireInfo = Questionnaire::getById(new MongoId($id));
     if (empty($questionnaireInfo)) {
         throw new InvalidParameterException(Yii::t('content', 'questionnaire_no_exist'));
     }
     if (!empty($channelId) && !empty($openId)) {
         $questionnaireLogInfo = QuestionnaireLog::getByQuestionnaireAndUser(new MongoId($id), $user);
         if (!empty($questionnaireLogInfo)) {
             $answerTime = MongodbUtil::MongoDate2String($questionnaireLogInfo->createdAt, 'Y-m-d H:i:s');
             $isAnswered = true;
         }
     }
     $questionnaire = $questionnaireInfo->toArray();
     $questionnaire['answerTime'] = $answerTime;
     $questionnaire['isAnswered'] = $isAnswered;
     return $questionnaire;
 }