|
- <?php
-
- namespace common\models;
-
- use Yii;
- use common\helpers\Departements ;
- use yii\helpers\Html ;
-
- /**
- * This is the model class for table "etablissement".
- *
- * @property integer $id
- * @property string $nom
- * @property string $siret
- * @property string $logo
- * @property string $photo
- * @property string $description
- * @property string $code_postal
- * @property string $ville
- */
- class Etablissement extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'etablissement';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['nom', 'siret'], 'required'],
- [['description'], 'string'],
- [['nom', 'siret', 'logo', 'photo', 'code_postal', 'ville'], 'string', 'max' => 255],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'nom' => 'Nom',
- 'siret' => 'Siret',
- 'logo' => 'Logo',
- 'photo' => 'Photo',
- 'description' => 'Description',
- 'code_postal' => 'Code postal',
- 'ville' => 'Ville',
- ];
- }
-
- public static function getEtablissementsPopulateDropdown()
- {
-
- $etablissements_dispos = Etablissement::find()
- ->orderby('code_postal, ville ASC')
- ->all() ;
-
- $departements = Departements::get() ;
- $data_etablissements_dispos = [] ;
- $options_etablissements_dispos = [] ;
- foreach($etablissements_dispos as $e)
- {
- if(!key_exists('d'. substr($e['code_postal'], 0, 2), $data_etablissements_dispos))
- {
- $data_etablissements_dispos['d'. substr($e['code_postal'], 0, 2)] = '<strong>'.$departements[substr($e['code_postal'], 0, 2)].'</strong>' ;
- $options_etablissements_dispos['d'. substr($e['code_postal'], 0, 2)] = ['disabled' => true] ;
- }
-
- $data_etablissements_dispos[$e['id']] = Html::encode($e['nom']).' - '.Html::encode($e['code_postal']).' '.Html::encode($e['ville']) ;
-
- }
-
-
- return ['data' => $data_etablissements_dispos, 'options' => $options_etablissements_dispos] ;
-
- }
- }
|