From cc76819bdb384876aa38d32a27e68efac600037c Mon Sep 17 00:00:00 2001 From: noumo Date: Sun, 17 May 2015 02:11:53 +0300 Subject: [PATCH] 0.9a rc --- components/ApiObject.php | 6 +- components/CategoryController.php | 22 +++-- components/CategoryModel.php | 50 +++++----- components/Controller.php | 15 ++- controllers/AdminsController.php | 2 +- helpers/Data.php | 5 + helpers/Image.php | 19 +--- helpers/Mail.php | 29 ++++++ media/css/admin.css | 2 +- messages/ru/admin.php | 1 + migrations/m000000_000000_install.php | 29 ++++-- models/Photo.php | 2 +- modules/article/ArticleModule.php | 1 + modules/article/api/Article.php | 72 +++++++++++++-- modules/article/api/ArticleObject.php | 21 +++++ modules/article/api/CategoryObject.php | 10 +- modules/article/api/PhotoObject.php | 27 ++++++ .../article/controllers/ItemsController.php | 33 ++++++- modules/article/models/Item.php | 12 +-- modules/article/views/items/_form.php | 7 +- modules/article/views/items/_menu.php | 8 +- modules/article/views/items/_submenu.php | 12 +++ modules/article/views/items/edit.php | 4 +- modules/article/views/items/index.php | 10 ++ modules/article/views/items/photos.php | 10 ++ modules/carousel/controllers/AController.php | 2 +- modules/carousel/models/Carousel.php | 2 +- modules/carousel/views/a/_form.php | 2 +- modules/catalog/api/Catalog.php | 61 ++++++++++-- modules/catalog/api/CategoryObject.php | 78 ++++++++++++++-- modules/catalog/api/ItemObject.php | 37 ++++---- modules/catalog/api/PhotoObject.php | 11 ++- modules/catalog/controllers/AController.php | 2 +- .../catalog/controllers/ItemsController.php | 22 ++++- modules/catalog/messages/ru/admin.php | 3 + modules/catalog/models/Category.php | 18 +++- modules/catalog/models/Item.php | 58 ++++++++++-- modules/catalog/models/ItemData.php | 17 ++++ modules/catalog/views/items/_form.php | 9 +- modules/catalog/views/items/index.php | 10 ++ modules/faq/controllers/AController.php | 2 +- modules/faq/views/a/_form.php | 4 +- modules/feedback/FeedbackModule.php | 11 ++- modules/feedback/api/Feedback.php | 19 ++-- modules/feedback/controllers/AController.php | 50 +++------- .../feedback/controllers/SendController.php | 6 +- modules/feedback/mail/en/answer.php | 11 +++ modules/feedback/mail/en/new_feedback.php | 7 ++ modules/feedback/mail/ru/answer.php | 11 +++ modules/feedback/mail/ru/new_feedback.php | 9 ++ modules/feedback/messages/ru/admin.php | 5 +- modules/feedback/models/Feedback.php | 35 ++++++- modules/feedback/views/a/_menu.php | 2 +- modules/feedback/views/a/index.php | 2 +- modules/feedback/views/a/view.php | 14 +-- modules/file/api/File.php | 8 +- modules/file/controllers/AController.php | 2 +- modules/file/models/File.php | 2 +- modules/file/views/a/_form.php | 2 +- modules/gallery/GalleryModule.php | 11 +-- modules/gallery/api/AlbumObject.php | 10 +- modules/gallery/api/Gallery.php | 92 ++++++++----------- modules/gallery/api/PhotoObject.php | 12 ++- modules/gallery/models/Category.php | 26 ++++++ modules/gallery/views/a/_submenu.php | 2 +- modules/gallery/views/a/photos.php | 3 +- modules/guestbook/api/Guestbook.php | 28 ++---- modules/guestbook/controllers/AController.php | 2 +- .../guestbook/controllers/SendController.php | 5 +- modules/guestbook/mail/ru/new_post.php | 4 +- modules/guestbook/messages/ru/api.php | 6 -- modules/guestbook/models/Guestbook.php | 44 ++++----- modules/guestbook/views/a/_menu.php | 2 +- modules/news/NewsModule.php | 3 +- modules/news/api/News.php | 30 ++++-- modules/news/api/NewsObject.php | 21 +++++ modules/news/api/PhotoObject.php | 27 ++++++ modules/news/controllers/AController.php | 30 +++++- modules/news/models/News.php | 16 ++-- modules/news/views/a/_form.php | 14 +-- modules/news/views/a/_menu.php | 2 +- modules/news/views/a/_submenu.php | 12 +++ modules/news/views/a/edit.php | 5 +- modules/news/views/a/index.php | 12 ++- modules/news/views/a/photos.php | 10 ++ modules/page/api/Page.php | 12 +-- modules/page/api/PageObject.php | 18 +++- modules/page/controllers/AController.php | 4 +- modules/page/models/Page.php | 2 +- modules/page/views/a/_form.php | 1 + modules/shopcart/ShopcartModule.php | 7 +- modules/shopcart/models/Good.php | 2 +- modules/shopcart/models/Order.php | 79 ++++++++++++---- modules/shopcart/views/a/_menu.php | 34 ++++--- modules/shopcart/views/a/view.php | 62 ++++++++++--- modules/subscribe/api/Subscribe.php | 49 +++++----- modules/subscribe/controllers/AController.php | 2 +- .../subscribe/controllers/SendController.php | 15 ++- modules/subscribe/views/a/_form.php | 4 +- modules/text/controllers/AController.php | 2 +- modules/text/views/a/_form.php | 5 +- views/category/_menu.php | 2 +- views/category/index.php | 91 ++++++++---------- widgets/Redactor.php | 4 +- 104 files changed, 1215 insertions(+), 552 deletions(-) create mode 100644 helpers/Mail.php create mode 100644 modules/article/api/PhotoObject.php create mode 100644 modules/article/views/items/_submenu.php create mode 100644 modules/article/views/items/photos.php create mode 100644 modules/catalog/models/ItemData.php create mode 100644 modules/feedback/mail/en/answer.php create mode 100644 modules/feedback/mail/en/new_feedback.php create mode 100644 modules/feedback/mail/ru/answer.php create mode 100644 modules/feedback/mail/ru/new_feedback.php create mode 100644 modules/gallery/models/Category.php delete mode 100644 modules/guestbook/messages/ru/api.php create mode 100644 modules/news/api/PhotoObject.php create mode 100644 modules/news/views/a/_submenu.php create mode 100644 modules/news/views/a/photos.php diff --git a/components/ApiObject.php b/components/ApiObject.php index 77b95bc..e02e15c 100644 --- a/components/ApiObject.php +++ b/components/ApiObject.php @@ -29,12 +29,12 @@ public function getId(){ public function thumb($width = null, $height = null, $crop = true) { if($this->image && ($width || $height)){ - return Image::thumb(Yii::getAlias('@webroot') . $this->image, $width, $height, $crop); + return Image::thumb($this->image, $width, $height, $crop); } return ''; } - public function seo($attribute){ - return !empty($this->model->seo->{$attribute}) ? $this->model->seo->{$attribute} : ''; + public function seo($attribute, $default = ''){ + return !empty($this->model->seo->{$attribute}) ? $this->model->seo->{$attribute} : $default; } } \ No newline at end of file diff --git a/components/CategoryController.php b/components/CategoryController.php index 5f9a7c4..31ea1ec 100644 --- a/components/CategoryController.php +++ b/components/CategoryController.php @@ -13,12 +13,13 @@ class CategoryController extends Controller { public $categoryClass; public $moduleName; + public $viewRoute = '/items'; public function actionIndex() { $class = $this->categoryClass; return $this->render('@easyii/views/category/index', [ - 'tree' => $class::tree() + 'cats' => $class::cats() ]); } @@ -37,7 +38,7 @@ public function actionCreate($parent = null) $model->image = UploadedFile::getInstance($model, 'image'); if($model->image && $model->validate(['image'])){ $model->image = Image::upload($model->image, $this->moduleName); - }else{ + } else { $model->image = ''; } } @@ -46,17 +47,16 @@ public function actionCreate($parent = null) $parent = Yii::$app->request->post('parent', null); if($parent && ($parentCategory = $class::findOne((int)$parent))){ - $model->appendTo($parentCategory); $model->order_num = $parentCategory->order_num; + $model->appendTo($parentCategory); } else { $model->attachBehavior(SortableModel::className()); $model->makeRoot(); } - if($model->save()){ - + if(!$model->hasErrors()){ $this->flash('success', Yii::t('easyii', 'Category created')); - return $this->redirect(['/admin/'.$this->moduleName.'/items/index', 'id' => $model->primaryKey]); + return $this->redirect(['/admin/'.$this->moduleName, 'id' => $model->primaryKey]); } else{ $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors())); @@ -134,7 +134,7 @@ public function actionDelete($id) $class = $this->categoryClass; if(($model = $class::findOne($id))){ $model->deleteWithChildren(); - } else{ + } else { $this->error = Yii::t('easyii', 'Not found'); } return $this->formatResponse(Yii::t('easyii', 'Category deleted')); @@ -169,15 +169,17 @@ private function move($id, $direction) if(($model = $modelClass::findOne($id))) { $up = $direction == 'up'; - $orderDir = $up ? 'ASC' : 'DESC'; + $orderDir = $up ? SORT_ASC : SORT_DESC; + + if($model->depth == 0){ - if($model->primaryKey == $model->tree){ - $swapCat = $modelClass::find()->where([$up ? '>' : '<', 'order_num', $model->order_num])->orderBy('order_num '.$orderDir)->one(); + $swapCat = $modelClass::find()->where([$up ? '>' : '<', 'order_num', $model->order_num])->orderBy(['order_num' => $orderDir])->one(); if($swapCat) { $modelClass::updateAll(['order_num' => '-1'], ['order_num' => $swapCat->order_num]); $modelClass::updateAll(['order_num' => $swapCat->order_num], ['order_num' => $model->order_num]); $modelClass::updateAll(['order_num' => $model->order_num], ['order_num' => '-1']); + $model->trigger(\yii\db\ActiveRecord::EVENT_AFTER_UPDATE); } } else { $where = [ diff --git a/components/CategoryModel.php b/components/CategoryModel.php index eb2f0a3..6c7f986 100644 --- a/components/CategoryModel.php +++ b/components/CategoryModel.php @@ -7,6 +7,7 @@ use yii\easyii\behaviors\SeoBehavior; use yii\easyii\helpers\Data; use creocoder\nestedsets\NestedSetsBehavior; +use yii\easyii\helpers\Image; class CategoryModel extends \yii\easyii\components\ActiveRecord { @@ -57,7 +58,7 @@ public function behaviors() public function beforeSave($insert) { if (parent::beforeSave($insert)) { - if(!$this->isNewRecord && $this->image != $this->oldAttributes['image']){ + if(!$insert && $this->image != $this->oldAttributes['image'] && $this->oldAttributes['image']){ @unlink(Yii::getAlias('@webroot').$this->oldAttributes['image']); } return true; @@ -87,7 +88,7 @@ public static function tree() }); } - public static function flat() + public static function cats() { return Data::cache(static::tableName().'_flat', 3600, function(){ return self::generateFlat(); @@ -113,7 +114,7 @@ public static function generateTree() $l = count($stack); // Check if we're dealing with different levels - while($l > 0 && $stack[$l - 1]['depth'] >= $item['depth']) { + while($l > 0 && $stack[$l - 1]->depth >= $item['depth']) { array_pop($stack); $l--; } @@ -122,15 +123,15 @@ public static function generateTree() if ($l == 0) { // Assigning the root node $i = count($trees); - $trees[$i] = $item; + $trees[$i] = (object)$item; $stack[] = & $trees[$i]; } else { // Add node to parent - $item['parent'] = $stack[$l - 1]['category_id']; - $i = count($stack[$l - 1]['children']); - $stack[$l - 1]['children'][$i] = $item; - $stack[] = & $stack[$l - 1]['children'][$i]; + $item['parent'] = $stack[$l - 1]->category_id; + $i = count($stack[$l - 1]->children); + $stack[$l - 1]->children[$i] = (object)$item; + $stack[] = & $stack[$l - 1]->children[$i]; } } } @@ -147,38 +148,39 @@ public static function generateFlat() $depth = 0; $lastId = 0; foreach ($collection as $node) { - $id = $node['category_id']; - $node['parent'] = ''; - - if($node['depth'] > $depth){ - $node['parent'] = $flat[$lastId]['category_id']; - $depth = $node['depth']; - } elseif($node['depth'] == 0){ + $node = (object)$node; + $id = $node->category_id; + $node->parent = ''; + + if($node->depth > $depth){ + $node->parent = $flat[$lastId]->category_id; + $depth = $node->depth; + } elseif($node->depth == 0){ $depth = 0; } else { - if ($node['depth'] == $depth) { - $node['parent'] = $flat[$lastId]['parent']; + if ($node->depth == $depth) { + $node->parent = $flat[$lastId]->parent; } else { foreach($flat as $temp){ - if($temp['depth'] == $node['depth']){ - $node['parent'] = $temp['parent']; - $depth = $temp['depth']; + if($temp->depth == $node->depth){ + $node->parent = $temp->parent; + $depth = $temp->depth; break; } } } } $lastId = $id; - unset($node['lft'], $node['rgt']); + unset($node->lft, $node->rgt); $flat[$id] = $node; } } foreach($flat as &$node){ - $node['children'] = []; + $node->children = []; foreach($flat as $temp){ - if($temp['parent'] == $node['category_id']){ - $node['children'][] = $temp['category_id']; + if($temp->parent == $node->category_id){ + $node->children[] = $temp->category_id; } } } diff --git a/components/Controller.php b/components/Controller.php index ea9e41b..dd389b1 100644 --- a/components/Controller.php +++ b/components/Controller.php @@ -2,7 +2,8 @@ namespace yii\easyii\components; use Yii; -use \yii\easyii\models; +use yii\easyii\models; +use yii\helpers\Url; class Controller extends \yii\web\Controller { @@ -45,14 +46,12 @@ public function back() public function setReturnUrl($url = null) { - Yii::$app->getSession()->set($this->module->id.'_return', $url ? $url : Yii::$app->request->url); + Yii::$app->getSession()->set($this->module->id.'_return', $url ? Url::to($url) : Url::current()); } public function getReturnUrl($defaultUrl = null) { - $url = Yii::$app->getSession()->get($this->module->id.'_return', $defaultUrl); - - return $url === null ? Yii::$app->getHomeUrl() : $url; + return Yii::$app->getSession()->get($this->module->id.'_return', $defaultUrl ? Url::to($defaultUrl) : Url::to('/admin/'.$this->module->id)); } public function formatResponse($success = '', $back = true) @@ -61,12 +60,12 @@ public function formatResponse($success = '', $back = true) Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; if($this->error){ return ['result' => 'error', 'error' => $this->error]; - } else{ + } else { $response = ['result' => 'success']; if($success) { if(is_array($success)){ $response = array_merge(['result' => 'success'], $success); - } else{ + } else { $response = array_merge(['result' => 'success'], ['message' => $success]); } } @@ -76,7 +75,7 @@ public function formatResponse($success = '', $back = true) else{ if($this->error){ $this->flash('error', $this->error); - } else{ + } else { if(is_array($success) && isset($success['message'])){ $this->flash('success', $success['message']); } diff --git a/controllers/AdminsController.php b/controllers/AdminsController.php index e0c1e8a..d8b6e6f 100644 --- a/controllers/AdminsController.php +++ b/controllers/AdminsController.php @@ -85,7 +85,7 @@ public function actionDelete($id) { if(($model = Admin::findOne($id))){ $model->delete(); - } else{ + } else { $this->error = Yii::t('easyii', 'Not found'); } return $this->formatResponse(Yii::t('easyii', 'Admin deleted')); diff --git a/helpers/Data.php b/helpers/Data.php index 4562061..1d054f3 100644 --- a/helpers/Data.php +++ b/helpers/Data.php @@ -22,4 +22,9 @@ public static function cache($key, $duration, $callable) } return $data; } + + public static function getLocale() + { + return strtolower(substr(Yii::$app->language, 0, 2)); + } } \ No newline at end of file diff --git a/helpers/Image.php b/helpers/Image.php index b820eb5..66662e7 100644 --- a/helpers/Image.php +++ b/helpers/Image.php @@ -25,25 +25,13 @@ public static function upload(UploadedFile $fileInstance, $dir = '', $resizeWidt return Upload::getLink($fileName); } - static function createThumbnail($fileName, $width, $height = null, $crop = true) + static function thumb($filename, $width = null, $height = null, $crop = true) { - $fileName = str_replace(Url::base(true), '', $fileName); - $webRoot = Yii::getAlias('@webroot'); - if(!strstr($fileName, $webRoot)){ - $fileName = $webRoot . $fileName; - } - $thumbFolder = dirname($fileName) . DIRECTORY_SEPARATOR . ($width.($height ? 'x'.$height : '')); - $thumbFile = $thumbFolder . DIRECTORY_SEPARATOR . basename($fileName); - - if(!FileHelper::createDirectory($thumbFolder)){ - throw new HttpException(500, 'Cannot create "'.$thumbFolder.'". Please check write permissions.'); + if(!strstr($filename, $webRoot)){ + $filename = $webRoot . $filename; } - return self::copyResizedImage($fileName, $thumbFile, $width, $height, $crop) ? Upload::getLink($thumbFile) : false; - } - static function thumb($filename, $width = null, $height = null, $crop = true) - { if(file_exists($filename)) { $info = pathinfo($filename); @@ -97,6 +85,5 @@ static function copyResizedImage($inputFile, $outputFile, $width, $height = null else { throw new HttpException(500, 'Please install GD or Imagick extension'); } - return false; } } \ No newline at end of file diff --git a/helpers/Mail.php b/helpers/Mail.php new file mode 100644 index 0000000..5aee3bb --- /dev/null +++ b/helpers/Mail.php @@ -0,0 +1,29 @@ +mailer->compose($template, $data) + ->setTo(Setting::get('admin_email')) + ->setSubject(trim($subject)); + + if(!filter_var(Setting::get('robot_email'), FILTER_VALIDATE_EMAIL)){ + $message->setFrom(Setting::get('robot_email')); + } + + if(!empty($options['replyTo']) && filter_var($options['replyTo'], FILTER_VALIDATE_EMAIL)){ + $message->setReplyTo($options['replyTo']); + } + + return $message->send(); + } +} \ No newline at end of file diff --git a/media/css/admin.css b/media/css/admin.css index 4994199..ce7e934 100644 --- a/media/css/admin.css +++ b/media/css/admin.css @@ -101,7 +101,7 @@ html{ #admin-body .main .container-fluid{ padding: 20px; } -#admin-body .main a, #admin-body .main .btn, #admin-body .main .form-control{ +#admin-body .main a, #admin-body .main .btn, #admin-body .main .form-control, .input-group-addon{ border-radius: 0 !important; } diff --git a/messages/ru/admin.php b/messages/ru/admin.php index e2a36b7..60432e3 100644 --- a/messages/ru/admin.php +++ b/messages/ru/admin.php @@ -61,6 +61,7 @@ 'Not found' => 'Не найдено', 'Create error. {0}' => 'Ошибка при создании. {0}', 'Update error. {0}' => 'Ошибка при обновлении. {0}', + 'An error has occurred' => 'Произошла ошибка', 'Slug can contain only 0-9, a-z and "-" characters (max: 128).' => 'Метка может содержать только 0-9, a-z и "-" (макс. 128).', 'Only for developer' => 'Только для разработчика', diff --git a/migrations/m000000_000000_install.php b/migrations/m000000_000000_install.php index 7dc8743..8c0d8b2 100644 --- a/migrations/m000000_000000_install.php +++ b/migrations/m000000_000000_install.php @@ -61,25 +61,25 @@ public function up() //PHOTOS $this->createTable(models\Photo::tableName(), [ 'photo_id' => 'pk', - 'model' => Schema::TYPE_STRING . '(128) NOT NULL', + 'class' => Schema::TYPE_STRING . '(128) NOT NULL', 'item_id' => Schema::TYPE_INTEGER . " NOT NULL", 'image' => Schema::TYPE_STRING . '(128) NOT NULL', 'description' => Schema::TYPE_STRING . '(1024) NOT NULL', 'order_num' => Schema::TYPE_INTEGER . " NOT NULL", ], 'ENGINE=MyISAM DEFAULT CHARSET=utf8'); - $this->createIndex('model_item', models\Photo::tableName(), ['model', 'item_id']); + $this->createIndex('model_item', models\Photo::tableName(), ['class', 'item_id']); //SEOTEXT $this->createTable(models\SeoText::tableName(), [ 'seotext_id' => 'pk', - 'model' => Schema::TYPE_STRING . '(128) NOT NULL', + 'class' => Schema::TYPE_STRING . '(128) NOT NULL', 'item_id' => Schema::TYPE_INTEGER . " NOT NULL", 'h1' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'title' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'keywords' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'description' => Schema::TYPE_STRING . '(128) DEFAULT NULL', ], 'ENGINE=MyISAM DEFAULT CHARSET=utf8'); - $this->createIndex('model_item', models\SeoText::tableName(), ['model', 'item_id'], true); + $this->createIndex('model_item', models\SeoText::tableName(), ['class', 'item_id'], true); //SETTINGS $this->createTable(models\Setting::tableName(), [ @@ -129,10 +129,18 @@ public function up() 'data' => Schema::TYPE_TEXT . ' NOT NULL', 'image' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', - 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', + 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", ], 'ENGINE=MyISAM DEFAULT CHARSET=utf8'); $this->createIndex('slug', catalog\models\Item::tableName(), 'slug', true); + $this->createTable(catalog\models\ItemData::tableName(), [ + 'data_id' => 'pk', + 'item_id' => Schema::TYPE_INTEGER . ' NOT NULL', + 'name' => Schema::TYPE_STRING . '(128) NOT NULL', + 'value' => Schema::TYPE_STRING . '(1024) DEFAULT NULL', + ], 'ENGINE=MyISAM DEFAULT CHARSET=utf8'); + $this->createIndex('item_id', catalog\models\ItemData::tableName(), 'item_id', true); + //SHOPCART MODULE $this->createTable(shopcart\models\Order::tableName(), [ 'order_id' => 'pk', @@ -141,9 +149,11 @@ public function up() 'phone' => Schema::TYPE_STRING . '(64) NOT NULL', 'email' => Schema::TYPE_STRING . '(128) NOT NULL', 'comment' => Schema::TYPE_STRING . '(1024) NOT NULL', + 'remark' => Schema::TYPE_STRING . '(1024) NOT NULL', 'access_token' => Schema::TYPE_STRING . '(32) NOT NULL', + 'ip' => Schema::TYPE_STRING . '(16) NOT NULL', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", - 'new' => Schema::TYPE_BOOLEAN . " DEFAULT '1'", + 'new' => Schema::TYPE_BOOLEAN . " DEFAULT '0'", 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'" ], 'ENGINE=MyISAM DEFAULT CHARSET=utf8'); @@ -165,7 +175,8 @@ public function up() 'phone' => Schema::TYPE_STRING . '(64) DEFAULT NULL', 'title' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'text' => Schema::TYPE_TEXT . ' NOT NULL', - 'answer' => Schema::TYPE_TEXT . ' DEFAULT NULL', + 'answer_subject' => Schema::TYPE_STRING . '(128) DEFAULT NULL', + 'answer_text' => Schema::TYPE_TEXT . ' DEFAULT NULL', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'ip' => Schema::TYPE_STRING . '(16) NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'" @@ -238,7 +249,7 @@ public function up() 'lft' => Schema::TYPE_INTEGER . ' NOT NULL', 'rgt' => Schema::TYPE_INTEGER . ' NOT NULL', 'depth' => Schema::TYPE_INTEGER . ' NOT NULL', - 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '1'" + 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'" ], 'ENGINE=MyISAM DEFAULT CHARSET=utf8'); $this->createIndex('slug', article\models\Category::tableName(), 'slug', true); @@ -250,8 +261,8 @@ public function up() 'short' => Schema::TYPE_STRING . '(1024) DEFAULT NULL', 'text' => Schema::TYPE_TEXT . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', + 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'views' => Schema::TYPE_INTEGER . " DEFAULT '0'", - 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'" ], 'ENGINE=MyISAM DEFAULT CHARSET=utf8'); $this->createIndex('slug', article\models\Item::tableName(), 'slug', true); diff --git a/models/Photo.php b/models/Photo.php index 449cf77..f7d980f 100644 --- a/models/Photo.php +++ b/models/Photo.php @@ -18,7 +18,7 @@ public static function tableName() public function rules() { return [ - [['model', 'item_id'], 'required'], + [['class', 'item_id'], 'required'], ['item_id', 'integer'], ['image', 'image'], ['description', 'trim'] diff --git a/modules/article/ArticleModule.php b/modules/article/ArticleModule.php index 35f7472..b8a115d 100644 --- a/modules/article/ArticleModule.php +++ b/modules/article/ArticleModule.php @@ -6,6 +6,7 @@ class ArticleModule extends \yii\easyii\components\Module public $settings = [ 'categoryThumb' => true, 'articleThumb' => true, + 'enablePhotos' => true, 'enableShort' => true, 'shortMaxLength' => 255, diff --git a/modules/article/api/Article.php b/modules/article/api/Article.php index e468352..166f2f5 100644 --- a/modules/article/api/Article.php +++ b/modules/article/api/Article.php @@ -3,13 +3,18 @@ use Yii; -use yii\easyii\modules\catalog\models\Category; -use yii\easyii\modules\catalog\models\Item; +use yii\data\ActiveDataProvider; +use yii\easyii\modules\article\models\Category; +use yii\easyii\modules\article\models\Item; +use yii\easyii\widgets\Fancybox; +use yii\widgets\LinkPager; class Article extends \yii\easyii\components\API { private $_cats; private $_items; + private $_adp; + private $_item = []; private $_last; public function api_cat($id_slug) @@ -25,6 +30,39 @@ public function api_tree() return Category::tree(); } + public function api_cats() + { + return Category::cats(); + } + + public function api_items($options = []) + { + if(!$this->_items){ + $this->_items = []; + + $query = Item::find()->with(['seo', 'category'])->status(Item::STATUS_ON); + + if(!empty($options['where'])){ + $query->andFilterWhere($options['where']); + } + if(!empty($options['orderBy'])){ + $query->orderBy($options['orderBy']); + } else { + $query->sort(); + } + + $this->_adp = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => !empty($options['pagination']) ? $options['pagination'] : [] + ]); + + foreach($this->_adp->models as $model){ + $this->_items[] = new ArticleObject($model); + } + } + return $this->_items; + } + public function api_last($limit = 1, $where = null) { if($limit === 1 && $this->_last){ @@ -35,7 +73,7 @@ public function api_last($limit = 1, $where = null) $query = Item::find()->with('seo')->status(Item::STATUS_ON)->sort()->limit($limit); if($where){ - $query->where($where); + $query->andFilterWhere($where); } foreach($query->all() as $item){ @@ -52,22 +90,40 @@ public function api_last($limit = 1, $where = null) public function api_get($id_slug) { - if(!isset($this->_items[$id_slug])) { - $this->_items[$id_slug] = $this->findItem($id_slug); + if(!isset($this->_item[$id_slug])) { + $this->_item[$id_slug] = $this->findItem($id_slug); } - return $this->_items[$id_slug]; + return $this->_item[$id_slug]; + } + + public function api_plugin($options = []) + { + Fancybox::widget([ + 'selector' => '.easyii-box', + 'options' => $options + ]); + } + + public function api_pagination() + { + return $this->_adp ? $this->_adp->pagination : null; + } + + public function api_pages() + { + return $this->_adp ? LinkPager::widget(['pagination' => $this->_adp->pagination]) : ''; } private function findCategory($id_slug) { - $category = Category::find()->where(['or', 'category_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->one(); + $category = Category::find()->where(['or', 'category_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one(); return $category ? new CategoryObject($category) : null; } private function findItem($id_slug) { - $article = Item::find()->where(['or', 'item_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->one(); + $article = Item::find()->where(['or', 'item_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one(); if($article) { $article->updateCounters(['views' => 1]); return new ArticleObject($article); diff --git a/modules/article/api/ArticleObject.php b/modules/article/api/ArticleObject.php index 19a28a8..7fff016 100644 --- a/modules/article/api/ArticleObject.php +++ b/modules/article/api/ArticleObject.php @@ -2,6 +2,8 @@ namespace yii\easyii\modules\article\api; use yii\easyii\components\API; +use yii\easyii\models\Photo; +use yii\easyii\modules\article\models\Item; use yii\helpers\Url; class ArticleObject extends \yii\easyii\components\ApiObject @@ -9,6 +11,9 @@ class ArticleObject extends \yii\easyii\components\ApiObject public $slug; public $image; public $views; + public $category_id; + + private $_photos; public function getTitle(){ return LIVE_EDIT ? API::liveEdit($this->model->title, $this->editLink) : $this->model->title; @@ -22,6 +27,22 @@ public function getText(){ return LIVE_EDIT ? API::liveEdit($this->model->text, $this->editLink, 'div') : $this->model->text; } + public function getCat(){ + return Article::cats()[$this->category_id]; + } + + public function getPhotos() + { + if(!$this->_photos){ + $this->_photos = []; + + foreach(Photo::find()->where(['class' => Item::className(), 'item_id' => $this->id])->sort()->all() as $model){ + $this->_photos[] = new PhotoObject($model); + } + } + return $this->_photos; + } + public function getEditLink(){ return Url::to(['/admin/article/items/edit/', 'id' => $this->id]); } diff --git a/modules/article/api/CategoryObject.php b/modules/article/api/CategoryObject.php index 6c34c0b..95a2921 100644 --- a/modules/article/api/CategoryObject.php +++ b/modules/article/api/CategoryObject.php @@ -21,11 +21,11 @@ public function getTitle(){ return LIVE_EDIT ? API::liveEdit($this->model->title, $this->editLink) : $this->model->title; } - public function getPages(){ - return $this->_adp ? LinkPager::widget(['pagination' => $this->_adp->pagination]) : ''; + public function pages($options = []){ + return $this->_adp ? LinkPager::widget(array_merge($options, ['pagination' => $this->_adp->pagination])) : ''; } - public function getPagination(){ + public function pagination(){ return $this->_adp ? $this->_adp->pagination : null; } @@ -34,10 +34,10 @@ public function items($options = []) if(!$this->_items){ $this->_items = []; - $query = Item::find()->with('seo')->where(['category_id' => $this->id])->sort(); + $query = Item::find()->with('seo')->where(['category_id' => $this->id])->status(Item::STATUS_ON)->sort(); if(!empty($options['where'])){ - $query->andWhere($options['where']); + $query->andFilterWhere($options['where']); } $this->_adp = new ActiveDataProvider([ diff --git a/modules/article/api/PhotoObject.php b/modules/article/api/PhotoObject.php new file mode 100644 index 0000000..08a6cc7 --- /dev/null +++ b/modules/article/api/PhotoObject.php @@ -0,0 +1,27 @@ +thumb($width, $height)); + $a = Html::a($img, $this->image, [ + 'class' => 'easyii-box', + 'rel' => 'article-'.$this->model->item_id, + 'title' => $this->description + ]); + return LIVE_EDIT ? API::liveEdit($a, $this->editLink) : $a; + } + + public function getEditLink(){ + return Url::to(['/admin/article/items/photos', 'id' => $this->model->item_id]).'#photo-'.$this->id; + } +} \ No newline at end of file diff --git a/modules/article/controllers/ItemsController.php b/modules/article/controllers/ItemsController.php index d14c4bc..b6cab23 100644 --- a/modules/article/controllers/ItemsController.php +++ b/modules/article/controllers/ItemsController.php @@ -2,13 +2,14 @@ namespace yii\easyii\modules\article\controllers; use Yii; +use yii\easyii\behaviors\SortableDateController; +use yii\easyii\behaviors\StatusController; use yii\web\UploadedFile; use yii\easyii\components\Controller; use yii\easyii\modules\article\models\Category; use yii\easyii\modules\article\models\Item; use yii\easyii\helpers\Image; -use yii\easyii\behaviors\SortableController; use yii\widgets\ActiveForm; class ItemsController extends Controller @@ -17,8 +18,12 @@ public function behaviors() { return [ [ - 'class' => SortableController::className(), + 'class' => SortableDateController::className(), 'model' => Item::className(), + ], + [ + 'class' => StatusController::className(), + 'model' => Item::className() ] ]; } @@ -59,6 +64,7 @@ public function actionCreate($id) $model->image = ''; } } + $model->status = Item::STATUS_ON; if ($model->save()) { $this->flash('success', Yii::t('easyii/article', 'Article created')); @@ -114,6 +120,17 @@ public function actionEdit($id) } } + public function actionPhotos($id) + { + if(!($model = Item::findOne($id))){ + return $this->redirect(['/admin/'.$this->module->id]); + } + + return $this->render('photos', [ + 'model' => $model, + ]); + } + public function actionClearImage($id) { $model = Item::findOne($id); @@ -136,7 +153,7 @@ public function actionDelete($id) { if(($model = Item::findOne($id))){ $model->delete(); - } else{ + } else { $this->error = Yii::t('easyii', 'Not found'); } return $this->formatResponse(Yii::t('easyii/article', 'Article deleted')); @@ -151,4 +168,14 @@ public function actionDown($id, $category_id) { return $this->move($id, 'down', ['category_id' => $category_id]); } + + public function actionOn($id) + { + return $this->changeStatus($id, Item::STATUS_ON); + } + + public function actionOff($id) + { + return $this->changeStatus($id, Item::STATUS_OFF); + } } \ No newline at end of file diff --git a/modules/article/models/Item.php b/modules/article/models/Item.php index d61318c..5d14a0a 100644 --- a/modules/article/models/Item.php +++ b/modules/article/models/Item.php @@ -24,7 +24,8 @@ public function rules() [['title', 'short', 'text'], 'trim'], ['title', 'string', 'max' => 128], ['image', 'image'], - ['views', 'number', 'integerOnly' => true], + [['views', 'time'], 'integer'], + ['time', 'default', 'value' => time()], ['slug', 'match', 'pattern' => self::$SLUG_PATTERN, 'message' => Yii::t('easyii', 'Slug can contain only 0-9, a-z and "-" characters (max: 128).')], ['slug', 'default', 'value' => null], ]; @@ -37,6 +38,7 @@ public function attributeLabels() 'text' => Yii::t('easyii', 'Text'), 'short' => Yii::t('easyii/article', 'Short'), 'image' => Yii::t('easyii', 'Image'), + 'time' => Yii::t('easyii', 'Date'), 'slug' => Yii::t('easyii', 'Slug'), ]; } @@ -44,9 +46,7 @@ public function attributeLabels() public function behaviors() { return [ - SortableModel::className(), 'seoBehavior' => SeoBehavior::className(), - 'seo' => SeoBehavior::className(), 'sluggable' => [ 'class' => SluggableBehavior::className(), 'attribute' => 'title', @@ -64,11 +64,9 @@ public function beforeSave($insert) { if (parent::beforeSave($insert)) { $settings = Yii::$app->getModule('admin')->activeModules['article']->settings; - if($this->short && $settings['enableShort']){ - $this->short = StringHelper::truncate($this->short, $settings['shortMaxLength']); - } + $this->short = StringHelper::truncate($settings['enableShort'] ? $this->short : strip_tags($this->text), $settings['shortMaxLength']); - if(!$this->isNewRecord && $this->image != $this->oldAttributes['image']){ + if(!$insert && $this->image != $this->oldAttributes['image'] && $this->oldAttributes['image']){ @unlink(Yii::getAlias('@webroot').$this->oldAttributes['image']); } diff --git a/modules/article/views/items/_form.php b/modules/article/views/items/_form.php index 954705f..21715a0 100644 --- a/modules/article/views/items/_form.php +++ b/modules/article/views/items/_form.php @@ -1,5 +1,6 @@ true, - 'options' => ['enctype' => 'multipart/form-data'] + 'options' => ['enctype' => 'multipart/form-data', 'class' => 'model-form'] ]); ?> field($model, 'title') ?> @@ -35,6 +36,10 @@ ] ]) ?> +field($model, 'time')->widget(DateTimePicker::className()); ?> + + + field($model, 'slug') ?> $model]) ?> diff --git a/modules/article/views/items/_menu.php b/modules/article/views/items/_menu.php index b1695d8..58aba56 100644 --- a/modules/article/views/items/_menu.php +++ b/modules/article/views/items/_menu.php @@ -5,10 +5,10 @@ $module = $this->context->module->id; ?>
\ No newline at end of file diff --git a/modules/article/views/items/_submenu.php b/modules/article/views/items/_submenu.php new file mode 100644 index 0000000..7334850 --- /dev/null +++ b/modules/article/views/items/_submenu.php @@ -0,0 +1,12 @@ +context->action->id; +$module = $this->context->module->id; +?> + + +
\ No newline at end of file diff --git a/modules/article/views/items/edit.php b/modules/article/views/items/edit.php index 30d2c50..d6ed6ae 100644 --- a/modules/article/views/items/edit.php +++ b/modules/article/views/items/edit.php @@ -1,6 +1,8 @@ title = Yii::t('easyii/article', 'Edit article'); +$this->title = $model->title; ?> render('_menu', ['category' => $model->category]) ?> +context->module->settings['enablePhotos']) echo $this->render('_submenu', ['model' => $model]) ?> + render('_form', ['model' => $model]) ?> diff --git a/modules/article/views/items/index.php b/modules/article/views/items/index.php index ea7ca2e..2ed7728 100644 --- a/modules/article/views/items/index.php +++ b/modules/article/views/items/index.php @@ -1,4 +1,6 @@ title = Yii::t('easyii/article', 'Articles'); @@ -16,6 +18,7 @@ + @@ -27,6 +30,13 @@ title ?> views ?> + + status == Item::STATUS_ON, [ + 'class' => 'switch', + 'data-id' => $item->primaryKey, + 'data-link' => Url::to(['/admin/'.$module.'/items']), + ]) ?> +
diff --git a/modules/article/views/items/photos.php b/modules/article/views/items/photos.php new file mode 100644 index 0000000..589261d --- /dev/null +++ b/modules/article/views/items/photos.php @@ -0,0 +1,10 @@ +title = $model->title; +?> + +render('_menu', ['category' => $model->category]) ?> +render('_submenu', ['model' => $model]) ?> + + $model])?> \ No newline at end of file diff --git a/modules/carousel/controllers/AController.php b/modules/carousel/controllers/AController.php index 542e0e0..770b924 100644 --- a/modules/carousel/controllers/AController.php +++ b/modules/carousel/controllers/AController.php @@ -131,7 +131,7 @@ public function actionDelete($id) { if(($model = Carousel::findOne($id))){ $model->delete(); - } else{ + } else { $this->error = Yii::t('easyii', 'Not found'); } return $this->formatResponse(Yii::t('easyii/carousel', 'Carousel item deleted')); diff --git a/modules/carousel/models/Carousel.php b/modules/carousel/models/Carousel.php index 68b3fe6..6d7aee1 100644 --- a/modules/carousel/models/Carousel.php +++ b/modules/carousel/models/Carousel.php @@ -45,7 +45,7 @@ public function behaviors() public function beforeSave($insert) { if (parent::beforeSave($insert)) { - if(!$this->isNewRecord && $this->image != $this->oldAttributes['image']){ + if(!$insert && $this->image != $this->oldAttributes['image'] && $this->oldAttributes['image']){ @unlink(Yii::getAlias('@webroot').$this->oldAttributes['image']); } return true; diff --git a/modules/carousel/views/a/_form.php b/modules/carousel/views/a/_form.php index a0c8b7c..9df55e0 100644 --- a/modules/carousel/views/a/_form.php +++ b/modules/carousel/views/a/_form.php @@ -4,7 +4,7 @@ ?> true, - 'options' => ['enctype' => 'multipart/form-data'] + 'options' => ['enctype' => 'multipart/form-data', 'class' => 'model-form'] ]); ?> image) : ?> diff --git a/modules/catalog/api/Catalog.php b/modules/catalog/api/Catalog.php index c6a4df7..4d15548 100644 --- a/modules/catalog/api/Catalog.php +++ b/modules/catalog/api/Catalog.php @@ -3,14 +3,18 @@ use Yii; +use yii\data\ActiveDataProvider; use yii\easyii\widgets\Fancybox; use yii\easyii\modules\catalog\models\Category; use yii\easyii\modules\catalog\models\Item; +use yii\widgets\LinkPager; class Catalog extends \yii\easyii\components\API { private $_cats; private $_items; + private $_adp; + private $_item = []; public function api_cat($id_slug) { @@ -25,6 +29,39 @@ public function api_tree() return Category::tree(); } + public function api_cats() + { + return Category::cats(); + } + + public function api_items($options = []) + { + if(!$this->_items){ + $this->_items = []; + + $query = Item::find()->with(['seo', 'category'])->status(Item::STATUS_ON); + + if(!empty($options['where'])){ + $query->andFilterWhere($options['where']); + } + if(!empty($options['orderBy'])){ + $query->orderBy($options['orderBy']); + } else { + $query->sortDate(); + } + + $this->_adp = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => !empty($options['pagination']) ? $options['pagination'] : [] + ]); + + foreach($this->_adp->models as $model){ + $this->_items[] = new ItemObject($model); + } + } + return $this->_items; + } + public function api_last($limit = 1, $where = null) { if($limit === 1 && $this->_last){ @@ -33,9 +70,9 @@ public function api_last($limit = 1, $where = null) $result = []; - $query = Item::find()->with('seo')->sort()->limit($limit); + $query = Item::find()->with('seo')->sortDate()->status(Item::STATUS_ON)->limit($limit); if($where){ - $query->where($where); + $query->andFilterWhere($where); } foreach($query->all() as $item){ @@ -52,10 +89,20 @@ public function api_last($limit = 1, $where = null) public function api_get($id_slug) { - if(!isset($this->_items[$id_slug])) { - $this->_items[$id_slug] = $this->findItem($id_slug); + if(!isset($this->_item[$id_slug])) { + $this->_item[$id_slug] = $this->findItem($id_slug); } - return $this->_items[$id_slug]; + return $this->_item[$id_slug]; + } + + public function api_pagination() + { + return $this->_adp ? $this->_adp->pagination : null; + } + + public function api_pages() + { + return $this->_adp ? LinkPager::widget(['pagination' => $this->_adp->pagination]) : ''; } public function api_plugin($options = []) @@ -68,14 +115,14 @@ public function api_plugin($options = []) private function findCategory($id_slug) { - $category = Category::find()->where(['or', 'category_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->one(); + $category = Category::find()->where(['or', 'category_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one(); return $category ? new CategoryObject($category) : null; } private function findItem($id_slug) { - if(!($item = Item::find()->where(['or', 'item_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->one())){ + if(!($item = Item::find()->where(['or', 'item_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one())){ return null; } diff --git a/modules/catalog/api/CategoryObject.php b/modules/catalog/api/CategoryObject.php index 02a1449..e43f3e2 100644 --- a/modules/catalog/api/CategoryObject.php +++ b/modules/catalog/api/CategoryObject.php @@ -3,7 +3,8 @@ use yii\data\ActiveDataProvider; use yii\easyii\components\API; -use yii\easyii\modules\article\models\Item; +use yii\easyii\modules\catalog\models\Item; +use yii\easyii\modules\catalog\models\ItemData; use yii\helpers\Url; use yii\widgets\LinkPager; @@ -12,6 +13,7 @@ class CategoryObject extends \yii\easyii\components\ApiObject public $slug; public $image; public $tree; + public $fields; public $depth; private $_adp; @@ -21,11 +23,11 @@ public function getTitle(){ return LIVE_EDIT ? API::liveEdit($this->model->title, $this->editLink) : $this->model->title; } - public function getPages(){ - return $this->_adp ? LinkPager::widget(['pagination' => $this->_adp->pagination]) : ''; + public function pages($options = []){ + return $this->_adp ? LinkPager::widget(array_merge($options, ['pagination' => $this->_adp->pagination])) : ''; } - public function getPagination(){ + public function pagination(){ return $this->_adp ? $this->_adp->pagination : null; } @@ -34,12 +36,58 @@ public function items($options = []) if(!$this->_items){ $this->_items = []; - $query = Item::find()->with('seo')->where(['category_id' => $this->id])->sort(); + $query = Item::find()->with('seo')->where(['category_id' => $this->id])->status(Item::STATUS_ON); if(!empty($options['where'])){ - $query->andWhere($options['where']); + $query->andFilterWhere($options['where']); } + if(!empty($options['orderBy'])){ + $query->orderBy($options['orderBy']); + } else { + $query->sortDate(); + } + + if(!empty($options['filters']) && is_array($options['filters'])){ + + if(!empty($options['filters']['price'])){ + $price = $options['filters']['price']; + if(is_array($price) && count($price) == 2) { + if(!$price[0]){ + $query->andFilterWhere(['<=', 'price', (float)$price[1]]); + } elseif(!$price[1]) { + $query->andFilterWhere(['>=', 'price', (float)$price[0]]); + } else { + $query->andFilterWhere(['between', 'price', (float)$price[0], (float)$price[1]]); + } + } + unset($options['filters']['price']); + } + if(count($options['filters'])){ + $filtersApplied = 0; + $subQuery = ItemData::find()->select('item_id, COUNT(*) as filter_matched')->groupBy('item_id'); + foreach($options['filters'] as $field => $value){ + if(!is_array($value)) { + $subQuery->orFilterWhere(['and', ['name' => $field], ['value' => $value]]); + $filtersApplied++; + } elseif(count($value) == 2){ + if(!$value[0]){ + $additionalCondition = ['<=', 'value', (float)$value[1]]; + } elseif(!$value[1]) { + $additionalCondition = ['>=', 'value', (float)$value[0]]; + } else { + $additionalCondition = ['between', 'value', (float)$value[0], (float)$value[1]]; + } + $subQuery->orFilterWhere(['and', ['name' => $field], $additionalCondition]); + $filtersApplied++; + } + } + if($filtersApplied) { + $query->join('LEFT JOIN', ['f' => $subQuery], 'f.item_id = '.Item::tableName().'.item_id'); + $query->andFilterWhere(['f.filter_matched' => $filtersApplied]); + } + } + } $this->_adp = new ActiveDataProvider([ 'query' => $query, 'pagination' => !empty($options['pagination']) ? $options['pagination'] : [] @@ -52,6 +100,24 @@ public function items($options = []) return $this->_items; } + public function fieldOptions($name, $firstOption = '') + { + $options = []; + if($firstOption) { + $options[''] = $firstOption; + } + + foreach($this->fields as $field){ + if($field->name == $name){ + foreach($field->options as $option){ + $options[$option] = $option; + } + break; + } + } + return $options; + } + public function getEditLink(){ return Url::to(['/admin/catalog/a/edit/', 'id' => $this->id]); } diff --git a/modules/catalog/api/ItemObject.php b/modules/catalog/api/ItemObject.php index b826636..b947add 100644 --- a/modules/catalog/api/ItemObject.php +++ b/modules/catalog/api/ItemObject.php @@ -11,36 +11,39 @@ class ItemObject extends \yii\easyii\components\ApiObject { public $slug; public $image; - public $views; + public $data; + public $category_id; + public $available; + public $discount; - private $_adp; private $_photos; public function getTitle(){ return LIVE_EDIT ? API::liveEdit($this->model->title, $this->editLink) : $this->model->title; } - public function getText(){ - return LIVE_EDIT ? API::liveEdit($this->model->text, $this->editLink, 'div') : $this->model->text; + public function getDescription(){ + return LIVE_EDIT ? API::liveEdit($this->model->description, $this->editLink, 'div') : $this->model->description; } - public function photos($options = []) - { - if(!$this->_photos){ - $this->_photos = []; + public function getCat(){ + return Catalog::cats()[$this->category_id]; + } - $query = Photo::find()->where(['model' => Item::className(), 'item_id' => $this->id])->sort(); + public function getPrice(){ + return $this->discount ? round($this->model->price * (1 - $this->discount / 100) ) : $this->model->price; + } - if(!empty($options['where'])){ - $query->where($options['where']); - } + public function getOldPrice(){ + return $this->model->price; + } - $this->_adp = new ActiveDataProvider([ - 'query' => $query, - 'pagination' => !empty($options['pagination']) ? $options['pagination'] : [] - ]); + public function getPhotos() + { + if(!$this->_photos){ + $this->_photos = []; - foreach($this->_adp->models as $model){ + foreach(Photo::find()->where(['class' => Item::className(), 'item_id' => $this->id])->sort()->all() as $model){ $this->_photos[] = new PhotoObject($model); } } diff --git a/modules/catalog/api/PhotoObject.php b/modules/catalog/api/PhotoObject.php index fa27499..b2e4405 100644 --- a/modules/catalog/api/PhotoObject.php +++ b/modules/catalog/api/PhotoObject.php @@ -11,16 +11,17 @@ class PhotoObject extends \yii\easyii\components\ApiObject public $image; public $description; - public function getBox($width, $height){ - $a = Html::a(Html::img($this->thumb($width, $height), $this->image, [ + public function box($width, $height){ + $img = Html::img($this->thumb($width, $height)); + $a = Html::a($img, $this->image, [ 'class' => 'easyii-box', - 'rel' => 'album-'.$this->id, + 'rel' => 'catalog-'.$this->model->item_id, 'title' => $this->description - ])); + ]); return LIVE_EDIT ? API::liveEdit($a, $this->editLink) : $a; } public function getEditLink(){ - return Url::to(['/admin/catalog/items/photos/', 'id' => $this->id.'#'.'photo-'.$this->id]); + return Url::to(['/admin/catalog/items/photos', 'id' => $this->model->item_id]).'#photo-'.$this->id; } } \ No newline at end of file diff --git a/modules/catalog/controllers/AController.php b/modules/catalog/controllers/AController.php index 1b3964b..b37284b 100644 --- a/modules/catalog/controllers/AController.php +++ b/modules/catalog/controllers/AController.php @@ -64,7 +64,7 @@ public function actionFields($id) $ids[] = $child->primaryKey; } if(count($ids)){ - Category::updateAll(['fields' => $model->fields], ['in', 'category_id', $ids]); + Category::updateAll(['fields' => json_encode($model->fields)], ['in', 'category_id', $ids]); } $this->flash('success', Yii::t('easyii/catalog', 'Category updated')); diff --git a/modules/catalog/controllers/ItemsController.php b/modules/catalog/controllers/ItemsController.php index 2e8d535..4d914ee 100644 --- a/modules/catalog/controllers/ItemsController.php +++ b/modules/catalog/controllers/ItemsController.php @@ -2,6 +2,7 @@ namespace yii\easyii\modules\catalog\controllers; use Yii; +use yii\easyii\behaviors\StatusController; use yii\web\UploadedFile; use yii\helpers\Html; @@ -9,7 +10,7 @@ use yii\easyii\modules\catalog\models\Category; use yii\easyii\modules\catalog\models\Item; use yii\easyii\helpers\Image; -use yii\easyii\behaviors\SortableController; +use yii\easyii\behaviors\SortableDateController; use yii\widgets\ActiveForm; class ItemsController extends Controller @@ -18,8 +19,12 @@ public function behaviors() { return [ [ - 'class' => SortableController::className(), + 'class' => SortableDateController::className(), 'model' => Item::className(), + ], + [ + 'class' => StatusController::className(), + 'model' => Item::className() ] ]; } @@ -61,6 +66,7 @@ public function actionCreate($id) $model->image = ''; } } + $model->status = Item::STATUS_ON; if ($model->save()) { $this->flash('success', Yii::t('easyii/catalog', 'Item created')); @@ -154,7 +160,7 @@ public function actionDelete($id) { if(($model = Item::findOne($id))){ $model->delete(); - } else{ + } else { $this->error = Yii::t('easyii', 'Not found'); } return $this->formatResponse(Yii::t('easyii/catalog', 'Item deleted')); @@ -170,6 +176,16 @@ public function actionDown($id, $category_id) return $this->move($id, 'down', ['category_id' => $category_id]); } + public function actionOn($id) + { + return $this->changeStatus($id, Item::STATUS_ON); + } + + public function actionOff($id) + { + return $this->changeStatus($id, Item::STATUS_OFF); + } + private function generateForm($fields, $data = null) { $result = ''; diff --git a/modules/catalog/messages/ru/admin.php b/modules/catalog/messages/ru/admin.php index 3c17b26..c9abe53 100644 --- a/modules/catalog/messages/ru/admin.php +++ b/modules/catalog/messages/ru/admin.php @@ -16,5 +16,8 @@ 'Title' => 'Название', 'Type' => 'Тип поля', 'Options' => 'Опции', + 'Available' => 'Доступно', + 'Price' => 'Цена', + 'Discount' => 'Скидка', 'Select' => 'Выбрать', ]; \ No newline at end of file diff --git a/modules/catalog/models/Category.php b/modules/catalog/models/Category.php index 5cc8d00..d096e58 100644 --- a/modules/catalog/models/Category.php +++ b/modules/catalog/models/Category.php @@ -19,6 +19,10 @@ public static function tableName() public function beforeSave($insert) { if (parent::beforeSave($insert)) { + if($insert && ($parent = $this->parents(1)->one())){ + $this->fields = $parent->fields; + } + if(!$this->fields || !is_array($this->fields)){ $this->fields = []; } @@ -30,15 +34,21 @@ public function beforeSave($insert) } } + public function afterSave($insert, $attributes) + { + parent::afterSave($insert, $attributes); + $this->parseFields(); + } + public function afterFind() { parent::afterFind(); - $this->fields = $this->fields !== '' ? json_decode($this->fields) : []; + $this->parseFields(); } public function getItems() { - return $this->hasMany(Item::className(), ['category_id' => 'category_id'])->sort(); + return $this->hasMany(Item::className(), ['category_id' => 'category_id'])->sortDate(); } public function afterDelete() @@ -49,4 +59,8 @@ public function afterDelete() $item->delete(); } } + + private function parseFields(){ + $this->fields = $this->fields !== '' ? json_decode($this->fields) : []; + } } \ No newline at end of file diff --git a/modules/catalog/models/Item.php b/modules/catalog/models/Item.php index aade02a..93a414e 100644 --- a/modules/catalog/models/Item.php +++ b/modules/catalog/models/Item.php @@ -9,6 +9,8 @@ class Item extends \yii\easyii\components\ActiveRecord { + const STATUS_OFF = 0; + const STATUS_ON = 1; public static function tableName() { @@ -23,6 +25,10 @@ public function rules() ['title', 'string', 'max' => 128], ['image', 'image'], ['description', 'safe'], + ['price', 'number'], + ['discount', 'integer', 'max' => 99], + [['available', 'time'], 'integer'], + ['time', 'default', 'value' => time()], ['slug', 'match', 'pattern' => self::$SLUG_PATTERN, 'message' => Yii::t('easyii', 'Slug can contain only 0-9, a-z and "-" characters (max: 128).')], ['slug', 'default', 'value' => null], ]; @@ -34,6 +40,10 @@ public function attributeLabels() 'title' => Yii::t('easyii', 'Title'), 'image' => Yii::t('easyii', 'Image'), 'description' => Yii::t('easyii', 'Description'), + 'available' => Yii::t('easyii/catalog', 'Available'), + 'price' => Yii::t('easyii/catalog', 'Price'), + 'discount' => Yii::t('easyii/catalog', 'Discount'), + 'time' => Yii::t('easyii', 'Date'), 'slug' => Yii::t('easyii', 'Slug'), ]; } @@ -41,8 +51,7 @@ public function attributeLabels() public function behaviors() { return [ - SortableModel::className(), - 'seo' => SeoBehavior::className(), + 'seoBehavior' => SeoBehavior::className(), 'sluggable' => [ 'class' => SluggableBehavior::className(), 'attribute' => 'title', @@ -58,28 +67,53 @@ public function beforeSave($insert) $this->data = new \stdClass(); } - $this->search = ''; - foreach($this->data as $key => $value){ - $this->search .= $key . '#' . (is_array($value) ? implode(',', $value) : $value) . "\n"; - } - $this->data = json_encode($this->data); + if(!$insert && $this->image != $this->oldAttributes['image'] && $this->oldAttributes['image']){ + @unlink(Yii::getAlias('@webroot').$this->oldAttributes['image']); + } + return true; } else { return false; } } + public function afterSave($insert, $attributes){ + parent::afterSave($insert, $attributes); + + $this->parseData(); + + ItemData::deleteAll(['item_id' => $this->primaryKey]); + + foreach($this->data as $name => $value){ + if(!is_array($value)){ + $this->insertDataValue($name, $value); + } else { + foreach($value as $arrayItem){ + $this->insertDataValue($name, $arrayItem); + } + } + } + } + + private function insertDataValue($name, $value){ + Yii::$app->db->createCommand()->insert(ItemData::tableName(), [ + 'item_id' => $this->primaryKey, + 'name' => $name, + 'value' => $value + ])->execute(); + } + public function afterFind() { parent::afterFind(); - $this->data = $this->data !== '' ? json_decode($this->data) : []; + $this->parseData(); } public function getPhotos() { - return $this->hasMany(Photo::className(), ['item_id' => 'item_id'])->where(['model' => Item::className()])->sort(); + return $this->hasMany(Photo::className(), ['item_id' => 'item_id'])->where(['class' => Item::className()])->sort(); } public function getCategory() @@ -98,5 +132,11 @@ public function afterDelete() if($this->image) { @unlink(Yii::getAlias('@webroot') . $this->image); } + + ItemData::deleteAll(['item_id' => $this->primaryKey]); + } + + private function parseData(){ + $this->data = $this->data !== '' ? json_decode($this->data) : []; } } \ No newline at end of file diff --git a/modules/catalog/models/ItemData.php b/modules/catalog/models/ItemData.php new file mode 100644 index 0000000..a0a28f8 --- /dev/null +++ b/modules/catalog/models/ItemData.php @@ -0,0 +1,17 @@ + ['enctype' => 'multipart/form-data'] + 'options' => ['enctype' => 'multipart/form-data', 'class' => 'model-form'] ]); ?> field($model, 'title') ?> @@ -33,6 +34,12 @@ ]) ?> +field($model, 'available') ?> +field($model, 'price') ?> +field($model, 'discount') ?> + +field($model, 'time')->widget(DateTimePicker::className()); ?> + field($model, 'slug') ?> $model]) ?> diff --git a/modules/catalog/views/items/index.php b/modules/catalog/views/items/index.php index 4356293..50443c7 100644 --- a/modules/catalog/views/items/index.php +++ b/modules/catalog/views/items/index.php @@ -1,4 +1,6 @@ title = Yii::t('easyii/catalog', 'Catalog'); @@ -15,6 +17,7 @@ # + @@ -25,6 +28,13 @@ primaryKey ?> title ?> + + status == Item::STATUS_ON, [ + 'class' => 'switch', + 'data-id' => $item->primaryKey, + 'data-link' => Url::to(['/admin/'.$module.'/items']), + ]) ?> +
diff --git a/modules/faq/controllers/AController.php b/modules/faq/controllers/AController.php index 4296f1c..da25aa4 100644 --- a/modules/faq/controllers/AController.php +++ b/modules/faq/controllers/AController.php @@ -102,7 +102,7 @@ public function actionDelete($id) { if(($model = Faq::findOne($id))){ $model->delete(); - } else{ + } else { $this->error = Yii::t('easyii', 'Not found'); } return $this->formatResponse(Yii::t('easyii/faq', 'Entry deleted')); diff --git a/modules/faq/views/a/_form.php b/modules/faq/views/a/_form.php index 9d44355..bb1fbfd 100644 --- a/modules/faq/views/a/_form.php +++ b/modules/faq/views/a/_form.php @@ -3,7 +3,9 @@ use yii\widgets\ActiveForm; use yii\easyii\widgets\Redactor; ?> - + ['class' => 'model-form'] +]); ?> field($model, 'question')->widget(Redactor::className(),[ 'options' => [ 'minHeight' => 300, diff --git a/modules/feedback/FeedbackModule.php b/modules/feedback/FeedbackModule.php index 70b1cf8..9438021 100644 --- a/modules/feedback/FeedbackModule.php +++ b/modules/feedback/FeedbackModule.php @@ -4,10 +4,17 @@ class FeedbackModule extends \yii\easyii\components\Module { public $settings = [ + 'mailAdminOnNewFeedback' => true, + 'subjectOnNewFeedback' => 'New feedback', + 'templateOnNewFeedback' => '@easyii/modules/feedback/mail/en/new_feedback', + + 'answerTemplate' => '@easyii/modules/feedback/mail/en/answer', + 'answerSubject' => 'Answer on your feedback message', + 'answerHeader' => 'Hello,', + 'answerFooter' => 'Best regards.', + 'enableTitle' => false, 'enablePhone' => true, - 'answerHello' => 'Hello,', - 'answerFooter' => 'Best regards.', 'enableCaptcha' => false, ]; diff --git a/modules/feedback/api/Feedback.php b/modules/feedback/api/Feedback.php index cd86c60..0132a1c 100644 --- a/modules/feedback/api/Feedback.php +++ b/modules/feedback/api/Feedback.php @@ -7,7 +7,6 @@ use yii\helpers\Html; use yii\helpers\Url; use yii\widgets\ActiveForm; -use yii\bootstrap\Alert; use yii\easyii\widgets\ReCaptcha; class Feedback extends \yii\easyii\components\API @@ -15,7 +14,8 @@ class Feedback extends \yii\easyii\components\API const SENT_VAR = 'feedback_sent'; private $_defaultFormOptions = [ - 'showAlert' => true + 'errorUrl' => '', + 'successUrl' => '' ]; public function api_form($options = []) @@ -30,19 +30,12 @@ public function api_form($options = []) 'action' => Url::to(['/admin/feedback/send']) ]); - echo Html::hiddenInput('returnUrl', Yii::$app->controller->route); - - if($options['showAlert']) { - $sent = Yii::$app->request->get(self::SENT_VAR); - if ($sent == "1") { - echo Alert::widget(['options' => ['class' => 'alert-success'], 'body' => Yii::t('easyii/feedback/api', 'Feedback sent. We will answer you soon')]); - } elseif ($sent == "0") { - echo Alert::widget(['options' => ['class' => 'alert-danger'], 'body' => Yii::t('easyii/guestbook/api', 'An error has occurred')]); - } - } + echo Html::hiddenInput('errorUrl', $options['errorUrl'] ? $options['errorUrl'] : Url::current([self::SENT_VAR => 0])); + echo Html::hiddenInput('successUrl', $options['successUrl'] ? $options['successUrl'] : Url::current([self::SENT_VAR => 1])); echo $form->field($model, 'name'); echo $form->field($model, 'email')->input('email'); + if($settings['enablePhone']) echo $form->field($model, 'phone'); if($settings['enableTitle']) echo $form->field($model, 'title'); @@ -61,7 +54,7 @@ public function api_save($data) $model = new FeedbackModel($data); if($model->save()){ return ['result' => 'success']; - } else{ + } else { return ['result' => 'error', 'error' => $model->getErrors()]; } } diff --git a/modules/feedback/controllers/AController.php b/modules/feedback/controllers/AController.php index 1e5f9b1..1c19a9e 100644 --- a/modules/feedback/controllers/AController.php +++ b/modules/feedback/controllers/AController.php @@ -69,15 +69,19 @@ public function actionView($id) $model->update(); } - if (Yii::$app->request->post('Feedback')) { + $postData = Yii::$app->request->post('Feedback'); + if($postData) { if(filter_var(Setting::get('admin_email'), FILTER_VALIDATE_EMAIL)) { - $model->answer = trim(Yii::$app->request->post('Feedback')['answer']); - if($this->sendAnswer($model)){ + $model->answer_subject = filter_var($postData['answer_subject'], FILTER_SANITIZE_STRING); + $model->answer_text = filter_var($postData['answer_text'], FILTER_SANITIZE_STRING); + if($model->sendAnswer()){ + $model->status = Feedback::STATUS_ANSWERED; + $model->save(); $this->flash('success', Yii::t('easyii/feedback', 'Answer successfully sent')); } else{ - $this->flash('error', Yii::t('easyii/feedback/api', 'An error has occurred')); + $this->flash('error', Yii::t('easyii/feedback', 'An error has occurred while sending mail')); } } else { @@ -87,9 +91,10 @@ public function actionView($id) return $this->refresh(); } else { - if(!$model->answer) { - if ($this->module->settings['answerHello']) $model->answer = Yii::t('easyii/feedback', $this->module->settings['answerHello']) . " " . $model->name . ".\n"; - if ($this->module->settings['answerFooter']) $model->answer .= "\n\n" . Yii::t('easyii/feedback', $this->module->settings['answerFooter']); + if(!$model->answer_text) { + $model->answer_subject = Yii::t('easyii/feedback', $this->module->settings['answerSubject']); + if ($this->module->settings['answerHeader']) $model->answer_text = Yii::t('easyii/feedback', $this->module->settings['answerHeader']) . " " . $model->name . ".\n"; + if ($this->module->settings['answerFooter']) $model->answer_text .= "\n\n" . Yii::t('easyii/feedback', $this->module->settings['answerFooter']); } return $this->render('view', [ @@ -106,7 +111,7 @@ public function actionSetAnswer($id) $this->flash('error', Yii::t('easyii', 'Not found')); } else{ - $model->status = Feedback::STATUS_ANSWER; + $model->status = Feedback::STATUS_ANSWERED; if($model->update()) { $this->flash('success', Yii::t('easyii/feedback', 'Feedback updated')); } @@ -121,36 +126,9 @@ public function actionDelete($id) { if(($model = Feedback::findOne($id))){ $model->delete(); - } else{ + } else { $this->error = Yii::t('easyii', 'Not found'); } return $this->formatResponse(Yii::t('easyii/feedback', 'Feedback deleted')); } - - public function sendAnswer($model) - { - $text = $model->answer; - $text .= "\n\n\n"; - $text .= "-------------------------------------------------------------------------------- \n"; - $text .= Yii::$app->formatter->asDatetime($model->time, 'medium') . " you wrote: \n"; - - foreach(explode("\n", $model->text) as $line){ - $text .= '> '.$line; - } - $sent = Yii::$app->mailer->compose() - ->setFrom(Setting::get('robot_email')) - ->setTo($model->email) - ->setSubject(strtoupper(Yii::$app->request->serverName).' '.Yii::t('easyii/feedback', 'feedback answer')) - ->setTextBody($text) - ->setReplyTo(Setting::get('admin_email')) - ->send(); - - if($sent) { - $model->status = Feedback::STATUS_ANSWER; - $model->update(); - return true; - } - - return false; - } } \ No newline at end of file diff --git a/modules/feedback/controllers/SendController.php b/modules/feedback/controllers/SendController.php index 2f8e0dc..3e64042 100644 --- a/modules/feedback/controllers/SendController.php +++ b/modules/feedback/controllers/SendController.php @@ -2,8 +2,6 @@ namespace yii\easyii\modules\feedback\controllers; use Yii; - -use yii\easyii\modules\feedback\api\Feedback; use yii\easyii\modules\feedback\models\Feedback as FeedbackModel; class SendController extends \yii\web\Controller @@ -15,8 +13,8 @@ public function actionIndex() $request = Yii::$app->request; if ($model->load($request->post())) { - $sent = $model->save() ? 1 : 0; - return $this->redirect(['/' . $request->post('returnUrl'), Feedback::SENT_VAR => $sent]); + $returnUrl = $model->save() ? $request->post('successUrl') : $request->post('errorUrl'); + return $this->redirect($returnUrl); } else { return $this->redirect(Yii::$app->request->baseUrl); } diff --git a/modules/feedback/mail/en/answer.php b/modules/feedback/mail/en/answer.php new file mode 100644 index 0000000..ab2bc23 --- /dev/null +++ b/modules/feedback/mail/en/answer.php @@ -0,0 +1,11 @@ +title = $subject; +?> +

answer_text) ?>

+
+
+
+

formatter->asDatetime($feedback->time, 'medium') ?> you wrote:

+

+ text) as $line) echo '> '.$line.'
'; ?> +

\ No newline at end of file diff --git a/modules/feedback/mail/en/new_feedback.php b/modules/feedback/mail/en/new_feedback.php new file mode 100644 index 0000000..f815d8e --- /dev/null +++ b/modules/feedback/mail/en/new_feedback.php @@ -0,0 +1,7 @@ +title = $subject; +?> +

User name ?> leaved message in your guestbook.

+

You can view it .

\ No newline at end of file diff --git a/modules/feedback/mail/ru/answer.php b/modules/feedback/mail/ru/answer.php new file mode 100644 index 0000000..c0a581a --- /dev/null +++ b/modules/feedback/mail/ru/answer.php @@ -0,0 +1,11 @@ +title = $subject; +?> +

answer_text) ?>

+
+
+
+

formatter->asDatetime($feedback->time, 'medium') ?> Вы писали:

+

+ text) as $line) echo '> '.$line.'
'; ?> +

\ No newline at end of file diff --git a/modules/feedback/mail/ru/new_feedback.php b/modules/feedback/mail/ru/new_feedback.php new file mode 100644 index 0000000..07e1060 --- /dev/null +++ b/modules/feedback/mail/ru/new_feedback.php @@ -0,0 +1,9 @@ +title = $subject; +?> +

Пользователь name ?> оставил сообщение в вашей гостевой книге.

+

Просмотреть его вы можете .

+
+

Это автоматическое сообщение и на него не нужно отвечатью

\ No newline at end of file diff --git a/modules/feedback/messages/ru/admin.php b/modules/feedback/messages/ru/admin.php index 480a1e2..b4390a2 100644 --- a/modules/feedback/messages/ru/admin.php +++ b/modules/feedback/messages/ru/admin.php @@ -5,13 +5,16 @@ 'Feedback deleted' => 'Обращение удалено', 'Feedback updated' => 'Обращение обновлено', 'Answer' => 'Ответ', + 'Subject' => 'Тема', 'Phone' => 'Телефон', 'No answer' => 'Без ответа', 'Hello,' => 'Здравствуйте,', + 'Answer on your feedback message' => 'Ответ на ваше обращение', 'Best regards.' => 'С наилучшими пожеланиями.', 'Answer successfully sent' => 'Ответ успешно отправлен', 'Mark as answered' => 'Отметить отвеченным', 'feedback answer' => 'обратная связь', 'Please fill correct `Admin E-mail` in Settings' => 'Пожалуйста укажите корректный `E-mail Администратора` в разделе Настройки', - 'Are you sure you want to resend the answer?' => 'Вы уверены, что хотите послать ответ повторно?' + 'Are you sure you want to resend the answer?' => 'Вы уверены, что хотите послать ответ повторно?', + 'An error has occurred while sending mail' => 'Произошла ошибка при отправке письма', ]; \ No newline at end of file diff --git a/modules/feedback/models/Feedback.php b/modules/feedback/models/Feedback.php index 637fdc8..b7c47ce 100644 --- a/modules/feedback/models/Feedback.php +++ b/modules/feedback/models/Feedback.php @@ -3,6 +3,8 @@ use Yii; use yii\easyii\behaviors\CalculateNotice; +use yii\easyii\helpers\Mail; +use yii\easyii\models\Setting; use yii\easyii\validators\ReCaptchaValidator; use yii\easyii\validators\EscapeValidator; @@ -10,7 +12,7 @@ class Feedback extends \yii\easyii\components\ActiveRecord { const STATUS_NEW = 0; const STATUS_VIEW = 1; - const STATUS_ANSWER = 2; + const STATUS_ANSWERED = 2; const FLASH_KEY = 'eaysiicms_feedback_send_result'; @@ -57,7 +59,8 @@ public function attributeLabels() 'name' => Yii::t('easyii', 'Name'), 'title' => Yii::t('easyii', 'Title'), 'text' => Yii::t('easyii', 'Text'), - 'answer' => Yii::t('easyii/feedback', 'Answer'), + 'answer_subject' => Yii::t('easyii/feedback', 'Subject'), + 'answer_text' => Yii::t('easyii', 'Text'), 'phone' => Yii::t('easyii/feedback', 'Phone'), 'reCaptcha' => Yii::t('easyii', 'Anti-spam check') ]; @@ -74,4 +77,32 @@ public function behaviors() ] ]; } + + public function mailAdmin() + { + $settings = Yii::$app->getModule('admin')->activeModules['feedback']->settings; + + if(!$settings['mailAdminOnNewFeedback']){ + return false; + } + return Mail::send( + Setting::get('admin_email'), + $settings['subjectOnNewFeedback'], + $settings['templateOnNewFeedback'], + ['feedback' => $this] + ); + } + + public function sendAnswer() + { + $settings = Yii::$app->getModule('admin')->activeModules['feedback']->settings; + + return Mail::send( + $this->email, + $this->answer_subject, + $settings['answerTemplate'], + ['feedback' => $this], + ['replyTo' => Setting::get('admin_email')] + ); + } } \ No newline at end of file diff --git a/modules/feedback/views/a/_menu.php b/modules/feedback/views/a/_menu.php index f3ebf35..c512569 100644 --- a/modules/feedback/views/a/_menu.php +++ b/modules/feedback/views/a/_menu.php @@ -19,7 +19,7 @@ } elseif(strpos($returnUrl, 'all') !== false) { $backTo = 'all'; $allUrl = $returnUrl; - } else{ + } else { $backTo = 'index'; $indexUrl = $returnUrl; } diff --git a/modules/feedback/views/a/index.php b/modules/feedback/views/a/index.php index 32b42c1..0572210 100644 --- a/modules/feedback/views/a/index.php +++ b/modules/feedback/views/a/index.php @@ -31,7 +31,7 @@ context->module->settings['enableTitle'] && $item->title != '') ? $item->title : StringHelper::truncate($item->text, 64, '...')?> formatter->asDatetime($item->time, 'short') ?> - status == Feedback::STATUS_ANSWER) : ?> + status == Feedback::STATUS_ANSWERED) : ?> diff --git a/modules/feedback/views/a/view.php b/modules/feedback/views/a/view.php index 904c8c8..ae27567 100644 --- a/modules/feedback/views/a/view.php +++ b/modules/feedback/views/a/view.php @@ -1,15 +1,16 @@ title = Yii::t('easyii/feedback', 'View feedback'); $this->registerCss('.feedback-view dt{margin-bottom: 10px;}'); -if($model->status == Feedback::STATUS_ANSWER) { +if($model->status == Feedback::STATUS_ANSWERED) { $this->registerJs('$(".send-answer").click(function(){return confirm("'.Yii::t('easyii/feedback', 'Are you sure you want to resend the answer?').'");})'); } ?> -render('_menu', ['noanswer' => $model->status == Feedback::STATUS_ANSWER]) ?> +render('_menu', ['noanswer' => $model->status == Feedback::STATUS_ANSWERED]) ?>