Fix forms and reviews

parent fa4327b2
/index.php /index.php
/index-test.php /index-test.php
/uploads/temp/* /uploads/temp/*
\ No newline at end of file /uploads/reviews/*
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace common\components; namespace common\components;
use \yii\db\ActiveRecord; use \yii\db\ActiveRecord;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
class BaseForm extends \yii\widgets\ActiveForm class BaseForm extends \yii\widgets\ActiveForm
{ {
...@@ -137,7 +138,7 @@ JS; ...@@ -137,7 +138,7 @@ JS;
} }
//$config['ActiveForm'] = $config['activeForm']; //$config['ActiveForm'] = $config['activeForm'];
//die(print_r($config['elements'])); //die(print_r($config['elements']));
unset($config['activeForm']); // unset($config['activeForm']);
$config['options'] = []; $config['options'] = [];
//die(print_r(\yii::$app->controller->getAction('captcha'))); //die(print_r(\yii::$app->controller->getAction('captcha')));
//$config['options'][] = $this->errorSummary($model); //$config['options'][] = $this->errorSummary($model);
...@@ -286,11 +287,14 @@ JS; ...@@ -286,11 +287,14 @@ JS;
public function initCustom($config) { public function initCustom($config) {
ob_start(); ob_start();
ob_implicit_flush(false); ob_implicit_flush(false);
$form = ActiveForm::begin([ $form = ActiveForm::begin(ArrayHelper::merge(
'enableAjaxValidation' => true, $config['activeForm'],
'enableClientValidation' => false, [
'validateOnType' => true, 'enableAjaxValidation' => true,
]); 'enableClientValidation' => false,
'validateOnType' => true,
]
));
foreach($config['options'] as $item) { foreach($config['options'] as $item) {
echo $item; echo $item;
} }
......
...@@ -5,14 +5,6 @@ use yii\helpers\Html; ...@@ -5,14 +5,6 @@ use yii\helpers\Html;
return [ return [
'activeForm'=>[ 'activeForm'=>[
'id' => 'block-form', 'id' => 'block-form',
'class' => 'ActiveForm',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
// 'template' => '<div class="form-group">{label}<div class="col-md-9">{input}</div><div class="col-md-9">{error}</div></div>',
'labelOptions' => ['class' => 'col-md-3 control-label'],
],
'enableAjaxValidation' => false,
// 'htmlOptions'=>['class'=>'registr'),
], ],
'elements' => [ 'elements' => [
/*'lang' => [ /*'lang' => [
......
...@@ -5,14 +5,6 @@ use yii\helpers\ArrayHelper; ...@@ -5,14 +5,6 @@ use yii\helpers\ArrayHelper;
return [ return [
'activeForm'=>[ 'activeForm'=>[
'id' => 'module-form', 'id' => 'module-form',
'class' => 'ActiveForm',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
// 'template' => '<div class="form-group">{label}<div class="col-md-9">{input}</div><div class="col-md-9">{error}</div></div>',
'labelOptions' => ['class' => 'col-md-3 control-label'],
],
'enableAjaxValidation' => false,
// 'htmlOptions'=>['class'=>'registr'),
], ],
'elements' => [ 'elements' => [
'name' => ['type' => 'text', 'class' => 'form-control'], 'name' => ['type' => 'text', 'class' => 'form-control'],
......
...@@ -5,14 +5,6 @@ use yii\helpers\ArrayHelper; ...@@ -5,14 +5,6 @@ use yii\helpers\ArrayHelper;
return [ return [
'activeForm'=>[ 'activeForm'=>[
'id' => 'controller-form', 'id' => 'controller-form',
'class' => 'ActiveForm',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
// 'template' => '<div class="form-group">{label}<div class="col-md-9">{input}</div><div class="col-md-9">{error}</div></div>',
'labelOptions' => ['class' => 'col-md-3 control-label'],
],
'enableAjaxValidation' => false,
// 'htmlOptions'=>['class'=>'registr'),
], ],
'elements' => [ 'elements' => [
'content_id' => [ 'content_id' => [
......
...@@ -17,14 +17,6 @@ if(count($blocks)) { ...@@ -17,14 +17,6 @@ if(count($blocks)) {
return [ return [
'activeForm'=>[ 'activeForm'=>[
'id' => 'controller-form', 'id' => 'controller-form',
'class' => 'ActiveForm',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
// 'template' => '<div class="form-group">{label}<div class="col-md-9">{input}</div><div class="col-md-9">{error}</div></div>',
'labelOptions' => ['class' => 'col-md-3 control-label'],
],
'enableAjaxValidation' => false,
// 'htmlOptions'=>['class'=>'registr'),
], ],
'elements' => [ 'elements' => [
'category_id' => [ 'category_id' => [
......
...@@ -11,14 +11,6 @@ use yii\helpers\ArrayHelper; ...@@ -11,14 +11,6 @@ use yii\helpers\ArrayHelper;
return [ return [
'activeForm'=>[ 'activeForm'=>[
'id' => 'faq-form', 'id' => 'faq-form',
'class' => 'ActiveForm',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
// 'template' => '<div class="form-group">{label}<div class="col-md-9">{input}</div><div class="col-md-9">{error}</div></div>',
'labelOptions' => ['class' => 'col-md-3 control-label'],
],
'enableAjaxValidation' => false,
// 'htmlOptions'=>['class'=>'registr'),
], ],
'elements' => [ 'elements' => [
'lang' => [ 'lang' => [
......
...@@ -8,6 +8,7 @@ use common\modules\reviews\models\SearchReviews; ...@@ -8,6 +8,7 @@ use common\modules\reviews\models\SearchReviews;
use common\components\AdminController; use common\components\AdminController;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\web\UploadedFile;
/** /**
* ReviewAdminController implements the CRUD actions for Reviews model. * ReviewAdminController implements the CRUD actions for Reviews model.
...@@ -109,9 +110,21 @@ class ReviewAdminController extends AdminController ...@@ -109,9 +110,21 @@ class ReviewAdminController extends AdminController
'Добавить отзыв' 'Добавить отзыв'
]; ];
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->validate())
{
if($model->file)
{
$model->file = UploadedFile::getInstance($model, 'file');
$model->upload();
}
$model->save();
return $this->redirect(['manage']); return $this->redirect(['manage']);
} else { }
else
{
//die(print_r($model->errors)); //die(print_r($model->errors));
$form = new \common\components\BaseForm('/common/modules/reviews/forms/ReviewForm', $model); $form = new \common\components\BaseForm('/common/modules/reviews/forms/ReviewForm', $model);
return $this->render('create', [ return $this->render('create', [
...@@ -131,15 +144,32 @@ class ReviewAdminController extends AdminController ...@@ -131,15 +144,32 @@ class ReviewAdminController extends AdminController
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
\yii::$app->controller->page_title = 'Редактировать отзыв <small>'.$model->user->email.'</small>'; \yii::$app->controller->page_title = 'Редактировать отзыв';
\yii::$app->controller->breadcrumbs = [ \yii::$app->controller->breadcrumbs = [
['Список отзывов' => '/reviews/review-admin/manage'], ['Список отзывов' => '/reviews/review-admin/manage'],
'Редактировать отзыв' 'Редактировать отзыв'
]; ];
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->validate())
{
if($model->file)
{
if($model->photo)
{
$model->deletePhoto();
}
$model->file = UploadedFile::getInstance($model, 'file');
$model->upload();
}
$model->save();
return $this->redirect(['manage']); return $this->redirect(['manage']);
} else { }
else
{
$form = new \common\components\BaseForm('/common/modules/reviews/forms/ReviewForm', $model); $form = new \common\components\BaseForm('/common/modules/reviews/forms/ReviewForm', $model);
return $this->render('update', [ return $this->render('update', [
'model' => $model, 'model' => $model,
......
...@@ -4,15 +4,6 @@ use yii\helpers\ArrayHelper; ...@@ -4,15 +4,6 @@ use yii\helpers\ArrayHelper;
return [ return [
'activeForm'=>[ 'activeForm'=>[
'id' => 'answer-form',
'class' => 'ActiveForm',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
// 'template' => '<div class="form-group">{label}<div class="col-md-9">{input}</div><div class="col-md-9">{error}</div></div>',
'labelOptions' => ['class' => 'col-md-3 control-label'],
],
'enableAjaxValidation' => false,
// 'htmlOptions'=>['class'=>'registr'),
], ],
'elements' => [ 'elements' => [
'admin_id' => [ 'admin_id' => [
......
...@@ -6,33 +6,32 @@ use common\modules\reviews\models\Reviews; ...@@ -6,33 +6,32 @@ use common\modules\reviews\models\Reviews;
return [ return [
'activeForm'=>[ 'activeForm'=>[
'id' => 'module-form', 'options' => [
'class' => 'ActiveForm', 'enctype' => 'multipart/form-data'
'options' => ['class' => 'form-horizontal'], ],
'fieldConfig' => [
// 'template' => '<div class="form-group">{label}<div class="col-md-9">{input}</div><div class="col-md-9">{error}</div></div>',
'labelOptions' => ['class' => 'col-md-3 control-label'],
],
'enableAjaxValidation' => false, 'enableAjaxValidation' => false,
// 'htmlOptions'=>['class'=>'registr'),
], ],
'elements' => [ 'elements' => [
'title' => [
'type' => 'text',
],
'lang' => [ 'lang' => [
'type' => 'dropdownlist', 'type' => 'dropdownlist',
'items' => ArrayHelper::map(\common\modules\languages\models\Languages::find()->all(),'code','name') 'items' => ArrayHelper::map(\common\modules\languages\models\Languages::find()->all(),'code','name')
], ],
'file' => ['type' => 'file', 'class' => 'form-control',],
'date' => ['type' => 'date', 'class' => 'form-control',], 'date' => ['type' => 'date', 'class' => 'form-control',],
'text' => ['type' => 'textarea', 'class' => 'form-control'], 'text' => ['type' => 'textarea', 'class' => 'form-control'],
'<a id="doAnswer" style="cursor: pointer;" onclick="$(this).next().next().slideToggle(); return false;">Ответить</a>' . // '<a id="doAnswer" style="cursor: pointer;" onclick="$(this).next().next().slideToggle(); return false;">Ответить</a>' .
'<br><div style="display: none;">', // '<br><div style="display: none;">',
'admin_id' => [ // 'admin_id' => [
'type' => 'dropdownlist', // 'type' => 'dropdownlist',
'items' => ArrayHelper::map(\common\modules\users\models\User::find()->all(),'id','fio'), // 'items' => ArrayHelper::map(\common\modules\users\models\User::find()->all(),'id','fio'),
'empty' => 'Оператор', // 'empty' => 'Оператор',
], // ],
'answer' => ['type' => 'textarea', 'class' => 'form-control'], // 'answer' => ['type' => 'textarea', 'class' => 'form-control'],
'</div>', // '</div>',
'state' => [ 'state' => [
'type' => 'dropdownlist', 'type' => 'dropdownlist',
'items' => ['active','hidden'], 'items' => ['active','hidden'],
......
...@@ -34,6 +34,10 @@ use Yii; ...@@ -34,6 +34,10 @@ use Yii;
*/ */
class Reviews extends \common\components\ActiveRecordModel class Reviews extends \common\components\ActiveRecordModel
{ {
public $file;
const TEMP_FOLDER = '/uploads/reviews/';
private static $rate = [ private static $rate = [
'rate_usability' => [ 'rate_usability' => [
0 => 'Не определено', 0 => 'Не определено',
...@@ -93,6 +97,7 @@ class Reviews extends \common\components\ActiveRecordModel ...@@ -93,6 +97,7 @@ class Reviews extends \common\components\ActiveRecordModel
return [ return [
[['text', 'state', 'date', 'notification_send', 'show_in_module'], 'required'], [['text', 'state', 'date', 'notification_send', 'show_in_module'], 'required'],
[['admin_id', 'priority', 'notification_send', 'order', 'cat_id', 'show_in_module', 'rate_usability', 'rate_loyality', 'rate_profit'], 'integer'], [['admin_id', 'priority', 'notification_send', 'order', 'cat_id', 'show_in_module', 'rate_usability', 'rate_loyality', 'rate_profit'], 'integer'],
[['file'], 'file', 'skipOnEmpty' => true, 'extensions' => 'png, jpg, jpeg, gif'],
[['text', 'state', 'attendant_products'], 'string'], [['text', 'state', 'attendant_products'], 'string'],
[['admin_id'], 'adminIdValidate'], [['admin_id'], 'adminIdValidate'],
[['date', 'answer', 'good', 'bad', 'date_create', 'notification_date', 'rate_usability', 'rate_loyality', 'rate_profit', 'title', 'order'], 'safe'], [['date', 'answer', 'good', 'bad', 'date_create', 'notification_date', 'rate_usability', 'rate_loyality', 'rate_profit', 'title', 'order'], 'safe'],
...@@ -126,6 +131,7 @@ class Reviews extends \common\components\ActiveRecordModel ...@@ -126,6 +131,7 @@ class Reviews extends \common\components\ActiveRecordModel
'good' => Yii::t('reviews', 'Понравилось'), 'good' => Yii::t('reviews', 'Понравилось'),
'bad' => Yii::t('reviews', 'Не понравилось'), 'bad' => Yii::t('reviews', 'Не понравилось'),
'photo' => Yii::t('reviews', 'Фото'), 'photo' => Yii::t('reviews', 'Фото'),
'file' => Yii::t('reviews', 'Фото'),
'state' => Yii::t('reviews', 'Состояние'), 'state' => Yii::t('reviews', 'Состояние'),
'date' => Yii::t('reviews', 'Дата'), 'date' => Yii::t('reviews', 'Дата'),
'date_create' => Yii::t('reviews', 'Создана'), 'date_create' => Yii::t('reviews', 'Создана'),
...@@ -197,4 +203,36 @@ class Reviews extends \common\components\ActiveRecordModel ...@@ -197,4 +203,36 @@ class Reviews extends \common\components\ActiveRecordModel
return parent::beforeSave($insert); return parent::beforeSave($insert);
} }
private function getPath()
{
return Yii::getAlias('@webroot') . self::TEMP_FOLDER;
}
public function upload()
{
if($this->validate())
{
if(!file_exists($this->getPath()))
{
mkdir($this->getPath(), 0777, true);
}
$this->photo = $this->getPath() . date('dmYHis-') . uniqid() . '.' . $this->file->extension;
$this->file->saveAs($this->photo);
return true;
}
else
{
return false;
}
}
public function deletePhoto()
{
if(file_exists($this->getPath() . $this->photo))
{
unlink($this->getPath() . $this->photo);
}
}
} }
...@@ -28,23 +28,7 @@ use yii\grid\GridView; ...@@ -28,23 +28,7 @@ use yii\grid\GridView;
// 'id', // 'id',
// 'lang', // 'lang',
[ 'title',
'attribute' => 'user_id',
'format' => 'raw',
'value' => function($data){
if(!$data->hasComment()){
$add = Html::a('Ответить',Url::toRoute(['updateanswer', 'id'=>$data->id]), ['class' => 'btn btn-primary m-r-5 m-b-5']);
}
else {
$add = Html::a('Редактировать',Url::toRoute(['updateanswer', 'id'=>$data->id]), ['class' => 'btn btn-primary m-r-5 m-b-5']);
}
if(!empty($data->user))
return $data->user->fullName . '<br >' . $add;
return 'Удален ' . '<br >' . $add;
}
],
//'title',
[ [
'attribute' => 'text:ntext', 'attribute' => 'text:ntext',
'header' => 'Отзыв', 'header' => 'Отзыв',
......
...@@ -16,11 +16,6 @@ $buttons = array( ...@@ -16,11 +16,6 @@ $buttons = array(
return array( return array(
'activeForm' => array( 'activeForm' => array(
'id' => 'testing-mistake-form', 'id' => 'testing-mistake-form',
//'enableAjaxValidation' => true,
//'clientOptions' => array(
// 'validateOnSubmit' => true,
// 'validateOnChange' => true
//)
), ),
'elements' => array( 'elements' => array(
//'passing_id' => array('type' => 'text'), //'passing_id' => array('type' => 'text'),
......
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160126_110636_fix_review_table extends Migration
{
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql')
{
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
}
$this->addColumn('reviews', 'title', Schema::TYPE_STRING . '(255) AFTER `user_id`');
}
public function safeDown()
{
$this->dropColumn('reviews', 'title');
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment