add api for project
This commit is contained in:
20
frontend/modules/api/models/Company.php
Normal file
20
frontend/modules/api/models/Company.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\models;
|
||||
|
||||
class Company extends \common\models\Company
|
||||
{
|
||||
public function fields()
|
||||
{
|
||||
return [
|
||||
'id',
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
}
|
||||
|
||||
public function extraFields(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
44
frontend/modules/api/models/Project.php
Normal file
44
frontend/modules/api/models/Project.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\models;
|
||||
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\helpers\Url;
|
||||
use yii\web\Link;
|
||||
use yii\web\Linkable;
|
||||
|
||||
class Project extends \common\models\Project implements Linkable
|
||||
{
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'id',
|
||||
'name',
|
||||
'budget',
|
||||
'status',
|
||||
'hh_id' => function() {
|
||||
return $this->hh;
|
||||
},
|
||||
'company' => function() {
|
||||
return $this->company;
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
public function extraFields(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getLinks(): array
|
||||
{
|
||||
return [
|
||||
Link::REL_SELF => Url::to(['index', 'project_id' => $this->id], true),
|
||||
];
|
||||
}
|
||||
|
||||
public function getCompany(): ActiveQuery
|
||||
{
|
||||
return $this->hasOne(Company::className(), ['id' => 'company_id']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user