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.

87 line
2.3KB

  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. use common\helpers\Departements ;
  5. use yii\helpers\Html ;
  6. /**
  7. * This is the model class for table "etablissement".
  8. *
  9. * @property integer $id
  10. * @property string $nom
  11. * @property string $siret
  12. * @property string $logo
  13. * @property string $photo
  14. * @property string $description
  15. * @property string $code_postal
  16. * @property string $ville
  17. */
  18. class Etablissement extends \yii\db\ActiveRecord
  19. {
  20. /**
  21. * @inheritdoc
  22. */
  23. public static function tableName()
  24. {
  25. return 'etablissement';
  26. }
  27. /**
  28. * @inheritdoc
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['nom', 'siret'], 'required'],
  34. [['description'], 'string'],
  35. [['nom', 'siret', 'logo', 'photo', 'code_postal', 'ville'], 'string', 'max' => 255],
  36. ];
  37. }
  38. /**
  39. * @inheritdoc
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => 'ID',
  45. 'nom' => 'Nom',
  46. 'siret' => 'Siret',
  47. 'logo' => 'Logo',
  48. 'photo' => 'Photo',
  49. 'description' => 'Description',
  50. 'code_postal' => 'Code postal',
  51. 'ville' => 'Ville',
  52. ];
  53. }
  54. public static function getEtablissementsPopulateDropdown()
  55. {
  56. $etablissements_dispos = Etablissement::find()
  57. ->orderby('code_postal, ville ASC')
  58. ->all() ;
  59. $departements = Departements::get() ;
  60. $data_etablissements_dispos = [] ;
  61. $options_etablissements_dispos = [] ;
  62. foreach($etablissements_dispos as $e)
  63. {
  64. if(!key_exists('d'. substr($e['code_postal'], 0, 2), $data_etablissements_dispos))
  65. {
  66. $data_etablissements_dispos['d'. substr($e['code_postal'], 0, 2)] = '<strong>'.$departements[substr($e['code_postal'], 0, 2)].'</strong>' ;
  67. $options_etablissements_dispos['d'. substr($e['code_postal'], 0, 2)] = ['disabled' => true] ;
  68. }
  69. $data_etablissements_dispos[$e['id']] = Html::encode($e['nom']).' - '.Html::encode($e['code_postal']).' '.Html::encode($e['ville']) ;
  70. }
  71. return ['data' => $data_etablissements_dispos, 'options' => $options_etablissements_dispos] ;
  72. }
  73. }