|
- <?php
-
- namespace common\logic\Producer;
-
- use common\helpers\Departments;
- use common\logic\BaseService;
- use common\logic\RepositoryInterface;
- use yii\helpers\Html;
-
- class ProducerRepository extends BaseService implements RepositoryInterface
- {
- public function getOneById($id)
- {
- return ProducerModel::searchOne(['id' => $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] = '<strong>' . $departments[$departmentCode] . '</strong>';
- $optionsProducers['d' . $departmentCode] = ['disabled' => true];
- }
-
- $dataProducers[$p->id] = '<span class="glyphicon glyphicon-lock"></span> ' . Html::encode(
- $p->name
- ) . ' - ' . Html::encode($p->postcode) . ' ' . Html::encode(
- $p->city
- ) . ' <span class="glyphicon glyphicon-lock"></span>';
-
- if (strlen($p->code)) {
- $optionsProducers[$p->id] = ['class' => 'lock'];
- }
- }
-
- return [
- 'data' => $dataProducers,
- 'options' => $optionsProducers
- ];
- }
- }
|