<?php
/**
 * @link      http://www.u-bo.com
 * @copyright 南京友博网络科技有限公司 
 * @license   http://www.u-bo.com/license/
 */

namespace wap\controllers;

use Yii;
use wap\controllers\Controller;
use wap\models\Project;
use yii\db\Query;
use common\models\Common;
use yii\web\NotFoundHttpException;
use yii\web\ForbiddenHttpException;
use yii\data\ActiveDataProvider;
use yii\helpers\StringHelper;
use yii\helpers\Url;
use common\models\PermissionScope;

/**
 * 项目控制器
 *
 * @author legendjw http://blog.u-bo.com
 * @since 0.1
 */
class ProjectController extends Controller
{
    /**
     * 项目详情
     */
    public function actionDetail()
    {
        $request = Yii::$app->request;
        $id = (int) $request->get('id');

        $model = Project::findOne(['project_id' => $id]);
        if (empty($model)) {
            throw new NotFoundHttpException('该项目不存在');
        }

        //权限检测
        $scopeUser = PermissionScope::getScopeUser('project/project/detail');
        if (!empty($scopeUser) && !in_array($model['user_id'], $scopeUser) && !in_array($model['leader_id'], $scopeUser)) {
            throw new ForbiddenHttpException('该项目不存在');
        }

        return $this->render('detail', [
            'model' => $model,
            'scopeCount' => $model->getProjectScope(true),
            'resourceCount' => $model->getProjectResource(true),
        ]);
    }

}
