This commit is contained in:
2018-12-03 12:10:39 +03:00
parent c730e2547e
commit 45173d3b66
7 changed files with 111 additions and 13 deletions

View File

@ -13,6 +13,7 @@ use yii\db\Expression;
* @property string $name
* @property string $description
* @property int $status_id
* @property int $projectId
* @property string $created_at
* @property string $updated_at
*
@ -21,6 +22,7 @@ use yii\db\Expression;
*/
class Company extends \yii\db\ActiveRecord
{
public $projectId;
/**
* {@inheritdoc}
*/
@ -49,7 +51,7 @@ class Company extends \yii\db\ActiveRecord
return [
[['name'], 'required'],
[['description'], 'string'],
[['status_id'], 'integer'],
[['status_id', 'projectId'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['name'], 'string', 'max' => 255],
[['status_id'], 'exist', 'skipOnError' => true, 'targetClass' => Status::className(), 'targetAttribute' => ['status_id' => 'id']],
@ -86,4 +88,20 @@ class Company extends \yii\db\ActiveRecord
{
return $this->hasMany(FieldsValue::className(), ['company_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getStatus0()
{
return $this->hasOne(Status::class, ['id' => 'status']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProject()
{
return $this->hasOne(Project::class, ['company_id' => 'id']);
}
}

View File

@ -2,9 +2,11 @@
namespace common\models;
use common\classes\Debug;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "project".
@ -108,4 +110,23 @@ class Project extends \yii\db\ActiveRecord
{
return $this->hasMany(ProjectUser::class, ['project_id' => 'id']);
}
/**
* @return array
*/
public static function getList()
{
return ArrayHelper::map(self::find()->all(), 'id', 'name');
}
public static function getListName()
{
return ArrayHelper::map(self::find()->all(), 'name', 'name');
}
public function getUsersNameList()
{
$model = $this->getProjectUsers()->with('card')->all();
return ArrayHelper::getColumn($model, 'card.fio');
}
}