Reviews

parent 1929e5e0
...@@ -134,7 +134,7 @@ JS; ...@@ -134,7 +134,7 @@ JS;
if (is_string($config)) if (is_string($config))
{ {
$config = self::getFormConfig($config); $config = self::getFormConfig($config, $model);
} }
//$config['ActiveForm'] = $config['activeForm']; //$config['ActiveForm'] = $config['activeForm'];
//die(print_r($config['elements'])); //die(print_r($config['elements']));
...@@ -288,12 +288,12 @@ JS; ...@@ -288,12 +288,12 @@ JS;
ob_start(); ob_start();
ob_implicit_flush(false); ob_implicit_flush(false);
$form = ActiveForm::begin(ArrayHelper::merge( $form = ActiveForm::begin(ArrayHelper::merge(
$config['activeForm'],
[ [
'enableAjaxValidation' => true, 'enableAjaxValidation' => true,
'enableClientValidation' => false, 'enableClientValidation' => false,
'validateOnType' => true, 'validateOnType' => true,
] ],
$config['activeForm']
)); ));
foreach($config['options'] as $item) { foreach($config['options'] as $item) {
echo $item; echo $item;
...@@ -312,11 +312,9 @@ JS; ...@@ -312,11 +312,9 @@ JS;
list($module, $form) = explode(".", $alias, 2); list($module, $form) = explode(".", $alias, 2);
return "application.modules.{$module}.forms.{$form}"; return "application.modules.{$module}.forms.{$form}";
} }
/*public function render*/
// Убран static // Убран static
public function getFormConfig($alias) public function getFormConfig($alias, $model)
{ {
if (is_string($alias)) if (is_string($alias))
{ {
...@@ -329,58 +327,6 @@ JS; ...@@ -329,58 +327,6 @@ JS;
} }
} }
/*public function __toString()
{
try
{
$cs = Yii::app()->clientScript;
if (!($this->parent instanceof self))
{
//$id = $this->activeForm['id'];
if ($this->side == 'client')
{
// $cs
// ->registerScriptFile('/js/plugins/clientForm/inFieldLabel/jquery.infieldlabel.js')
// ->registerScriptFile('/js/plugins/clientForm/clientForm.js')
// ->registerCssFile('/js/plugins/clientForm/form.css')->registerScript(
// $id . '_baseForm', "$('#{$id}').clientForm()");
}
else
{
$cs->registerScriptFile('/js/admin/admin_form.js')
->registerScriptFile('/js/admin/admin_form.js')
->registerScriptFile('/js/plugins/adminForm/buttonSet.js')
->registerScriptFile('/js/plugins/adminForm/tooltips/jquery.atooltip.js')
->registerCssFile('/js/plugins/adminForm/tooltips/atooltip.css')
->registerScriptFile('/js/plugins/adminForm/chosen/chosen.jquery.js')
->registerCssFile('/js/plugins/adminForm/chosen/chosen.css');
;
}
}
if ($this->_clear)
{
$cs->registerScript('clearForm', '$(function()
{
$(":input","#' . $this->activeForm['id'] . '")
.not(":button, :submit, :reset, :hidden")
.val("")
.removeAttr("checked")
.removeAttr("selected");
})');
}
return parent::__toString();
} catch (Exception $e)
{
Yii::app()->handleException($e);
}
}*/
public function renderBody() public function renderBody()
{ {
$output = parent::renderBody(); $output = parent::renderBody();
......
...@@ -110,15 +110,17 @@ class ReviewAdminController extends AdminController ...@@ -110,15 +110,17 @@ class ReviewAdminController extends AdminController
'Добавить отзыв' 'Добавить отзыв'
]; ];
if ($model->load(Yii::$app->request->post()) && $model->validate()) $model->load(Yii::$app->request->post());
$model->image = UploadedFile::getInstance($model, 'image');
if (Yii::$app->request->isPost && $model->validate())
{ {
if($model->file) if($model->image)
{ {
$model->file = UploadedFile::getInstance($model, 'file');
$model->upload(); $model->upload();
$model->image = null;
} }
$model->save(); $model->save();
return $this->redirect(['manage']); return $this->redirect(['manage']);
...@@ -150,20 +152,22 @@ class ReviewAdminController extends AdminController ...@@ -150,20 +152,22 @@ class ReviewAdminController extends AdminController
'Редактировать отзыв' 'Редактировать отзыв'
]; ];
if ($model->load(Yii::$app->request->post()) && $model->validate()) $model->load(Yii::$app->request->post());
$model->image = UploadedFile::getInstance($model, 'image');
if (Yii::$app->request->isPost && $model->validate())
{ {
if($model->file) if($model->image)
{ {
if($model->photo) if($model->photo)
{ {
$model->deletePhoto(); $model->deletePhoto();
} }
$model->file = UploadedFile::getInstance($model, 'file');
$model->upload(); $model->upload();
$model->image = null;
} }
$model->save(); $model->save();
return $this->redirect(['manage']); return $this->redirect(['manage']);
......
...@@ -9,7 +9,6 @@ return [ ...@@ -9,7 +9,6 @@ return [
'options' => [ 'options' => [
'enctype' => 'multipart/form-data' 'enctype' => 'multipart/form-data'
], ],
'enableAjaxValidation' => false,
], ],
'elements' => [ 'elements' => [
'title' => [ 'title' => [
...@@ -19,7 +18,8 @@ return [ ...@@ -19,7 +18,8 @@ return [
'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',], ($model->photo?Html::img(Reviews::PHOTO_FOLDER . $model->photo):''),
'image' => ['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>' .
......
...@@ -34,9 +34,9 @@ use Yii; ...@@ -34,9 +34,9 @@ use Yii;
*/ */
class Reviews extends \common\components\ActiveRecordModel class Reviews extends \common\components\ActiveRecordModel
{ {
public $file; public $image;
const TEMP_FOLDER = '/uploads/reviews/'; const PHOTO_FOLDER = '/uploads/reviews/';
private static $rate = [ private static $rate = [
'rate_usability' => [ 'rate_usability' => [
...@@ -95,16 +95,15 @@ class Reviews extends \common\components\ActiveRecordModel ...@@ -95,16 +95,15 @@ class Reviews extends \common\components\ActiveRecordModel
public function rules() public function rules()
{ {
return [ return [
[['text', 'state', 'date', 'notification_send', 'show_in_module'], 'required'], [['text', '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'], [['image'], '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', 'photo', 'state', 'video'], 'safe'],
[['lang'], 'string', 'max' => 2], [['lang'], 'string', 'max' => 2],
[['title'], 'string', 'max' => 250], [['title'], 'string', 'max' => 250],
[['photo'], 'string', 'max' => 50], [['email', 'video'], 'string', 'max' => 255]
[['email'], 'string', 'max' => 255]
]; ];
} }
...@@ -131,7 +130,7 @@ class Reviews extends \common\components\ActiveRecordModel ...@@ -131,7 +130,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', 'Фото'), 'image' => 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', 'Создана'),
...@@ -206,20 +205,20 @@ class Reviews extends \common\components\ActiveRecordModel ...@@ -206,20 +205,20 @@ class Reviews extends \common\components\ActiveRecordModel
private function getPath() private function getPath()
{ {
return Yii::getAlias('@webroot') . self::TEMP_FOLDER; return Yii::getAlias('@webroot') . self::PHOTO_FOLDER;
} }
public function upload() public function upload()
{ {
if($this->validate()) if ($this->validate())
{ {
if(!file_exists($this->getPath())) if(!file_exists($this->getPath()))
{ {
mkdir($this->getPath(), 0777, true); mkdir($this->getPath(), 0777, true);
} }
$this->photo = $this->getPath() . date('dmYHis-') . uniqid() . '.' . $this->file->extension; $this->photo = date('dmYHis-') . uniqid() . '.' . $this->image->extension;
$this->file->saveAs($this->photo); $this->image->saveAs($this->getPath() . $this->photo);
return true; return true;
} }
else else
......
...@@ -40,7 +40,7 @@ use yii\helpers\Html; ...@@ -40,7 +40,7 @@ use yii\helpers\Html;
</ol> </ol>
<span style="color: red;">Важно!</span> Не используйте клавишу ENTER для перевода строки при заполнении шаблона. Если это необходимо, пользуйтесь вместо этого тегом <strong><span style="color: red">&lt;br&gt;</span></strong>. <span style="color: red;">Важно!</span> Не используйте клавишу ENTER для перевода строки при заполнении шаблона. Если это необходимо, пользуйтесь вместо этого тегом <strong><span style="color: red">&lt;br&gt;</span></strong>.
<div class="message info">Внимание! Для правильной работы модуля CSV-импорта необходимо корректно заполнять шаблон. Любое отхождение от шаблона (пустая строка, добавленный столбец) может нарушить работу данной системы.</div> <div class="message info">Внимание! Для правильной работы модуля XLS-импорта необходимо корректно заполнять шаблон. Любое отхождение от шаблона (пустая строка, добавленный столбец) может нарушить работу данной системы.</div>
<hr> <hr>
......
...@@ -13,11 +13,11 @@ class m160126_110636_fix_review_table extends Migration ...@@ -13,11 +13,11 @@ class m160126_110636_fix_review_table extends Migration
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
} }
$this->addColumn('reviews', 'title', Schema::TYPE_STRING . '(255) AFTER `user_id`'); $this->addColumn('reviews', 'video', Schema::TYPE_STRING . '(255) AFTER `photo`');
} }
public function safeDown() public function safeDown()
{ {
$this->dropColumn('reviews', 'title'); $this->dropColumn('reviews', 'video');
} }
} }
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