$this->query->joinWith([
'phones',
'contacts',
'companies',
'emails',
'documents' => function (ActiveQuery $query) {
$query->joinWith(['documentBills']);
},
'actions',
'listeners' => function (ActiveQuery $query) {
$query->joinWith([
'programs2' => function (ActiveQuery $query) {
$query->joinWith(['program']);
}
]);
},
]);
->andFilterWhere([
'>=',
'DATE(programs2.end_date)',
$this->endDateFrom ? date("Y-m-d",strtotime($this->endDateFrom)) : null
])
->andFilterWhere([
'<=',
'DATE(programs2.end_date)',
$this->endDateTo ? date("Y-m-d",strtotime($this->endDateTo)) : null
]
)
public function getPrograms2(): ActiveQuery
{
return $this->hasMany(ListenerProgram::class, ['listener_id' => 'id'])
->from(['programs' => ListenerProgram::tableName()]);
}
public function getProgram(): ActiveQuery
{
return $this->hasOne(ProgramVariation::class, ['id' => 'program_id'])
->from(['program' => ProgramVariation::tableName()]);
}
public function rules()
{
return [
[['phone', 'fio', 'companyName', 'companyNameFio', 'email', 'contractNumber', 'plan', 'result', 'billNumber'], 'trim'],
[['inn', 'manager_id', 'remindersCount', 'actionsCount', 'executorId'], 'integer'],
[['work_status', 'phone', 'fio', 'companyName', 'companyNameFio', 'email', 'contractNumber',
'service', 'cameFrom', 'requestNumber', 'timeDiff', 'plan', 'result', 'billNumber', <b>'mainProgram'], 'string'</b>],
[['registrationDateFrom', 'registrationDateTo'], 'date', 'format' => 'php:' . \Yii::$app->params['dateFormatPhp']],
[['searchInArchive', 'searchInTrash'], 'boolean'],[['endDateFrom', 'endDateTo'], 'date', 'format' => 'php:' . \Yii::$app->params['dateFormatPhp']],
];
}
Program::getAllProgram() в модели Program может выглядеть такuse yii\helper\ArrayHelper; public static function getAllProgram() { /** * в запрос self::find()->all() можно добавить условие выборки, сортировки, группировки и т.д. и т.п. */ return ArrayHelper::map(self::find->all(), 'id', 'name'); }
<?php
namespace app\modules\crm\modules\program\models;
use yii\db\ActiveQuery;
/**
* @property integer $id
* @property string $name
*
* @property ProgramVariation[] $variations
*/
class Program extends \yii\db\ActiveRecord
{
public static function tableName()
{
return '{{%programs}}';
}
public function rules()
{
return [
['name', 'required'],
['name', 'string', 'max' => 500],
];
}
public function attributeLabels()
{
return [
'name' => 'Наименование',
];
}
public function getVariations(): ActiveQuery
{
return $this->hasMany(ProgramVariation::class, ['program_id' => 'id'])
->from(['variations' => ProgramVariation::tableName()]);
}
}