Commit d204fdc13522157ccb507df980b9f4a251ba7349
1 parent
fab1487f
- doctors
- add doctor to question
Showing
14 changed files
with
590 additions
and
7 deletions
Show diff stats
| 1 | +<?php | ||
| 2 | + /** | ||
| 3 | + * Created by PhpStorm. | ||
| 4 | + * User: stes | ||
| 5 | + * Date: 31.05.18 | ||
| 6 | + * Time: 14:30 | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | + namespace backend\controllers; | ||
| 10 | + | ||
| 11 | + use artbox\core\admin\actions\Create; | ||
| 12 | + use artbox\core\admin\actions\Delete; | ||
| 13 | + use artbox\core\admin\actions\Index; | ||
| 14 | + use artbox\core\admin\actions\Update; | ||
| 15 | + use artbox\core\admin\actions\View; | ||
| 16 | + use artbox\core\admin\interfaces\ControllerInterface; | ||
| 17 | + use artbox\core\admin\widgets\Form; | ||
| 18 | + use common\models\Doctor; | ||
| 19 | + use yii\filters\AccessControl; | ||
| 20 | + use yii\filters\VerbFilter; | ||
| 21 | + use yii\web\Controller; | ||
| 22 | + use yii\web\NotFoundHttpException; | ||
| 23 | + | ||
| 24 | + class DoctorController extends Controller implements ControllerInterface | ||
| 25 | + { | ||
| 26 | + public function behaviors() | ||
| 27 | + { | ||
| 28 | + return [ | ||
| 29 | + 'verbs' => [ | ||
| 30 | + 'class' => VerbFilter::className(), | ||
| 31 | + 'actions' => [ | ||
| 32 | + 'delete' => [ 'POST' ], | ||
| 33 | + ], | ||
| 34 | + ], | ||
| 35 | + 'access' => [ | ||
| 36 | + 'class' => AccessControl::className(), | ||
| 37 | + 'rules' => [ | ||
| 38 | + [ | ||
| 39 | + 'allow' => true, | ||
| 40 | + 'roles' => [ '@' ], | ||
| 41 | + ], | ||
| 42 | + ], | ||
| 43 | + ], | ||
| 44 | + ]; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public function actions() | ||
| 48 | + { | ||
| 49 | + return [ | ||
| 50 | + 'index' => [ | ||
| 51 | + 'class' => Index::className(), | ||
| 52 | + 'columns' => [ | ||
| 53 | + 'name' => [ | ||
| 54 | + 'type' => Index::ACTION_COL, | ||
| 55 | + ], | ||
| 56 | + | ||
| 57 | + 'position' => [ | ||
| 58 | + 'type' => Index::STRING_COL, | ||
| 59 | + ], | ||
| 60 | + 'sort' => [ | ||
| 61 | + 'type' => Index::POSITION_COL, | ||
| 62 | + ], | ||
| 63 | + 'status' => [ | ||
| 64 | + 'type' => Index::STATUS_COL, | ||
| 65 | + ], | ||
| 66 | + ], | ||
| 67 | + 'model' => Doctor::className(), | ||
| 68 | + 'hasLanguage' => true, | ||
| 69 | + 'enableMassDelete' => true, | ||
| 70 | + 'modelPrimaryKey' => 'id', | ||
| 71 | + ], | ||
| 72 | + 'create' => array_merge([ 'class' => Create::className() ], self::fieldsConfig()), | ||
| 73 | + 'update' => array_merge([ 'class' => Update::className() ], self::fieldsConfig()), | ||
| 74 | + 'view' => [ | ||
| 75 | + 'class' => View::className(), | ||
| 76 | + 'model' => Doctor::className(), | ||
| 77 | + 'hasAlias' => true, | ||
| 78 | + 'languageFields' => [ | ||
| 79 | + [ | ||
| 80 | + 'name' => 'name', | ||
| 81 | + 'type' => Form::STRING, | ||
| 82 | + ], | ||
| 83 | + [ | ||
| 84 | + 'name' => 'position', | ||
| 85 | + 'type' => Form::STRING, | ||
| 86 | + ], | ||
| 87 | + [ | ||
| 88 | + 'name' => 'description', | ||
| 89 | + 'type' => Form::WYSIWYG, | ||
| 90 | + ], | ||
| 91 | + ], | ||
| 92 | + 'fields' => [ | ||
| 93 | + [ | ||
| 94 | + 'name' => 'service_id', | ||
| 95 | + 'type' => Form::RELATION, | ||
| 96 | + 'relationAttribute' => 'title', | ||
| 97 | + 'relationName' => 'service', | ||
| 98 | + 'multiple' => false, | ||
| 99 | + ], | ||
| 100 | + ], | ||
| 101 | + ], | ||
| 102 | + 'delete' => [ | ||
| 103 | + 'class' => Delete::className(), | ||
| 104 | + ], | ||
| 105 | + ]; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public function findModel($id) | ||
| 109 | + { | ||
| 110 | + $model = Doctor::find() | ||
| 111 | + ->with('languages') | ||
| 112 | + ->where([ 'id' => $id ]) | ||
| 113 | + ->one(); | ||
| 114 | + if ($model !== null) { | ||
| 115 | + return $model; | ||
| 116 | + } else { | ||
| 117 | + throw new NotFoundHttpException('The requested page does not exist.'); | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + public function newModel() | ||
| 122 | + { | ||
| 123 | + return new Doctor(); | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + public function deleteModel($id) | ||
| 127 | + { | ||
| 128 | + $page = Doctor::find() | ||
| 129 | + ->with('languages.alias') | ||
| 130 | + ->where( | ||
| 131 | + [ | ||
| 132 | + 'id' => $id, | ||
| 133 | + ] | ||
| 134 | + ) | ||
| 135 | + ->one(); | ||
| 136 | + $langs = call_user_func( | ||
| 137 | + [ | ||
| 138 | + $page, | ||
| 139 | + 'getVariationModels', | ||
| 140 | + ] | ||
| 141 | + ); | ||
| 142 | + foreach ($langs as $lang) { | ||
| 143 | + if ($lang->alias !== null) { | ||
| 144 | + $lang->alias->delete(); | ||
| 145 | + } | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + return $page->delete(); | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + protected static function fieldsConfig() | ||
| 152 | + { | ||
| 153 | + return [ | ||
| 154 | + 'model' => Doctor::className(), | ||
| 155 | + 'hasAlias' => true, | ||
| 156 | + 'languageFields' => [ | ||
| 157 | + [ | ||
| 158 | + 'name' => 'name', | ||
| 159 | + 'type' => Form::STRING, | ||
| 160 | + 'decorate' => true | ||
| 161 | + ], | ||
| 162 | + [ | ||
| 163 | + 'name' => 'description', | ||
| 164 | + 'type' => Form::WYSIWYG, | ||
| 165 | + ], | ||
| 166 | + [ | ||
| 167 | + 'name' => 'position', | ||
| 168 | + 'type' => Form::STRING, | ||
| 169 | + ], | ||
| 170 | + ], | ||
| 171 | + 'fields' => [ | ||
| 172 | + [ | ||
| 173 | + 'name' => 'image_id', | ||
| 174 | + 'type' => Form::IMAGE | ||
| 175 | + ], | ||
| 176 | + [ | ||
| 177 | + 'name' => 'service_id', | ||
| 178 | + 'type' => Form::RELATION, | ||
| 179 | + 'relationAttribute' => 'title', | ||
| 180 | + 'relationName' => 'service', | ||
| 181 | + 'multiple' => false, | ||
| 182 | + ], | ||
| 183 | + [ | ||
| 184 | + 'name' => 'status', | ||
| 185 | + 'type' => Form::BOOL, | ||
| 186 | + ], | ||
| 187 | + [ | ||
| 188 | + 'name' => 'sort', | ||
| 189 | + 'type' => Form::NUMBER, | ||
| 190 | + ], | ||
| 191 | + ], | ||
| 192 | + ]; | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + } | ||
| 0 | \ No newline at end of file | 196 | \ No newline at end of file |
backend/controllers/QuestionController.php
| @@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
| 12 | use artbox\core\admin\actions\Index; | 12 | use artbox\core\admin\actions\Index; |
| 13 | use artbox\core\admin\actions\View; | 13 | use artbox\core\admin\actions\View; |
| 14 | use artbox\core\admin\widgets\Form; | 14 | use artbox\core\admin\widgets\Form; |
| 15 | + use common\models\Doctor; | ||
| 15 | use common\models\Question; | 16 | use common\models\Question; |
| 16 | use common\models\Service; | 17 | use common\models\Service; |
| 17 | use yii\filters\AccessControl; | 18 | use yii\filters\AccessControl; |
| @@ -133,6 +134,9 @@ | @@ -133,6 +134,9 @@ | ||
| 133 | $model = $this->findModel($id); | 134 | $model = $this->findModel($id); |
| 134 | $services = Service::find()->all(); | 135 | $services = Service::find()->all(); |
| 135 | $data = ArrayHelper::map($services, 'id', 'title'); | 136 | $data = ArrayHelper::map($services, 'id', 'title'); |
| 137 | + | ||
| 138 | + $doctors = Doctor::find()->all(); | ||
| 139 | + $dataDoctors = ArrayHelper::map($doctors, 'id', 'name'); | ||
| 136 | $model->scenario = Question::SCENARIO_ANSWER; | 140 | $model->scenario = Question::SCENARIO_ANSWER; |
| 137 | if ($model->load(\Yii::$app->request->post()) && $model->save()) { | 141 | if ($model->load(\Yii::$app->request->post()) && $model->save()) { |
| 138 | return $this->redirect('index'); | 142 | return $this->redirect('index'); |
| @@ -141,7 +145,8 @@ | @@ -141,7 +145,8 @@ | ||
| 141 | 'update', | 145 | 'update', |
| 142 | [ | 146 | [ |
| 143 | 'model' => $model, | 147 | 'model' => $model, |
| 144 | - 'services' => $data | 148 | + 'services' => $data, |
| 149 | + 'doctors' => $dataDoctors | ||
| 145 | ] | 150 | ] |
| 146 | ); | 151 | ); |
| 147 | } | 152 | } |
backend/views/layouts/menu_items.php
backend/views/question/_form.php
| @@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
| 8 | /* @var $this yii\web\View */ | 8 | /* @var $this yii\web\View */ |
| 9 | /* @var $model \common\models\Question */ | 9 | /* @var $model \common\models\Question */ |
| 10 | /* @var $form yii\widgets\ActiveForm */ | 10 | /* @var $form yii\widgets\ActiveForm */ |
| 11 | + /* @var $doctors \common\models\Doctor[]*/ | ||
| 11 | Switchery::register($this); | 12 | Switchery::register($this); |
| 12 | $js = <<< JS | 13 | $js = <<< JS |
| 13 | $('.switchery').each(function(idx, elem) { | 14 | $('.switchery').each(function(idx, elem) { |
| @@ -18,6 +19,7 @@ $('.switchery').each(function(idx, elem) { | @@ -18,6 +19,7 @@ $('.switchery').each(function(idx, elem) { | ||
| 18 | }); | 19 | }); |
| 19 | 20 | ||
| 20 | $(".select_service").select2(); | 21 | $(".select_service").select2(); |
| 22 | +$(".select_doctors").select2(); | ||
| 21 | JS; | 23 | JS; |
| 22 | 24 | ||
| 23 | 25 | ||
| @@ -30,6 +32,9 @@ JS; | @@ -30,6 +32,9 @@ JS; | ||
| 30 | <?=$form->field($model, 'service_id')->dropDownList($services, [ | 32 | <?=$form->field($model, 'service_id')->dropDownList($services, [ |
| 31 | 'class' => 'select_service' | 33 | 'class' => 'select_service' |
| 32 | ])?> | 34 | ])?> |
| 35 | + <?=$form->field($model, 'doctor_id')->dropDownList($doctors, [ | ||
| 36 | + 'class' => 'select_doctors' | ||
| 37 | + ])?> | ||
| 33 | <?= $form->field($model, 'name') | 38 | <?= $form->field($model, 'name') |
| 34 | ->textInput([ 'maxlength' => true ]) ?> | 39 | ->textInput([ 'maxlength' => true ]) ?> |
| 35 | 40 |
backend/views/question/update.php
| @@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
| 4 | 4 | ||
| 5 | /* @var $this yii\web\View */ | 5 | /* @var $this yii\web\View */ |
| 6 | /* @var $model \common\models\Question */ | 6 | /* @var $model \common\models\Question */ |
| 7 | + /* @var $doctors \common\models\Doctor[]*/ | ||
| 7 | 8 | ||
| 8 | $this->title = Yii::t( | 9 | $this->title = Yii::t( |
| 9 | 'app', | 10 | 'app', |
| @@ -40,6 +41,7 @@ | @@ -40,6 +41,7 @@ | ||
| 40 | [ | 41 | [ |
| 41 | 'model' => $model, | 42 | 'model' => $model, |
| 42 | 'services' => $services, | 43 | 'services' => $services, |
| 44 | + 'doctors' => $doctors | ||
| 43 | ] | 45 | ] |
| 44 | ) ?> | 46 | ) ?> |
| 45 | 47 |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace common\models; | ||
| 4 | + | ||
| 5 | +use artbox\core\models\Image; | ||
| 6 | +use artbox\core\models\Language; | ||
| 7 | +use artbox\core\models\traits\AliasableTrait; | ||
| 8 | +use Yii; | ||
| 9 | +use yii\db\ActiveQuery; | ||
| 10 | +use yii\helpers\Json; | ||
| 11 | +use yii2tech\ar\position\PositionBehavior; | ||
| 12 | +use yii2tech\ar\variation\VariationBehavior; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * This is the model class for table "doctor". | ||
| 16 | + * | ||
| 17 | + * @property int $id | ||
| 18 | + * @property int $service_id | ||
| 19 | + * @property bool $status | ||
| 20 | + * @property int $sort | ||
| 21 | + * | ||
| 22 | + * @property Service $service | ||
| 23 | + * @property DoctorLang[] $doctorLangs | ||
| 24 | + * @property Language[] $languages | ||
| 25 | + * * from VariationBehavior | ||
| 26 | + * @method ActiveQuery hasDefaultVariationRelation(); | ||
| 27 | + */ | ||
| 28 | +class Doctor extends \yii\db\ActiveRecord | ||
| 29 | +{ | ||
| 30 | + use AliasableTrait; | ||
| 31 | + /** | ||
| 32 | + * {@inheritdoc} | ||
| 33 | + */ | ||
| 34 | + public static function tableName() | ||
| 35 | + { | ||
| 36 | + return 'doctor'; | ||
| 37 | + } | ||
| 38 | + public function behaviors() | ||
| 39 | + { | ||
| 40 | + return [ | ||
| 41 | + 'translations' => [ | ||
| 42 | + 'class' => VariationBehavior::className(), | ||
| 43 | + 'variationsRelation' => 'languages', | ||
| 44 | + 'defaultVariationRelation' => 'language', | ||
| 45 | + 'variationOptionReferenceAttribute' => 'language_id', | ||
| 46 | + 'optionModelClass' => Language::className(), | ||
| 47 | + 'defaultVariationOptionReference' => function () { | ||
| 48 | + return Language::getCurrent()->id; | ||
| 49 | + }, | ||
| 50 | + 'optionQueryFilter' => function (ActiveQuery $query) { | ||
| 51 | + $query->where( | ||
| 52 | + [ | ||
| 53 | + 'status' => true, | ||
| 54 | + ] | ||
| 55 | + ); | ||
| 56 | + }, | ||
| 57 | + ], | ||
| 58 | + 'positionBehavior' => [ | ||
| 59 | + 'class' => PositionBehavior::className(), | ||
| 60 | + 'positionAttribute' => 'sort', | ||
| 61 | + ], | ||
| 62 | + ]; | ||
| 63 | + } | ||
| 64 | + /** | ||
| 65 | + * {@inheritdoc} | ||
| 66 | + */ | ||
| 67 | + public function rules() | ||
| 68 | + { | ||
| 69 | + return [ | ||
| 70 | + [['service_id', 'sort'], 'default', 'value' => null], | ||
| 71 | + [['service_id', 'sort'], 'integer'], | ||
| 72 | + [['status'], 'boolean'], | ||
| 73 | + [['service_id'], 'exist', 'skipOnError' => true, 'targetClass' => Service::className(), 'targetAttribute' => ['service_id' => 'id']], | ||
| 74 | + ]; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * {@inheritdoc} | ||
| 79 | + */ | ||
| 80 | + public function attributeLabels() | ||
| 81 | + { | ||
| 82 | + return [ | ||
| 83 | + 'id' => Yii::t('app', 'ID'), | ||
| 84 | + 'service_id' => Yii::t('app', 'Service ID'), | ||
| 85 | + 'status' => Yii::t('app', 'Status'), | ||
| 86 | + 'sort' => Yii::t('app', 'Sort'), | ||
| 87 | + ]; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * @return \yii\db\ActiveQuery | ||
| 92 | + */ | ||
| 93 | + public function getService() | ||
| 94 | + { | ||
| 95 | + return $this->hasOne(Service::className(), ['id' => 'service_id']); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * @return \yii\db\ActiveQuery | ||
| 100 | + */ | ||
| 101 | + public function getLanguages() | ||
| 102 | + { | ||
| 103 | + return $this->hasMany(DoctorLang::className(), ['doctor_id' => 'id']); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + public function getLanguage(){ | ||
| 107 | + return $this->hasDefaultVariationRelation(); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * @return string | ||
| 112 | + */ | ||
| 113 | + public function getRoute() | ||
| 114 | + { | ||
| 115 | + return Json::encode( | ||
| 116 | + [ | ||
| 117 | + 'doctor/view', | ||
| 118 | + 'id' => $this->id, | ||
| 119 | + ] | ||
| 120 | + ); | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + public function getImage(){ | ||
| 124 | + return $this->hasOne(Image::className(), ['id' => 'image_id']); | ||
| 125 | + } | ||
| 126 | +} |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace common\models; | ||
| 4 | + | ||
| 5 | +use artbox\core\models\Alias; | ||
| 6 | +use artbox\core\models\Language; | ||
| 7 | +use Yii; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * This is the model class for table "doctor_lang". | ||
| 11 | + * | ||
| 12 | + * @property int $language_id | ||
| 13 | + * @property int $alias_id | ||
| 14 | + * @property int $doctor_id | ||
| 15 | + * @property string $name | ||
| 16 | + * @property string $position | ||
| 17 | + * @property string $description | ||
| 18 | + * | ||
| 19 | + * @property Alias $alias | ||
| 20 | + * @property Doctor $doctor | ||
| 21 | + * @property Language $language | ||
| 22 | + */ | ||
| 23 | +class DoctorLang extends \yii\db\ActiveRecord | ||
| 24 | +{ | ||
| 25 | + /** | ||
| 26 | + * {@inheritdoc} | ||
| 27 | + */ | ||
| 28 | + public static function tableName() | ||
| 29 | + { | ||
| 30 | + return 'doctor_lang'; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * {@inheritdoc} | ||
| 35 | + */ | ||
| 36 | + public function rules() | ||
| 37 | + { | ||
| 38 | + return [ | ||
| 39 | + [['language_id', 'alias_id', 'doctor_id'], 'default', 'value' => null], | ||
| 40 | + [['language_id', 'alias_id', 'doctor_id'], 'integer'], | ||
| 41 | + [['description'], 'string'], | ||
| 42 | + [['name', 'position'], 'string', 'max' => 255], | ||
| 43 | + [['language_id', 'doctor_id'], 'unique', 'targetAttribute' => ['language_id', 'doctor_id']], | ||
| 44 | + [['alias_id'], 'exist', 'skipOnError' => true, 'targetClass' => Alias::className(), 'targetAttribute' => ['alias_id' => 'id']], | ||
| 45 | + [['doctor_id'], 'exist', 'skipOnError' => true, 'targetClass' => Doctor::className(), 'targetAttribute' => ['doctor_id' => 'id']], | ||
| 46 | + [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::className(), 'targetAttribute' => ['language_id' => 'id']], | ||
| 47 | + ]; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * {@inheritdoc} | ||
| 52 | + */ | ||
| 53 | + public function attributeLabels() | ||
| 54 | + { | ||
| 55 | + return [ | ||
| 56 | + 'language_id' => Yii::t('app', 'Language ID'), | ||
| 57 | + 'alias_id' => Yii::t('app', 'Alias ID'), | ||
| 58 | + 'doctor_id' => Yii::t('app', 'Doctor ID'), | ||
| 59 | + 'name' => Yii::t('app', 'Name'), | ||
| 60 | + 'position' => Yii::t('app', 'Position'), | ||
| 61 | + 'description' => Yii::t('app', 'Description'), | ||
| 62 | + ]; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * @return \yii\db\ActiveQuery | ||
| 67 | + */ | ||
| 68 | + public function getAlias() | ||
| 69 | + { | ||
| 70 | + return $this->hasOne(Alias::className(), ['id' => 'alias_id']); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * @return \yii\db\ActiveQuery | ||
| 75 | + */ | ||
| 76 | + public function getDoctor() | ||
| 77 | + { | ||
| 78 | + return $this->hasOne(Doctor::className(), ['id' => 'doctor_id']); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * @return \yii\db\ActiveQuery | ||
| 83 | + */ | ||
| 84 | + public function getLanguage() | ||
| 85 | + { | ||
| 86 | + return $this->hasOne(Language::className(), ['id' => 'language_id']); | ||
| 87 | + } | ||
| 88 | +} |
common/models/Question.php
| @@ -47,7 +47,8 @@ | @@ -47,7 +47,8 @@ | ||
| 47 | ], | 47 | ], |
| 48 | self::SCENARIO_ANSWER => [ | 48 | self::SCENARIO_ANSWER => [ |
| 49 | 'answer', | 49 | 'answer', |
| 50 | - 'status' | 50 | + 'status', |
| 51 | + 'doctor_id' | ||
| 51 | ], | 52 | ], |
| 52 | ] | 53 | ] |
| 53 | ); | 54 | ); |
| @@ -91,6 +92,7 @@ | @@ -91,6 +92,7 @@ | ||
| 91 | 'service_id', | 92 | 'service_id', |
| 92 | 'created_at', | 93 | 'created_at', |
| 93 | 'updated_at', | 94 | 'updated_at', |
| 95 | + 'doctor_id' | ||
| 94 | ], | 96 | ], |
| 95 | 'integer', | 97 | 'integer', |
| 96 | ], | 98 | ], |
| @@ -143,4 +145,9 @@ | @@ -143,4 +145,9 @@ | ||
| 143 | { | 145 | { |
| 144 | return $this->hasOne(Service::className(), [ 'id' => 'service_id' ]); | 146 | return $this->hasOne(Service::className(), [ 'id' => 'service_id' ]); |
| 145 | } | 147 | } |
| 148 | + | ||
| 149 | + public function getDoctor() | ||
| 150 | + { | ||
| 151 | + return $this->hasOne(Doctor::className(), [ 'id' => 'doctor_id' ]); | ||
| 152 | + } | ||
| 146 | } | 153 | } |
console/migrations/m180531_104933_create_doctor_table.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\db\Migration; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * Handles the creation of table `odctor`. | ||
| 7 | + */ | ||
| 8 | +class m180531_104933_create_doctor_table extends Migration | ||
| 9 | +{ | ||
| 10 | + /** | ||
| 11 | + * {@inheritdoc} | ||
| 12 | + */ | ||
| 13 | + public function safeUp() | ||
| 14 | + { | ||
| 15 | + $this->createTable('doctor', [ | ||
| 16 | + 'id' => $this->primaryKey(), | ||
| 17 | + 'service_id' => $this->integer(), | ||
| 18 | + 'status' => $this->boolean(), | ||
| 19 | + 'sort' => $this->integer(), | ||
| 20 | + 'image_id' => $this->integer() | ||
| 21 | + ]); | ||
| 22 | + | ||
| 23 | + $this->addForeignKey('doctor_service_fk', | ||
| 24 | + 'doctor', | ||
| 25 | + 'service_id', | ||
| 26 | + 'service', | ||
| 27 | + 'id', | ||
| 28 | + 'SET NULL', | ||
| 29 | + 'CASCADE'); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * {@inheritdoc} | ||
| 34 | + */ | ||
| 35 | + public function safeDown() | ||
| 36 | + { | ||
| 37 | + $this->dropTable('doctor'); | ||
| 38 | + } | ||
| 39 | +} |
console/migrations/m180531_111128_create_doctor_lang_table.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\db\Migration; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * Handles the creation of table `doctor_lang`. | ||
| 7 | + */ | ||
| 8 | +class m180531_111128_create_doctor_lang_table extends Migration | ||
| 9 | +{ | ||
| 10 | + /** | ||
| 11 | + * {@inheritdoc} | ||
| 12 | + */ | ||
| 13 | + public function safeUp() | ||
| 14 | + { | ||
| 15 | + $this->createTable('doctor_lang', [ | ||
| 16 | + 'language_id' => $this->integer(), | ||
| 17 | + 'alias_id' => $this->integer(), | ||
| 18 | + 'doctor_id' => $this->integer(), | ||
| 19 | + 'name' => $this->string(), | ||
| 20 | + 'position' => $this->string(), | ||
| 21 | + 'description' => $this->text() | ||
| 22 | + ]); | ||
| 23 | + | ||
| 24 | + $this->addPrimaryKey('doctor_lang_pk', 'doctor_lang', ['language_id', 'doctor_id']); | ||
| 25 | + | ||
| 26 | + $this->addForeignKey('doctor_lang_language_fk', | ||
| 27 | + 'doctor_lang', | ||
| 28 | + 'language_id', | ||
| 29 | + 'language', | ||
| 30 | + 'id'); | ||
| 31 | + $this->addForeignKey('doctor_lang_doctor_fk', | ||
| 32 | + 'doctor_lang', | ||
| 33 | + 'doctor_id', | ||
| 34 | + 'doctor', | ||
| 35 | + 'id', | ||
| 36 | + 'CASCADE', | ||
| 37 | + 'CASCADE'); | ||
| 38 | + | ||
| 39 | + $this->addForeignKey('doctor_lang_alias_fk', | ||
| 40 | + 'doctor_lang', | ||
| 41 | + 'alias_id', | ||
| 42 | + 'alias', | ||
| 43 | + 'id', | ||
| 44 | + 'CASCADE', | ||
| 45 | + 'CASCADE'); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * {@inheritdoc} | ||
| 50 | + */ | ||
| 51 | + public function safeDown() | ||
| 52 | + { | ||
| 53 | + $this->dropForeignKey('doctor_lang_language_fk', 'doctor_lang'); | ||
| 54 | + $this->dropForeignKey('doctor_lang_doctor_fk', 'doctor_lang'); | ||
| 55 | + $this->dropForeignKey('doctor_lang_alias_fk', 'doctor_lang'); | ||
| 56 | + $this->dropTable('doctor_lang'); | ||
| 57 | + } | ||
| 58 | +} |
console/migrations/m180531_115620_alter_table_question.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use yii\db\Migration; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * Class m180531_115620_alter_table_question | ||
| 7 | + */ | ||
| 8 | +class m180531_115620_alter_table_question extends Migration | ||
| 9 | +{ | ||
| 10 | + /** | ||
| 11 | + * {@inheritdoc} | ||
| 12 | + */ | ||
| 13 | + public function safeUp() | ||
| 14 | + { | ||
| 15 | + $this->addColumn('question', 'doctor_id', $this->integer()); | ||
| 16 | + | ||
| 17 | + $this->addForeignKey('question_doctor_fk', | ||
| 18 | + 'question', | ||
| 19 | + 'doctor_id', | ||
| 20 | + 'doctor', | ||
| 21 | + 'id', | ||
| 22 | + 'SET NULL', | ||
| 23 | + 'CASCADE'); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * {@inheritdoc} | ||
| 28 | + */ | ||
| 29 | + public function safeDown() | ||
| 30 | + { | ||
| 31 | + $this->dropForeignKey('question_doctor_fk', 'question'); | ||
| 32 | + $this->dropColumn('coctor_id', 'question'); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + /* | ||
| 36 | + // Use up()/down() to run migration code without a transaction. | ||
| 37 | + public function up() | ||
| 38 | + { | ||
| 39 | + | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public function down() | ||
| 43 | + { | ||
| 44 | + echo "m180531_115620_alter_table_question cannot be reverted.\n"; | ||
| 45 | + | ||
| 46 | + return false; | ||
| 47 | + } | ||
| 48 | + */ | ||
| 49 | +} |
frontend/controllers/SiteController.php
| @@ -239,7 +239,7 @@ | @@ -239,7 +239,7 @@ | ||
| 239 | } | 239 | } |
| 240 | } | 240 | } |
| 241 | $dataProvider = new ActiveDataProvider([ | 241 | $dataProvider = new ActiveDataProvider([ |
| 242 | - 'query' => Question::find()->where(['status' => true])->andFilterWhere(['service_id' => $service_id]), | 242 | + 'query' => Question::find()->where(['status' => true])->andFilterWhere(['service_id' => $service_id])->with(['doctor.language']), |
| 243 | 'pagination' => [ | 243 | 'pagination' => [ |
| 244 | 'pageSize' => 10, | 244 | 'pageSize' => 10, |
| 245 | ], | 245 | ], |
frontend/views/service/view.php
| @@ -71,7 +71,7 @@ | @@ -71,7 +71,7 @@ | ||
| 71 | <?php }?> | 71 | <?php }?> |
| 72 | </div> | 72 | </div> |
| 73 | 73 | ||
| 74 | - <div class="style service-links-c-a"><a href="#">Все отзывы</a></div> | 74 | + <div class="style service-links-c-a"><a href="<?=Url::to(['site/comments'])?>">Все отзывы</a></div> |
| 75 | <div class="style service-c-a-btns"> | 75 | <div class="style service-c-a-btns"> |
| 76 | <span class="btn_">Оставить отзыв</span> | 76 | <span class="btn_">Оставить отзыв</span> |
| 77 | </div> | 77 | </div> |
| @@ -91,7 +91,9 @@ | @@ -91,7 +91,9 @@ | ||
| 91 | <div class="style comments-h-autor"><?=$question->name?></div> | 91 | <div class="style comments-h-autor"><?=$question->name?></div> |
| 92 | <div class="style comments-h-text"><?=$question->question?> </div> | 92 | <div class="style comments-h-text"><?=$question->question?> </div> |
| 93 | <div class="service-ansvers-text-wr style"> | 93 | <div class="service-ansvers-text-wr style"> |
| 94 | - <div class="service-ansvers-title">врач-гинеколог <span>Алексей нестеренко</span></div> | 94 | + <?php if ($question->doctor !== null){?> |
| 95 | + <div class="service-ansvers-title"><?=$question->doctor->position?><span><?=$question->doctor->name?></span></div> | ||
| 96 | + <?php }?> | ||
| 95 | <div class="service-ansvers-txt"> | 97 | <div class="service-ansvers-txt"> |
| 96 | <?=$question->answer?> | 98 | <?=$question->answer?> |
| 97 | </div> | 99 | </div> |
| @@ -101,7 +103,7 @@ | @@ -101,7 +103,7 @@ | ||
| 101 | 103 | ||
| 102 | </div> | 104 | </div> |
| 103 | <?php } ?> | 105 | <?php } ?> |
| 104 | - <div class="style service-links-c-a service-links-a"><a href="#">Все вопросы</a></div> | 106 | + <div class="style service-links-c-a service-links-a"><a href="<?=Url::to(['site/questions'])?>">Все вопросы</a></div> |
| 105 | <div class="style service-c-a-btns"> | 107 | <div class="style service-c-a-btns"> |
| 106 | <span class="btn_">Задать вопрос</span> | 108 | <span class="btn_">Задать вопрос</span> |
| 107 | </div> | 109 | </div> |
frontend/views/site/_question.php
| @@ -14,7 +14,9 @@ | @@ -14,7 +14,9 @@ | ||
| 14 | <?php }?> | 14 | <?php }?> |
| 15 | </div> | 15 | </div> |
| 16 | <div class="service-ansvers-text-wr style"> | 16 | <div class="service-ansvers-text-wr style"> |
| 17 | - <div class="service-ansvers-title">врач-гинеколог <span>Алексей нестеренко</span></div> | 17 | + <?php if ($model->doctor !== null){?> |
| 18 | + <div class="service-ansvers-title"><?=$model->doctor->position?> <span><?=$model->doctor->name?></span></div> | ||
| 19 | + <?php }?> | ||
| 18 | <div class="service-ansvers-txt"> | 20 | <div class="service-ansvers-txt"> |
| 19 | <?=$model->answer?> | 21 | <?=$model->answer?> |
| 20 | </div> | 22 | </div> |