You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.3KB

  1. <?php
  2. namespace common\logic\Producer;
  3. use common\helpers\Departments;
  4. use common\logic\BaseService;
  5. use common\logic\RepositoryInterface;
  6. use yii\helpers\Html;
  7. class ProducerRepository extends BaseService implements RepositoryInterface
  8. {
  9. public function getOneById($id)
  10. {
  11. return ProducerModel::searchOne(['id' => $id]);
  12. }
  13. public function getOneBySlug($slug)
  14. {
  15. return ProducerModel::searchOne(['slug' => $slug]);
  16. }
  17. public function queryActive()
  18. {
  19. return ProducerModel::find()
  20. ->where([
  21. 'active' => true,
  22. ])
  23. ->orderBy('name ASC');
  24. }
  25. /**
  26. * Retourne le compte producteur de démonstration.
  27. *
  28. */
  29. public function getOneDemoAccount()
  30. {
  31. return ProducerModel::find()->where('name LIKE \'Démo\'')->one();
  32. }
  33. /**
  34. * Retourne la liste des établissements pour l'initialisation d'une liste
  35. * sélective.
  36. *
  37. * @return array
  38. */
  39. public static function getPopulateDropdown()
  40. {
  41. $producers = ProducerModel::find()
  42. ->where([
  43. 'active' => true,
  44. ])
  45. ->orderBy('postcode, city ASC')
  46. ->all();
  47. $departments = Departments::get();
  48. $dataProducers = [];
  49. $optionsProducers = [];
  50. foreach ($producers as $p) {
  51. $departmentCode = substr($p->postcode, 0, 2);
  52. if (!key_exists('d' . $departmentCode, $dataProducers) && isset($departments[$departmentCode])) {
  53. $dataProducers['d' . $departmentCode] = '<strong>' . $departments[$departmentCode] . '</strong>';
  54. $optionsProducers['d' . $departmentCode] = ['disabled' => true];
  55. }
  56. $dataProducers[$p->id] = '<span class="glyphicon glyphicon-lock"></span> ' . Html::encode(
  57. $p->name
  58. ) . ' - ' . Html::encode($p->postcode) . ' ' . Html::encode(
  59. $p->city
  60. ) . ' <span class="glyphicon glyphicon-lock"></span>';
  61. if (strlen($p->code)) {
  62. $optionsProducers[$p->id] = ['class' => 'lock'];
  63. }
  64. }
  65. return [
  66. 'data' => $dataProducers,
  67. 'options' => $optionsProducers
  68. ];
  69. }
  70. }