$id]);
}
public function getOneBySlug($slug)
{
return ProducerModel::searchOne(['slug' => $slug]);
}
public function queryActive()
{
return ProducerModel::find()
->where([
'active' => true,
])
->orderBy('name ASC');
}
/**
* Retourne le compte producteur de démonstration.
*
*/
public function getOneDemoAccount()
{
return ProducerModel::find()->where('name LIKE \'Démo\'')->one();
}
/**
* Retourne la liste des établissements pour l'initialisation d'une liste
* sélective.
*
* @return array
*/
public static function getPopulateDropdown()
{
$producers = ProducerModel::find()
->where([
'active' => true,
])
->orderBy('postcode, city ASC')
->all();
$departments = Departments::get();
$dataProducers = [];
$optionsProducers = [];
foreach ($producers as $p) {
$departmentCode = substr($p->postcode, 0, 2);
if (!key_exists('d' . $departmentCode, $dataProducers) && isset($departments[$departmentCode])) {
$dataProducers['d' . $departmentCode] = '' . $departments[$departmentCode] . '';
$optionsProducers['d' . $departmentCode] = ['disabled' => true];
}
$dataProducers[$p->id] = ' ' . Html::encode(
$p->name
) . ' - ' . Html::encode($p->postcode) . ' ' . Html::encode(
$p->city
) . ' ';
if (strlen($p->code)) {
$optionsProducers[$p->id] = ['class' => 'lock'];
}
}
return [
'data' => $dataProducers,
'options' => $optionsProducers
];
}
}