false, 'message' => Yii::t('api',$this->_errorMessages['none']), ); $this->displayJson($result); } return $model; } public function behaviors() { return [ 'access' => [ 'class' => AccessControlBehavior::className(), 'rules' => [ [ 'allow' => Yii::$app->user->checkAccess('createTicket'), 'actions' => ['list', 'status-list', 'view', 'read', 'create', 'save', 'update', 'delete', 'recommend-geo', 'link-geo', 'unlink-geo', 'recommend-tag', 'link-tag', 'unlink-tag', 'set-status', 'save-geo-attribute', 'save-attribute'], 'roles' => ['@'] ], // public actions [ 'allow' => true, 'actions' => ['new-read'], ], // deny all [ 'allow' => false ] ] ] ]; } protected function _getSearchModel() { return new TicketSearch(); } protected function _getStatusResult($result, AbstractObject $model) { if ($result) { $result = [ 'status' => true, 'data' => $model->getAttributes(), 'message' => Yii::t('api', $this->_successMessages['update']), ]; } else { $result = [ 'status' => false, 'data' => $model->getOldAttributes(), 'message' => Yii::t('api', $this->_errorMessages['update']), ]; } return $result; } protected function _update($data) { $model = $this->_findModel($data); if ($model->statusId != 'draft') { return array( 'status' => false, 'message' => Yii::t('api', $this->_errorMessages['status']), ); } $model->scenario = 'update'; unset($data['id']); if ($model->load(array($model->formName() => $data)) && $model->save()) { $result = array( 'status' => true, 'data' => $model->getAttributes(), 'message' => Yii::t('api', $this->_successMessages['update']), ); } else { $result = array( 'status' => false, 'message' => Yii::t('api', $this->_errorMessages['update']), 'data' => array('errors' => $model->errors), ); } return $result; } /** * @api {get} ticket/new-read?id=:id Request Ticket information * @apiName GetTicketNewRead * @apiGroup Ticket * * @apiParam {Number} id Ticket Id * @apiParam {Boolean} [tags] Request Ticket Tags * @apiParam {Boolean} [images] Request Ticket Images * * @apiSuccess {TicketData} ticket Ticket Data * @apiSuccess {Object.} tags {typeCode: TagGroup, ...} * @apiSuccess {Array.} images */ public function actionNewRead() { $request = $this->getRequestGetParams(); $id = (int) $request['id']; $needTags = !empty($request['tags']); $needUsers = !empty($request['users']); $needImages = !empty($request['images']); // noteForModerator - show only for managers, admin, noteForUser - show only for users, managers, admins $excludeColumns = ['noteForModerator', 'noteForUser']; if (!yii::$app->user->isGuest) { if ('admin' === yii::$app->user->identity->roleId || 'manager' === yii::$app->user->identity->roleId) { $excludeColumns = []; } else { // user $excludeColumns = ['noteForModerator']; } } $model = Ticket::find(['id' => $id, 'public' => 'y']); // todo: fix 404 message if (null == $model) { $this->displayJson([ 'status' => 404, 'message' => Yii::t('api',$this->_errorMessages['none']), ]); } $result = [ 'ticket' => $model->getAttributes(null, $excludeColumns), ]; if ($needTags) { $tags = Ticket::getTicketTags($model->id); $result['tags'] = $tags ? HelperData::group($tags, ['typeCode', 'typeName', 'internalTypeId']) : []; } if ($needUsers) { $result['users'] = Ticket::getTicketUsers($model->id); } if ($needImages) { if (($result['images'] = Ticket::getTicketImages($model->id))) { foreach ($result['images'] as &$img) { $img['thumbnailUrl'] = ThumbGenerator::getThumbnailUrl($img['filenameFs'], 96, 72, ThumbGenerator::METHOD_INNER); $img['imageUrl'] = ThumbGenerator::getThumbnailUrl($img['filenameFs'], 800, 600, ThumbGenerator::METHOD_INNER); } } } $this->displayJson($result); } }