File: /home/aliazzsr/api.crm.vqode.com/controllers/ProjectController.php
<?php
namespace app\controllers;
use app\components\BaseActiveController;
use app\models\enums\PermissionEnum;
use app\models\UserIdentity;
use yii\web\ForbiddenHttpException;
class ProjectController extends BaseActiveController
{
public $modelClass = 'app\models\core\Project';
protected static $permissionRequired = PermissionEnum::PROJECTS_ALL;
public function actions()
{
$actions = parent::actions();
$actions['statistics'] = [
'class' => 'app\components\actions\ProjectsStatisticsAction',
'modelClass' => $this->modelClass,
'checkAccess' => [$this, 'checkStatisticsAccess'],
];
return $actions;
}
/**
*
* @throws
*/
public function checkStatisticsAccess()
{
/** @var UserIdentity $identity */
$identity = \Yii::$app->user->getIdentity();
if (!$identity->can(PermissionEnum::DASHBOARD_PROJECTS)->read) {
throw new ForbiddenHttpException();
}
}
}
/**
* @SWG\Get(
* path="/projects?expand={models}",
* tags={"Projects"},
* security={{"bearer":{}}},
* summary="Finds Project records existing.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(in="path", name="models", type="string",
* description="List of relative to Project models comma-separated. Available: companies, contacts, riba, sector, stage, owner, priority"
* ),
* @SWG\Response(response=200, description="Successful operation.",
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Project"))
* ),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=422, description="Data validation error."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Get(
* path="/projects/{id}",
* tags={"Projects"},
* security={{"bearer":{}}},
* summary="Returns a single Project record. Available to expand with: companies, contacts, riba, sector, stage, owner, priority",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(description="Identifier", in="path", name="id", required=true, type="integer"),
* @SWG\Response(response=200, description="Successful operation.", @SWG\Schema(ref="#/definitions/Project")),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=404, description="Not found."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Get(
* path="/projects/statistics?group={group}&period={period}",
* tags={"Projects"},
* security={{"bearer":{}}},
* summary="Returns projects statistics",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(in="path", name="group", required=true, type="string",
* description="Group by. Available options: stage, active-stage, inactive-stage, sector, user, riba, company."),
* @SWG\Parameter(in="path", name="period", required=true, type="string",
* description="Period. Available options: month, year, total, and date interval: 01/01/2018-31/12/2018."),
* @SWG\Response(response=200, description="Projects statistics.", @SWG\Schema(ref="#/definitions/ProjectsStatistics")),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=404, description="Not found."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Get(
* path="/projects/statistics?group={group}&period={period}&group_id={group_id}",
* tags={"Projects"},
* security={{"bearer":{}}},
* summary="Returns projects",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(in="path", name="group", required=true, type="string",
* description="Group by. Available options: stage, active-stage, inactive-stage, sector, user, riba, company."),
* @SWG\Parameter(in="path", name="period", required=true, type="string",
* description="Period. Available options: month, year, total, and date interval: 01/01/2018-31/12/2018."),
* @SWG\Parameter(in="path", name="group_id", required=true, type="integer",
* description="Group identifier for the details"),
* @SWG\Response(response=200, description="Projects list.",
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Project"))),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=404, description="Not found."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Post(
* path="/projects",
* tags={"Projects"},
* security={{"bearer":{}}},
* summary="Creates a new Project record.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(name="body", required=true, in="body", @SWG\Schema(
* ref="#/definitions/Project", required={"name"}
* )),
* @SWG\Response(response=201, description="Successful operation."),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=422, description="Data validation error."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Post(
* path="/projects/validate",
* tags={"Projects"},
* security={{"bearer":{}}},
* summary="Validates a new Project record.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(name="body", required=true, in="body", @SWG\Schema(
* ref="#/definitions/Project", required={"name"}
* )),
* @SWG\Response(response=201, description="Successful operation."),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=422, description="Data validation error."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Post(
* path="/projects/{id}/validate",
* tags={"Projects"},
* security={{"bearer":{}}},
* summary="Validates an existed Project record.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(description="Identifier", in="path", name="id", required=true, type="integer"),
* @SWG\Parameter(name="body", required=true, in="body", @SWG\Schema(
* ref="#/definitions/Project", required={"name"}
* )),
* @SWG\Response(response=201, description="Successful operation."),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=422, description="Data validation error."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Put(
* path="/projects/{id}",
* tags={"Projects"},
* security={{"bearer":{}}},
* summary="Updates an existed Project record.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(description="Identifier", in="path", name="id", required=true, type="integer"),
* @SWG\Parameter(name="body", required=true, in="body", @SWG\Schema(ref="#/definitions/Project")),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=422, description="Data validation error."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Delete(
* path="/projects/{id}",
* tags={"Projects"},
* security={{"bearer":{}}},
* summary="Deletes a Project record.",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(description="Identifier", in="path", name="id", required=true, type="integer"),
* @SWG\Response(response=204, description="Successful operation."),
* @SWG\Response(response=401, description="Unauthorized."),
* @SWG\Response(response=404, description="Not found."),
* @SWG\Response(response=500, description="Internal server error.")
* )
*
* @SWG\Definition(
* definition="ProjectsStatistics",
* type="object",
* description="ProjectsStatistics model",
* allOf={
* @SWG\Schema(ref="#/definitions/ProjectsStatistics"),
* @SWG\Schema(
* @SWG\Property(property="group_id", type="integer", example=7, description="Group unique identifier"),
* @SWG\Property(property="group_name", type="string", example="Idea", description="Group name"),
* @SWG\Property(property="count", type="integer", example=13, description="Number of projects"),
* @SWG\Property(property="count_percentage", type="float", example=13.7461, description="Number of projects, percentage to overall number"),
* @SWG\Property(property="value", type="float", example=753000.00, description="Sum of value for projects selected"),
* @SWG\Property(property="value_percentage", type="float", example=50.0000, description="Sum of value, percentage to overall value"),
* @SWG\Property(property="edv", type="float", example=15000.00, description="Sum of Estimated Drywall Volume for projects selected"),
* @SWG\Property(property="edv_percentage", type="float", example=66.6667, description="Sum of Estimated Drywall Volume, percentage to overall volume")
* )
* }
* )
*/