From fce22ac2e5793b0b57b83b34607d38579450cf7c Mon Sep 17 00:00:00 2001 From: Anastasia Date: Fri, 1 Jun 2018 12:05:40 +0300 Subject: [PATCH] - visits --- backend/controllers/VisitController.php | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/layouts/menu_items.php | 5 +++++ backend/views/visit/_form.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ backend/views/visit/update.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ common/config/main.php | 2 +- common/models/Visit.php | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ console/migrations/m180601_065055_create_visit_table.php | 35 +++++++++++++++++++++++++++++++++++ frontend/config/main.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/views/layouts/main.php | 59 ++++++++++++++++++++++++++++++++++------------------------- frontend/views/service/view.php | 5 +++++ frontend/web/js/script.js | 6 +++--- 11 files changed, 548 insertions(+), 29 deletions(-) create mode 100644 backend/controllers/VisitController.php create mode 100644 backend/views/visit/_form.php create mode 100644 backend/views/visit/update.php create mode 100644 common/models/Visit.php create mode 100644 console/migrations/m180601_065055_create_visit_table.php diff --git a/backend/controllers/VisitController.php b/backend/controllers/VisitController.php new file mode 100644 index 0000000..21a24fe --- /dev/null +++ b/backend/controllers/VisitController.php @@ -0,0 +1,190 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => [ 'POST' ], + ], + ], + 'access' => [ + 'class' => AccessControl::className(), + 'rules' => [ + [ + 'allow' => true, + 'roles' => [ '@' ], + ], + ], + ], + ]; + } + public function actions() + { + return [ + 'index' => [ + 'class' => Index::className(), + 'columns' => [ + 'name' => [ + 'type' => Index::ACTION_COL, + ], + 'email' => [ + 'type' => Index::STRING_COL + ], + 'phone' => [ + 'type' => Index::STRING_COL + ], + 'status' => [ + 'type' => Index::STATUS_COL, + ], + 'created_at' => [ + 'type' => Index::DATETIME_COL, + ] + ], + 'model' => Visit::className(), + 'hasLanguage' => false, + 'enableMassDelete' => true, + 'modelPrimaryKey' => 'id', + 'defaultSort' => [ + 'created_at' => 'DESC', + ], + 'create' => false, + ], + 'view' => [ + 'class' => View::className(), + 'model' => Visit::className(), + 'hasAlias' => false, + 'hasGallery' => false, + + 'languageFields' => [ + ], + 'fields' => [ + [ + 'name' => 'name', + 'type' => Form::STRING, + ], + [ + 'name' => 'email', + 'type' => Form::STRING, + ], + [ + 'name' => 'phone', + 'type' => Form::STRING, + ], + [ + 'name' => 'message', + 'type' => Form::TEXTAREA, + ], + [ + 'name' => 'created_at', + 'type' => Form::STRING, + ], + + ], + ], + 'delete' => [ + 'class' => Delete::className(), + ], + ]; + } + public function actionUpdate($id) + { + $model = $this->findModel($id); + + $model->status = true; + $model->save(false, [ 'status' ]); + + if ($model->load(\Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); + } else { + return $this->render( + 'update', + [ + 'model' => $model, + ] + ); + } + } + public function findModel($id) + { + $model = Visit::find() + ->where([ 'id' => $id ]) + ->one(); + if ($model !== null) { + return $model; + } else { + throw new NotFoundHttpException('The requested page does not exist.'); + } + } + + public function newModel() + { + return new Visit(); + } + + public function deleteModel($id) + { + $category = Visit::find() + ->where( + [ + 'id' => $id, + ] + ) + ->one(); + + return $category->delete(); + } + + protected static function fieldsConfig() + { + return [ + 'model' => Visit::className(), + 'hasAlias' => false, + 'hasGallery' => false, + 'languageFields' => [ + ], + [ + 'name' => 'name', + 'type' => Form::STRING, + ], + [ + 'name' => 'email', + 'type' => Form::STRING, + ], + [ + 'name' => 'phone', + 'type' => Form::STRING, + ], + [ + 'name' => 'message', + 'type' => Form::TEXTAREA, + ], + [ + 'name' => 'updated_at', + 'type' => Form::STRING, + ], + ]; + } + + + } diff --git a/backend/views/layouts/menu_items.php b/backend/views/layouts/menu_items.php index b7d42f1..75ccf62 100755 --- a/backend/views/layouts/menu_items.php +++ b/backend/views/layouts/menu_items.php @@ -70,6 +70,11 @@ 'url' => [ '/doctor/index' ], ], + [ + 'label' => \Yii::t('app', 'Записи на прием'), + 'url' => [ '/visit/index' ], + + ], ], ], diff --git a/backend/views/visit/_form.php b/backend/views/visit/_form.php new file mode 100644 index 0000000..5a4b0ca --- /dev/null +++ b/backend/views/visit/_form.php @@ -0,0 +1,48 @@ + + +
+ + + + field($model, 'name') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'email') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'phone') + ->textInput([ 'maxlength' => true ]) ?> + + field($model, 'message') + ->textarea([ 'rows' => 6 ]) ?> + + field($model, 'status') + ->checkbox( + [ + 'class' => 'flat', + ] + ) ?> + entity !== null){ + $entity = call_user_func(array($model->entity, 'find'))->where(['id' => $model->entity_id])->one(); + echo ("

".$entity->title."

"); + } + ?> +
+ isNewRecord ? Yii::t('core', 'Create') : Yii::t('core', 'Update'), + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] + ) ?> +
+ + + +
diff --git a/backend/views/visit/update.php b/backend/views/visit/update.php new file mode 100644 index 0000000..3a11f82 --- /dev/null +++ b/backend/views/visit/update.php @@ -0,0 +1,45 @@ +title = Yii::t( + 'core', + 'Update {modelClass}: ', + [ + 'modelClass' => 'Visit', + ] + ) . $model->name; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => Yii::t('core', 'Visits'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => $model->name, + 'url' => [ + 'view', + 'id' => $model->id, + ], + ]; + $this->params[ 'breadcrumbs' ][] = Yii::t('core', 'Update'); +?> + + $this->title, + 'options' => [ + 'class' => 'x_panel feedback-update', + ], + ] +) ?> + +render( + '_form', + [ + 'model' => $model, + ] +) ?> + + diff --git a/common/config/main.php b/common/config/main.php index efd2a4d..1e146bf 100644 --- a/common/config/main.php +++ b/common/config/main.php @@ -27,7 +27,7 @@ ], 'components' => [ 'cache' => [ - 'class' => 'yii\caching\FileCache', + 'class' => 'yii\caching\DummyCache', ], 'i18n' => [ 'translations' => [ diff --git a/common/models/Visit.php b/common/models/Visit.php new file mode 100644 index 0000000..123bda0 --- /dev/null +++ b/common/models/Visit.php @@ -0,0 +1,112 @@ + TimestampBehavior::className(), + 'updatedAtAttribute' => false, + ], + ]; + } + /** + * {@inheritdoc} + */ + public static function tableName() + { + return 'visit'; + } + + /** + * {@inheritdoc} + */ + public function rules() + { + return [ + [ + [ + 'phone' + ], + 'required' + ], + [ + [ + 'status' + ], + 'boolean' + ], + [ + [ + 'email' + ], + 'email' + ], + [ + [ 'message' ], + 'string', + ], + [ + [ 'entity_id' ], + 'default', + 'value' => null, + ], + [ + [ 'entity_id', 'created_at' ], + 'integer', + ], + [ + [ + 'name', + 'phone', + 'entity', + 'email' + ], + 'string', + 'max' => 255, + ], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('app', 'ID'), + 'name' => Yii::t('app', 'Name'), + 'phone' => Yii::t('app', 'Phone'), + 'message' => Yii::t('app', 'Message'), + 'entity' => Yii::t('app', 'Entity'), + 'entity_id' => Yii::t('app', 'Entity ID'), + 'email' => Yii::t('app', 'Email'), + ]; + } + + public function getEntity(){ + if ($this->entity !== null){ + return $this->hasOne($this->entity, ['id' => 'entity_id']); + } + return null; + } + } diff --git a/console/migrations/m180601_065055_create_visit_table.php b/console/migrations/m180601_065055_create_visit_table.php new file mode 100644 index 0000000..2b05714 --- /dev/null +++ b/console/migrations/m180601_065055_create_visit_table.php @@ -0,0 +1,35 @@ +createTable('visit', [ + 'id' => $this->primaryKey(), + 'name' => $this->string(), + 'phone' => $this->string(), + 'message' => $this->text(), + 'entity' => $this->string(), + 'entity_id' => $this->integer(), + 'email' => $this->string(), + 'status' => $this->boolean(), + 'created_at'=> $this->integer() + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('visit'); + } +} diff --git a/frontend/config/main.php b/frontend/config/main.php index 20c8701..b02beef 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -188,6 +188,76 @@ }', ], + + 'visit' => [ + 'class' => 'artbox\core\forms\Module', + 'activeRecord' => "common\models\Visit", + 'attributes' => [ + 'name', + 'phone', + 'email', + 'message', + + 'entity', + 'entity_id' + ], + 'rules' => [ + [ + [ + 'phone', + ], + 'required', + ] + ], + 'labels' => [ + 'name' => 'ФИО', + 'email' => 'Email', + 'phone' => 'Телефон', + 'message' => 'Сообщение', + 'entity_id' => false, + 'entity' => false + ], + + 'inputOptions' => [ + 'entity' => [ + 'type' => 'hiddenInput' + ], + 'entity_id' => [ + 'type' => 'hiddenInput' + ], + 'name' => [ + 'template' => '
{input}
' + ], + 'email' => [ + 'template' => '
{input}
' + ], + 'phone' => [ + 'template' => '
{input}
', + 'options' => [ + 'placeholder' => '(0__)___-__-__' + ] + ], + 'message' => [ + 'type' => 'textarea', + 'options' => ['cols' => 30, 'rows'=> 10], + 'template' => '
{input}
' + ], + ], + 'buttonTemplate' => '
{button}
Закрыть окно
', + 'buttonOptions' => [], + 'buttonContent' => 'Отправить', + 'sendEmail' => false, + 'ajax' => true, + 'formId' => 'visit-form', + 'scenario' => 'default', + 'successCallback' => 'function (data) { + document.getElementById("visit-form").reset(); + var data = $("#visit-form").data(\'yiiActiveForm\'); + data.validated = false; + success(); + }', + + ], ], 'components' => [ 'assetManager' => [ diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index e2994dc..2799dec 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -18,6 +18,7 @@ use artbox\core\seo\widgets\SeoBreadcrumbs; use common\models\Service; use common\models\Settings; + use common\models\Visit; use frontend\assets\AppAsset; use frontend\assets\SliderAsset; use frontend\widgets\ArtboxModalWidget; @@ -408,31 +409,39 @@ ArtboxModalWidget::end(); ?> - + getModule('visit'); + if (isset($this->params['entity']) and isset($this->params['entity_id'])){ + $moduleVisit->inputOptions = array_merge($moduleVisit->inputOptions, ['entity' => [ + 'type' => 'hiddenInput', + 'options' => ['value' => $this->params['entity']], + ], + 'entity_id' => [ + 'type' => 'hiddenInput', + 'options' => ['value' => $this->params['entity_id']], + ] + ]); + } + ArtboxModalWidget::begin([ + 'modalTagOptions' => [ + 'id' => 'write-to' + ], + 'titleTagOptions' => [ + 'class' => 'style form-title' + ], + 'headerText' => \Yii::t('app', 'Записаться на прием'), + 'closeTagButton' => 'span', + 'closeTagContent' => '', + 'closeButtonOptions' => [ + 'id' => 'modal_close' + ] + ]); + + $moduleVisit->renderForm($this); + + ArtboxModalWidget::end(); + ?>