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']
]); ?>
= $form->field($model, 'title') ?>
@@ -35,6 +36,10 @@
]
]) ?>
+= $form->field($model, 'time')->widget(DateTimePicker::className()); ?>
+
+
+
= $form->field($model, 'slug') ?>
= SeoForm::widget(['model' => $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;
?>
= $this->render('_menu', ['category' => $model->category]) ?>
+context->module->settings['enablePhotos']) echo $this->render('_submenu', ['model' => $model]) ?>
+
= $this->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 @@
= Yii::t('easyii', 'Title') ?>
= Yii::t('easyii', 'Views') ?>
+ = Yii::t('easyii', 'Status') ?>
@@ -27,6 +30,13 @@
= $item->title ?>
= $item->views ?>
+
+ = Html::checkbox('', $item->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;
+?>
+
+= $this->render('_menu', ['category' => $model->category]) ?>
+= $this->render('_submenu', ['model' => $model]) ?>
+
+= Photos::widget(['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']
]); ?>
= $form->field($model, 'title') ?>
@@ -33,6 +34,12 @@
]) ?>
+= $form->field($model, 'available') ?>
+= $form->field($model, 'price') ?>
+= $form->field($model, 'discount') ?>
+
+= $form->field($model, 'time')->widget(DateTimePicker::className()); ?>
+
= $form->field($model, 'slug') ?>
= SeoForm::widget(['model' => $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 @@
#
= Yii::t('easyii', 'Name') ?>
+
= Yii::t('easyii', 'Status') ?>
@@ -25,6 +28,13 @@
= $item->primaryKey ?>
= $item->title ?>
+
+ = Html::checkbox('', $item->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']
+]); ?>
= $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;
+?>
+
= nl2br($feedback->answer_text) ?>
+
+
+
+
= Yii::$app->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 = $post->name ?> leaved message in your guestbook.
+
You can view it = Html::a('here', $link) ?>.
\ 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;
+?>
+
= nl2br($feedback->answer_text) ?>
+
+
+
+
= Yii::$app->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;
+?>
+
Пользователь = $post->name ?> оставил сообщение в вашей гостевой книге.
+
Просмотреть его вы можете = Html::a('здесь', $link) ?>.
+
+
Это автоматическое сообщение и на него не нужно отвечатью
\ 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 @@
= ($this->context->module->settings['enableTitle'] && $item->title != '') ? $item->title : StringHelper::truncate($item->text, 64, '...')?>
= Yii::$app->formatter->asDatetime($item->time, 'short') ?>
- status == Feedback::STATUS_ANSWER) : ?>
+ status == Feedback::STATUS_ANSWERED) : ?>
= Yii::t('easyii', 'Yes') ?>
= Yii::t('easyii', 'No') ?>
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?').'");})');
}
?>
-= $this->render('_menu', ['noanswer' => $model->status == Feedback::STATUS_ANSWER]) ?>
+= $this->render('_menu', ['noanswer' => $model->status == Feedback::STATUS_ANSWERED]) ?>
= Yii::t('easyii', 'Name') ?>
@@ -41,9 +42,8 @@
= Yii::t('easyii/feedback', 'Answer') ?>
-= Html::beginForm() ?>
-
- = Html::textarea('Feedback[answer]', $model->answer, ['class' => 'form-control', 'style' => 'height: 250px']) ?>
-
+
+ = $form->field($model, 'answer_subject') ?>
+ = $form->field($model, 'answer_text')->textarea(['style' => 'height: 250px']) ?>
= Html::submitButton(Yii::t('easyii', 'Send'), ['class' => 'btn btn-success send-answer']) ?>
-= Html::endForm() ?>
\ No newline at end of file
+
\ No newline at end of file
diff --git a/modules/file/api/File.php b/modules/file/api/File.php
index 6b47dc8..8327d23 100644
--- a/modules/file/api/File.php
+++ b/modules/file/api/File.php
@@ -11,7 +11,7 @@ class File extends \yii\easyii\components\API
private $_adp;
private $_last;
private $_items;
- private $_files;
+ private $_item = [];
public function api_items($options = [])
{
@@ -38,10 +38,10 @@ public function api_items($options = [])
public function api_get($id_slug)
{
- if(!isset($this->_files[$id_slug])) {
- $this->_files[$id_slug] = $this->findFile($id_slug);
+ if(!isset($this->_item[$id_slug])) {
+ $this->_item[$id_slug] = $this->findFile($id_slug);
}
- return $this->_files[$id_slug];
+ return $this->_item[$id_slug];
}
public function api_last($limit = 1, $where = null)
diff --git a/modules/file/controllers/AController.php b/modules/file/controllers/AController.php
index 23aa1a3..fb7cbea 100644
--- a/modules/file/controllers/AController.php
+++ b/modules/file/controllers/AController.php
@@ -129,7 +129,7 @@ public function actionDelete($id)
{
if(($model = File::findOne($id))){
$model->delete();
- } else{
+ } else {
$this->error = Yii::t('easyii', 'Not found');
}
return $this->formatResponse(Yii::t('easyii/file', 'File deleted'));
diff --git a/modules/file/models/File.php b/modules/file/models/File.php
index 4679eb9..332bf86 100644
--- a/modules/file/models/File.php
+++ b/modules/file/models/File.php
@@ -40,7 +40,7 @@ public function behaviors()
{
return [
SortableModel::className(),
- 'seo' => SeoBehavior::className(),
+ 'seoBehavior' => SeoBehavior::className(),
'sluggable' => [
'class' => SluggableBehavior::className(),
'attribute' => 'title',
diff --git a/modules/file/views/a/_form.php b/modules/file/views/a/_form.php
index 3ea7a42..f5f4268 100644
--- a/modules/file/views/a/_form.php
+++ b/modules/file/views/a/_form.php
@@ -5,7 +5,7 @@
?>
true,
- 'options' => ['enctype' => 'multipart/form-data']
+ 'options' => ['enctype' => 'multipart/form-data', 'class' => 'model-form']
]); ?>
= $form->field($model, 'title') ?>
= $form->field($model, 'file')->fileInput() ?>
diff --git a/modules/gallery/GalleryModule.php b/modules/gallery/GalleryModule.php
index af1ee9a..58025ba 100644
--- a/modules/gallery/GalleryModule.php
+++ b/modules/gallery/GalleryModule.php
@@ -4,15 +4,8 @@
class GalleryModule extends \yii\easyii\components\Module
{
public $settings = [
- 'photoMaxWidth' => 1280,
- 'photoThumbWidth' => 100,
- 'photoThumbHeight' => 100,
- 'photoThumbCrop' => true,
-
- 'albumThumb' => true,
- 'albumThumbWidth' => 100,
- 'albumThumbHeight' => 100,
- 'albumThumbCrop' => true,
+ 'categoryThumb' => true,
+ 'itemsInFolder' => false,
];
public static $installConfig = [
diff --git a/modules/gallery/api/AlbumObject.php b/modules/gallery/api/AlbumObject.php
index f1ef3ce..5addf30 100644
--- a/modules/gallery/api/AlbumObject.php
+++ b/modules/gallery/api/AlbumObject.php
@@ -4,7 +4,7 @@
use yii\data\ActiveDataProvider;
use yii\easyii\components\API;
use yii\easyii\models\Photo;
-use yii\easyii\modules\gallery\models\Album;
+use yii\easyii\modules\gallery\models\Category;
use yii\helpers\Url;
use yii\widgets\LinkPager;
@@ -22,8 +22,8 @@ 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(){
@@ -35,10 +35,10 @@ public function photos($options = [])
if(!$this->_photos){
$this->_photos = [];
- $query = Photo::find()->where(['model' => Album::className(), 'item_id' => $this->id])->sort();
+ $query = Photo::find()->where(['class' => Category::className(), 'item_id' => $this->id])->sort();
if(!empty($options['where'])){
- $query->where($options['where']);
+ $query->andFilterWhere($options['where']);
}
$this->_adp = new ActiveDataProvider([
diff --git a/modules/gallery/api/Gallery.php b/modules/gallery/api/Gallery.php
index 134be7f..ecc2f27 100644
--- a/modules/gallery/api/Gallery.php
+++ b/modules/gallery/api/Gallery.php
@@ -2,76 +2,71 @@
namespace yii\easyii\modules\gallery\api;
use Yii;
-use yii\data\ActiveDataProvider;
-use yii\helpers\Url;
-use yii\widgets\LinkPager;
use yii\easyii\models\Photo;
+use yii\easyii\modules\gallery\models\Category;
use yii\easyii\widgets\Fancybox;
-use yii\easyii\modules\gallery\models\Album;
class Gallery extends \yii\easyii\components\API
{
- private $_adp;
+ private $_cats;
+ private $_photos;
private $_last;
- private $_items;
- private $_albums;
- public function api_items($options = [])
+ public function api_cat($id_slug)
{
- if (!$this->_items) {
- $this->_items = [];
-
- $query = Album::find()->with('seo')->status(Album::STATUS_ON)->sort();
-
- if(!empty($options['where'])){
- $query->where($options['where']);
- }
-
- $this->_adp = new ActiveDataProvider([
- 'query' => $query,
- 'pagination' => !empty($options['pagination']) ? $options['pagination'] : []
- ]);
-
- foreach ($this->_adp->models as $model) {
- $this->_items[] = new AlbumObject($model);
- }
+ if(!isset($this->_cats[$id_slug])) {
+ $this->_cats[$id_slug] = $this->findCategory($id_slug);
}
- return $this->_items;
+ return $this->_cats[$id_slug];
}
- public function api_cat($id_slug)
+ public function api_tree()
{
- if (!isset($this->_albums[$id_slug])) {
- $this->_albums[$id_slug] = $this->findAlbum($id_slug);
- }
- return $this->_albums[$id_slug];
+ return Category::tree();
}
+ public function api_cats()
+ {
+ return Category::cats();
+ }
+
+
public function api_last($limit = 1, $where = null)
{
- if ($limit === 1 && $this->_last) {
+ if($limit === 1 && $this->_last){
return $this->_last;
}
$result = [];
- $query = Album::find()->with('seo')->sort()->limit($limit);
+ $query = Photo::find()->where(['class' => Category::className()])->sort()->limit($limit);
if($where){
- $query->where($where);
+ $query->andWhere($where);
}
- foreach($query->all() as $item) {
- $result[] = new AlbumObject($item);
+
+ foreach($query->all() as $item){
+ $photoObject = new PhotoObject($item);
+ $photoObject->rel = 'last';
+ $result[] = $photoObject;
}
- if ($limit > 1) {
+ if($limit > 1){
return $result;
- } else {
+ }else{
$this->_last = count($result) ? $result[0] : null;
return $this->_last;
}
}
+ public function api_get($id)
+ {
+ if(!isset($this->_photos[$id])) {
+ $this->_photos[$id] = $this->findPhoto($id);
+ }
+ return $this->_photos[$id];
+ }
+
public function api_plugin($options = [])
{
Fancybox::widget([
@@ -80,26 +75,15 @@ public function api_plugin($options = [])
]);
}
- public function api_photo($id)
+ private function findCategory($id_slug)
{
- $photo = Photo::findOne($id);
- return $photo ? $photo->image : null;
- }
+ $category = Category::find()->where(['or', 'category_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Category::STATUS_ON)->one();
- public function api_pagination()
- {
- return $this->_adp ? $this->_adp->pagination : null;
+ return $category ? new AlbumObject($category) : null;
}
- public function api_pages()
+ private function findPhoto($id)
{
- return $this->_adp ? LinkPager::widget(['pagination' => $this->_adp->pagination]) : '';
- }
-
- private function findAlbum($id_slug)
- {
- $album = Album::find()->where(['or', 'album_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->one();
-
- return $album ? new AlbumObject($album) : null;
+ return Photo::findOne($id);
}
}
\ No newline at end of file
diff --git a/modules/gallery/api/PhotoObject.php b/modules/gallery/api/PhotoObject.php
index 04093f8..94b34c2 100644
--- a/modules/gallery/api/PhotoObject.php
+++ b/modules/gallery/api/PhotoObject.php
@@ -10,17 +10,19 @@ class PhotoObject extends \yii\easyii\components\ApiObject
{
public $image;
public $description;
+ public $rel;
- 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' => 'album-' . ($this->rel ? $this->rel : $this->model->item_id),
'title' => $this->description
- ]));
+ ]);
return LIVE_EDIT ? API::liveEdit($a, $this->editLink) : $a;
}
public function getEditLink(){
- return Url::to(['/admin/gallery/a/photos/', 'id' => $this->id.'#'.'photo-'.$this->id]);
+ return Url::to(['/admin/gallery/a/photos', 'id' => $this->model->item_id]).'#photo-'.$this->id;
}
}
\ No newline at end of file
diff --git a/modules/gallery/models/Category.php b/modules/gallery/models/Category.php
new file mode 100644
index 0000000..10544ce
--- /dev/null
+++ b/modules/gallery/models/Category.php
@@ -0,0 +1,26 @@
+hasMany(Photo::className(), ['item_id' => 'category_id'])->where(['class' => self::className()])->sort();
+ }
+
+ public function afterDelete()
+ {
+ parent::afterDelete();
+
+ foreach($this->getPhotos()->all() as $photo){
+ $photo->delete();
+ }
+ }
+}
\ No newline at end of file
diff --git a/modules/gallery/views/a/_submenu.php b/modules/gallery/views/a/_submenu.php
index b077d67..b282aff 100644
--- a/modules/gallery/views/a/_submenu.php
+++ b/modules/gallery/views/a/_submenu.php
@@ -7,6 +7,6 @@
\ No newline at end of file
diff --git a/modules/gallery/views/a/photos.php b/modules/gallery/views/a/photos.php
index 31f7ff3..1559bc4 100644
--- a/modules/gallery/views/a/photos.php
+++ b/modules/gallery/views/a/photos.php
@@ -4,7 +4,6 @@
$this->title = $model->title;
?>
-= $this->render('_menu') ?>
-= $this->render('_submenu', ['model' => $model]) ?>
+= $this->render('@easyii/views/category/_menu') ?>
= Photos::widget(['model' => $model])?>
\ No newline at end of file
diff --git a/modules/guestbook/api/Guestbook.php b/modules/guestbook/api/Guestbook.php
index 0db4668..88d71a4 100644
--- a/modules/guestbook/api/Guestbook.php
+++ b/modules/guestbook/api/Guestbook.php
@@ -7,8 +7,6 @@
use yii\widgets\LinkPager;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
-use yii\bootstrap\Alert;
-
use yii\easyii\modules\guestbook\models\Guestbook as GuestbookModel;
use yii\easyii\widgets\ReCaptcha;
@@ -22,7 +20,8 @@ class Guestbook extends \yii\easyii\components\API
private $_items;
private $_defaultFormOptions = [
- 'showAlert' => true
+ 'errorUrl' => '',
+ 'successUrl' => ''
];
public function api_items($options = [])
@@ -30,10 +29,10 @@ public function api_items($options = [])
if(!$this->_items){
$this->_items = [];
- $query = GuestbookModel::find()->status(GuestbookModel::STATUS_ON)->orderBy('time DESC');
+ $query = GuestbookModel::find()->status(GuestbookModel::STATUS_ON)->sortDate();
if(!empty($options['where'])){
- $query->where($options['where']);
+ $query->andFilterWhere($options['where']);
}
$this->_adp = new ActiveDataProvider([
@@ -55,7 +54,7 @@ public function api_last($limit = 1)
}
$result = [];
- foreach(GuestbookModel::find()->orderBy('time DESC')->limit($limit)->all() as $item){
+ foreach(GuestbookModel::find()->status(GuestbookModel::STATUS_ON)->sortDate()->limit($limit)->all() as $item){
$result[] = new GuestbookObject($item);
}
@@ -79,27 +78,16 @@ public function api_form($options = [])
'action' => Url::to(['/admin/guestbook/send'])
]);
- echo Html::hiddenInput('returnUrl', Yii::$app->controller->route);
-
- if($options['showAlert']) {
- $sent = Yii::$app->request->get(self::SENT_VAR);
- if ($sent == "1") {
- $message = Yii::$app->getModule('admin')->activeModules['guestbook']->settings['preModerate'] ?
- Yii::t('easyii/guestbook/api', 'Message successfully sent and will be published after moderation') :
- Yii::t('easyii/guestbook/api', 'Message successfully added');
+ 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 Alert::widget(['options' => ['class' => 'alert-success'], 'body' => $message]);
- } elseif ($sent == "0") {
- echo Alert::widget(['options' => ['class' => 'alert-danger'], 'body' => Yii::t('easyii/guestbook/api', 'An error has occurred')]);
- }
- }
echo $form->field($model, 'name');
+
if($settings['enableTitle']) echo $form->field($model, 'title');
if($settings['enableEmail']) echo $form->field($model, 'email');
echo $form->field($model, 'text')->textarea();
-
if($settings['enableCaptcha']) echo $form->field($model, 'reCaptcha')->widget(ReCaptcha::className());
echo Html::submitButton(Yii::t('easyii', 'Send'), ['class' => 'btn btn-primary']);
diff --git a/modules/guestbook/controllers/AController.php b/modules/guestbook/controllers/AController.php
index de91071..def22d1 100644
--- a/modules/guestbook/controllers/AController.php
+++ b/modules/guestbook/controllers/AController.php
@@ -92,7 +92,7 @@ public function actionDelete($id)
{
if(($model = Guestbook::findOne($id))){
$model->delete();
- } else{
+ } else {
$this->error = Yii::t('easyii', 'Not found');
}
return $this->formatResponse(Yii::t('easyii/guestbook', 'Entry deleted'));
diff --git a/modules/guestbook/controllers/SendController.php b/modules/guestbook/controllers/SendController.php
index 9efd856..79b1d38 100644
--- a/modules/guestbook/controllers/SendController.php
+++ b/modules/guestbook/controllers/SendController.php
@@ -2,7 +2,6 @@
namespace yii\easyii\modules\guestbook\controllers;
use Yii;
-use yii\easyii\modules\guestbook\api\Guestbook;
use yii\easyii\modules\guestbook\models\Guestbook as GuestbookModel;
class SendController extends \yii\web\Controller
@@ -13,8 +12,8 @@ public function actionIndex()
$request = Yii::$app->request;
if ($model->load($request->post())) {
- $sent = $model->save() ? 1 : 0;
- return $this->redirect(['/' . $request->post('returnUrl'), Guestbook::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/guestbook/mail/ru/new_post.php b/modules/guestbook/mail/ru/new_post.php
index ab077c7..07e1060 100644
--- a/modules/guestbook/mail/ru/new_post.php
+++ b/modules/guestbook/mail/ru/new_post.php
@@ -4,4 +4,6 @@
$this->title = $subject;
?>
Пользователь = $post->name ?> оставил сообщение в вашей гостевой книге.
-Просмотреть его вы можете = Html::a('здесь', $link) ?>.
\ No newline at end of file
+Просмотреть его вы можете = Html::a('здесь', $link) ?>.
+
+Это автоматическое сообщение и на него не нужно отвечатью
\ No newline at end of file
diff --git a/modules/guestbook/messages/ru/api.php b/modules/guestbook/messages/ru/api.php
deleted file mode 100644
index 3721913..0000000
--- a/modules/guestbook/messages/ru/api.php
+++ /dev/null
@@ -1,6 +0,0 @@
- 'Сообщение отправлено и будет опубликовано после проверки',
- 'Message successfully added' => 'Сообщение успешно добавлено',
- 'An error has occurred' => 'Произошла ошибка',
-];
\ No newline at end of file
diff --git a/modules/guestbook/models/Guestbook.php b/modules/guestbook/models/Guestbook.php
index f433afa..0355eac 100644
--- a/modules/guestbook/models/Guestbook.php
+++ b/modules/guestbook/models/Guestbook.php
@@ -3,6 +3,7 @@
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;
@@ -87,37 +88,32 @@ public function mailAdmin()
{
$settings = Yii::$app->getModule('admin')->activeModules['guestbook']->settings;
- if(!$settings['mailAdminOnNewPost'] || !$settings['templateOnNewPost'] || !$settings['subjectOnNewPost']) {
+ if(!$settings['mailAdminOnNewPost']){
return false;
}
-
- return $this->mail($settings['templateOnNewPost'], $settings['subjectOnNewPost'], Url::to(['/admin/guestbook/a/view', 'id' => $this->primaryKey], true));
-
+ return Mail::send(
+ Setting::get('admin_email'),
+ $settings['subjectOnNewPost'],
+ $settings['templateOnNewPost'],
+ [
+ 'post' => $this,
+ 'link' => Url::to(['/admin/guestbook/a/view', 'id' => $this->primaryKey], true)
+ ]
+ );
}
public function notifyUser()
{
$settings = Yii::$app->getModule('admin')->activeModules['guestbook']->settings;
- if(!$settings['templateNotifyUser'] || !$settings['subjectNotifyUser'] || !$settings['frontendGuestbookRoute']) {
- return false;
- }
-
- return $this->mail($settings['templateNotifyUser'], $settings['subjectNotifyUser'], Url::to([$settings['frontendGuestbookRoute']], true));
- }
-
- private function mail($template, $subject, $link)
- {
- $robotEmail = Setting::get('robot_email');
- $adminEmail = Setting::get('admin_email');
- if(!$robotEmail || !$adminEmail){
- return false;
- }
-
- return Yii::$app->mailer->compose($template, ['post' => $this, 'subject' => $subject, 'link' => $link])
- ->setFrom($robotEmail)
- ->setTo($adminEmail)
- ->setSubject($subject)
- ->send();
+ return Mail::send(
+ $this->email,
+ $settings['subjectNotifyUser'],
+ $settings['templateNotifyUser'],
+ [
+ 'post' => $this,
+ 'link' => Url::to([$settings['frontendGuestbookRoute']], true)
+ ]
+ );
}
}
\ No newline at end of file
diff --git a/modules/guestbook/views/a/_menu.php b/modules/guestbook/views/a/_menu.php
index 6f11fcf..36a786d 100644
--- a/modules/guestbook/views/a/_menu.php
+++ b/modules/guestbook/views/a/_menu.php
@@ -15,7 +15,7 @@
if(strpos($returnUrl, 'noanswer') !== false){
$backTo = 'noanswer';
$noanswerUrl = $returnUrl;
- } else{
+ } else {
$backTo = 'index';
$indexUrl = $returnUrl;
}
diff --git a/modules/news/NewsModule.php b/modules/news/NewsModule.php
index 93ac4e0..ba6bec9 100644
--- a/modules/news/NewsModule.php
+++ b/modules/news/NewsModule.php
@@ -5,8 +5,9 @@ class NewsModule extends \yii\easyii\components\Module
{
public $settings = [
'enableThumb' => true,
+ 'enablePhotos' => true,
'enableShort' => true,
- 'shortMaxLength' => 256,
+ 'shortMaxLength' => 256
];
public static $installConfig = [
diff --git a/modules/news/api/News.php b/modules/news/api/News.php
index 688fb5d..22a05e2 100644
--- a/modules/news/api/News.php
+++ b/modules/news/api/News.php
@@ -3,6 +3,7 @@
use Yii;
use yii\data\ActiveDataProvider;
+use yii\easyii\widgets\Fancybox;
use yii\widgets\LinkPager;
use yii\easyii\modules\news\models\News as NewsModel;
@@ -12,17 +13,22 @@ class News extends \yii\easyii\components\API
private $_adp;
private $_last;
private $_items;
- private $_news = [];
+ private $_item = [];
public function api_items($options = [])
{
if(!$this->_items){
$this->_items = [];
- $query = NewsModel::find()->with('seo')->status(NewsModel::STATUS_ON)->orderBy('time DESC');
+ $query = NewsModel::find()->with('seo')->status(NewsModel::STATUS_ON);
if(!empty($options['where'])){
- $query->where($options['where']);
+ $query->andFilterWhere($options['where']);
+ }
+ if(!empty($options['orderBy'])){
+ $query->orderBy($options['orderBy']);
+ } else {
+ $query->sortDate();
}
$this->_adp = new ActiveDataProvider([
@@ -39,10 +45,10 @@ public function api_items($options = [])
public function api_get($id_slug)
{
- if(!isset($this->_news[$id_slug])) {
- $this->_news[$id_slug] = $this->findNews($id_slug);
+ if(!isset($this->_item[$id_slug])) {
+ $this->_item[$id_slug] = $this->findNews($id_slug);
}
- return $this->_news[$id_slug];
+ return $this->_item[$id_slug];
}
public function api_last($limit = 1)
@@ -52,7 +58,7 @@ public function api_last($limit = 1)
}
$result = [];
- foreach(NewsModel::find()->with('seo')->orderBy('time DESC')->limit($limit)->all() as $item){
+ foreach(NewsModel::find()->with('seo')->status(NewsModel::STATUS_ON)->sortDate()->limit($limit)->all() as $item){
$result[] = new NewsObject($item);
}
@@ -64,6 +70,14 @@ public function api_last($limit = 1)
}
}
+ public function api_plugin($options = [])
+ {
+ Fancybox::widget([
+ 'selector' => '.easyii-box',
+ 'options' => $options
+ ]);
+ }
+
public function api_pagination()
{
return $this->_adp ? $this->_adp->pagination : null;
@@ -76,7 +90,7 @@ public function api_pages()
private function findNews($id_slug)
{
- $news = NewsModel::find()->where(['or', 'news_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->one();
+ $news = NewsModel::find()->where(['or', 'news_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(NewsModel::STATUS_ON)->one();
if($news) {
$news->updateCounters(['views' => 1]);
return new NewsObject($news);
diff --git a/modules/news/api/NewsObject.php b/modules/news/api/NewsObject.php
index d9081c5..4ed95fc 100644
--- a/modules/news/api/NewsObject.php
+++ b/modules/news/api/NewsObject.php
@@ -1,7 +1,10 @@
model->title, $this->editLink) : $this->model->title;
}
@@ -23,6 +28,22 @@ public function getText(){
return LIVE_EDIT ? API::liveEdit($this->model->text, $this->editLink, 'div') : $this->model->text;
}
+ public function getDate(){
+ return Yii::$app->formatter->asDate($this->time);
+ }
+
+ public function getPhotos()
+ {
+ if(!$this->_photos){
+ $this->_photos = [];
+
+ foreach(Photo::find()->where(['class' => News::className(), 'item_id' => $this->id])->sort()->all() as $model){
+ $this->_photos[] = new PhotoObject($model);
+ }
+ }
+ return $this->_photos;
+ }
+
public function getEditLink(){
return Url::to(['/admin/news/a/edit/', 'id' => $this->id]);
}
diff --git a/modules/news/api/PhotoObject.php b/modules/news/api/PhotoObject.php
new file mode 100644
index 0000000..eb4a696
--- /dev/null
+++ b/modules/news/api/PhotoObject.php
@@ -0,0 +1,27 @@
+thumb($width, $height));
+ $a = Html::a($img, $this->image, [
+ 'class' => 'easyii-box',
+ 'rel' => 'news-'.$this->model->item_id,
+ 'title' => $this->description
+ ]);
+ return LIVE_EDIT ? API::liveEdit($a, $this->editLink) : $a;
+ }
+
+ public function getEditLink(){
+ return Url::to(['/admin/news/a/photos', 'id' => $this->model->item_id]).'#photo-'.$this->id;
+ }
+}
\ No newline at end of file
diff --git a/modules/news/controllers/AController.php b/modules/news/controllers/AController.php
index dc08f88..3907a2c 100644
--- a/modules/news/controllers/AController.php
+++ b/modules/news/controllers/AController.php
@@ -3,6 +3,7 @@
use Yii;
use yii\data\ActiveDataProvider;
+use yii\easyii\behaviors\SortableDateController;
use yii\widgets\ActiveForm;
use yii\web\UploadedFile;
@@ -16,6 +17,10 @@ class AController extends Controller
public function behaviors()
{
return [
+ [
+ 'class' => SortableDateController::className(),
+ 'model' => News::className(),
+ ],
[
'class' => StatusController::className(),
'model' => News::className()
@@ -26,7 +31,7 @@ public function behaviors()
public function actionIndex()
{
$data = new ActiveDataProvider([
- 'query' => News::find()->orderBy(['time' => SORT_DESC]),
+ 'query' => News::find()->sortDate(),
]);
return $this->render('index', [
@@ -114,11 +119,22 @@ public function actionEdit($id)
}
}
+ public function actionPhotos($id)
+ {
+ if(!($model = News::findOne($id))){
+ return $this->redirect(['/admin/'.$this->module->id]);
+ }
+
+ return $this->render('photos', [
+ 'model' => $model,
+ ]);
+ }
+
public function actionDelete($id)
{
if(($model = News::findOne($id))){
$model->delete();
- } else{
+ } else {
$this->error = Yii::t('easyii', 'Not found');
}
return $this->formatResponse(Yii::t('easyii/news', 'News deleted'));
@@ -143,6 +159,16 @@ public function actionClearImage($id)
return $this->back();
}
+ public function actionUp($id)
+ {
+ return $this->move($id, 'up');
+ }
+
+ public function actionDown($id)
+ {
+ return $this->move($id, 'down');
+ }
+
public function actionOn($id)
{
return $this->changeStatus($id, News::STATUS_ON);
diff --git a/modules/news/models/News.php b/modules/news/models/News.php
index 701e31e..3933b75 100644
--- a/modules/news/models/News.php
+++ b/modules/news/models/News.php
@@ -23,8 +23,8 @@ public function rules()
[['title', 'short', 'text'], 'trim'],
['title', 'string', 'max' => 128],
['image', 'image'],
+ [['views', 'time'], 'integer'],
['time', 'default', 'value' => time()],
- ['views', 'number', 'integerOnly' => true],
['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]
];
@@ -45,7 +45,7 @@ public function attributeLabels()
public function behaviors()
{
return [
- 'seo' => SeoBehavior::className(),
+ 'seoBehavior' => SeoBehavior::className(),
'sluggable' => [
'class' => SluggableBehavior::className(),
'attribute' => 'title',
@@ -58,15 +58,11 @@ public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
$settings = Yii::$app->getModule('admin')->activeModules['news']->settings;
- if($this->short && $settings['enableShort']){
- $this->short = StringHelper::truncate($this->short, $settings['shortMaxLength']);
- }
- if(is_string($this->time)){
- if(!($this->time = strtotime($this->time))){
- $this->time = time();
- }
- }
+ $this->short = StringHelper::truncate($settings['enableShort'] ? $this->short : strip_tags($this->text), $settings['shortMaxLength']);
+ if(!$insert && $this->image != $this->oldAttributes['image'] && $this->oldAttributes['image']){
+ @unlink(Yii::getAlias('@webroot').$this->oldAttributes['image']);
+ }
return true;
} else {
return false;
diff --git a/modules/news/views/a/_form.php b/modules/news/views/a/_form.php
index 7e5f770..63fe978 100644
--- a/modules/news/views/a/_form.php
+++ b/modules/news/views/a/_form.php
@@ -1,5 +1,5 @@
time = date('Y-m-d', $model->time);
$module = $this->context->module->id;
?>
true,
- 'options' => ['enctype' => 'multipart/form-data']
+ 'options' => ['enctype' => 'multipart/form-data', 'class' => 'model-form']
]); ?>
= $form->field($model, 'title') ?>
context->module->settings['enableThumb']) : ?>
@@ -34,14 +33,7 @@
]
]) ?>
-= $form->field($model, 'time')->widget(
- DatePicker::className(), [
- 'language' => strtolower(substr(Yii::$app->language, 0, 2)),
- 'clientOptions' => [
- 'autoclose' => true,
- 'format' => 'yyyy-mm-dd'
- ]
- ]); ?>
+= $form->field($model, 'time')->widget(DateTimePicker::className()); ?>
= $form->field($model, 'slug') ?>
diff --git a/modules/news/views/a/_menu.php b/modules/news/views/a/_menu.php
index a6e7ff0..430399d 100644
--- a/modules/news/views/a/_menu.php
+++ b/modules/news/views/a/_menu.php
@@ -7,7 +7,7 @@
>
-
+
= Yii::t('easyii', 'List') ?>
diff --git a/modules/news/views/a/_submenu.php b/modules/news/views/a/_submenu.php
new file mode 100644
index 0000000..c080edc
--- /dev/null
+++ b/modules/news/views/a/_submenu.php
@@ -0,0 +1,12 @@
+context->action->id;
+$module = $this->context->module->id;
+?>
+
+
+
\ No newline at end of file
diff --git a/modules/news/views/a/edit.php b/modules/news/views/a/edit.php
index f3880fd..c2c0ab4 100644
--- a/modules/news/views/a/edit.php
+++ b/modules/news/views/a/edit.php
@@ -1,5 +1,8 @@
title = Yii::t('easyii/news', 'Edit news');
+$this->title = $model->title;
?>
= $this->render('_menu') ?>
+
+context->module->settings['enablePhotos']) echo $this->render('_submenu', ['model' => $model]) ?>
+
= $this->render('_form', ['model' => $model]) ?>
\ No newline at end of file
diff --git a/modules/news/views/a/index.php b/modules/news/views/a/index.php
index 7ae17d2..7165a29 100644
--- a/modules/news/views/a/index.php
+++ b/modules/news/views/a/index.php
@@ -20,12 +20,12 @@
= Yii::t('easyii', 'Title') ?>
= Yii::t('easyii', 'Views') ?>
= Yii::t('easyii', 'Status') ?>
-
+
models as $item) : ?>
-
+
= $item->primaryKey ?>
@@ -38,7 +38,13 @@
'data-link' => Url::to(['/admin/'.$module.'/a']),
]) ?>
-
+
+
+
diff --git a/modules/news/views/a/photos.php b/modules/news/views/a/photos.php
new file mode 100644
index 0000000..31f7ff3
--- /dev/null
+++ b/modules/news/views/a/photos.php
@@ -0,0 +1,10 @@
+title = $model->title;
+?>
+
+= $this->render('_menu') ?>
+= $this->render('_submenu', ['model' => $model]) ?>
+
+= Photos::widget(['model' => $model])?>
\ No newline at end of file
diff --git a/modules/page/api/Page.php b/modules/page/api/Page.php
index 5caab0e..1f21264 100644
--- a/modules/page/api/Page.php
+++ b/modules/page/api/Page.php
@@ -26,15 +26,9 @@ private function findPage($id_slug)
private function notFound($id_slug)
{
- $page = new PageModel();
-
- if(!Yii::$app->user->isGuest && preg_match(PageModel::$SLUG_PATTERN, $id_slug)){
- $a = Html::a(Yii::t('easyii/page/api', 'Create page'), ['/admin/page/a/create', 'slug' => $id_slug], ['target' => '_blank']);
- $page->title = $a;
- $page->text = $a;
-
- }
-
+ $page = new PageModel([
+ 'slug' => $id_slug
+ ]);
return new PageObject($page);
}
}
\ No newline at end of file
diff --git a/modules/page/api/PageObject.php b/modules/page/api/PageObject.php
index 422c24f..ea5a054 100644
--- a/modules/page/api/PageObject.php
+++ b/modules/page/api/PageObject.php
@@ -1,7 +1,9 @@
model->title, $this->editLink) : $this->model->title;
+ if($this->model->isNewRecord){
+ return $this->createLink;
+ } else {
+ 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;
+ if($this->model->isNewRecord){
+ return $this->createLink;
+ } else {
+ return LIVE_EDIT ? API::liveEdit($this->model->text, $this->editLink, 'div') : $this->model->text;
+ }
}
public function getEditLink(){
return Url::to(['/admin/page/a/edit/', 'id' => $this->id]);
}
+
+ public function getCreateLink(){
+ return Html::a(Yii::t('easyii/page/api', 'Create page'), ['/admin/page/a/create', 'slug' => $this->slug], ['target' => '_blank']);
+ }
}
\ No newline at end of file
diff --git a/modules/page/controllers/AController.php b/modules/page/controllers/AController.php
index 4259554..abf30ad 100644
--- a/modules/page/controllers/AController.php
+++ b/modules/page/controllers/AController.php
@@ -15,7 +15,7 @@ class AController extends Controller
public function actionIndex()
{
$data = new ActiveDataProvider([
- 'query' => Page::find()->desc(),
+ 'query' => Page::find()->desc()
]);
return $this->render('index', [
'data' => $data
@@ -86,7 +86,7 @@ public function actionDelete($id)
{
if(($model = Page::findOne($id))){
$model->delete();
- } else{
+ } else {
$this->error = Yii::t('easyii', 'Not found');
}
return $this->formatResponse(Yii::t('easyii/page', 'Page deleted'));
diff --git a/modules/page/models/Page.php b/modules/page/models/Page.php
index f436d67..d8e8396 100644
--- a/modules/page/models/Page.php
+++ b/modules/page/models/Page.php
@@ -35,7 +35,7 @@ public function attributeLabels()
public function behaviors()
{
return [
- 'seo' => SeoBehavior::className(),
+ 'seoBehavior' => SeoBehavior::className(),
];
}
}
\ No newline at end of file
diff --git a/modules/page/views/a/_form.php b/modules/page/views/a/_form.php
index ca5e603..36b7b9b 100644
--- a/modules/page/views/a/_form.php
+++ b/modules/page/views/a/_form.php
@@ -7,6 +7,7 @@
?>
true,
+ 'options' => ['class' => 'model-form']
]); ?>
= $form->field($model, 'title') ?>
= $form->field($model, 'text')->widget(Redactor::className(),[
diff --git a/modules/shopcart/ShopcartModule.php b/modules/shopcart/ShopcartModule.php
index 38e9a16..6cc35af 100644
--- a/modules/shopcart/ShopcartModule.php
+++ b/modules/shopcart/ShopcartModule.php
@@ -6,7 +6,12 @@ class ShopcartModule extends \yii\easyii\components\Module
public $settings = [
'mailAdminOnNewOrder' => true,
'subjectOnNewOrder' => 'New order',
- 'templateOnNewOrder' => '@easyii/modules/shopcart/mail/new_order',
+ 'templateOnNewOrder' => '@easyii/modules/shopcart/mail/en/new_order',
+ 'subjectNotifyUser' => 'Your order status changed',
+ 'templateNotifyUser' => '@easyii/modules/shopcart/mail/en/notify_user',
+ 'frontendShopcartRoute' => '/shopcart/order',
+ 'enablePhone' => true,
+ 'enableEmail' => true
];
public static $installConfig = [
diff --git a/modules/shopcart/models/Good.php b/modules/shopcart/models/Good.php
index 0860109..3843400 100644
--- a/modules/shopcart/models/Good.php
+++ b/modules/shopcart/models/Good.php
@@ -1,7 +1,7 @@
'confirm'],
+ ['email', 'required', 'when' => function($model){ return $model->scenario == 'confirm' && Yii::$app->getModule('admin')->activeModules['shopcart']->settings['enableEmail']; }],
+ ['phone', 'required', 'when' => function($model){ return $model->scenario == 'confirm' && Yii::$app->getModule('admin')->activeModules['shopcart']->settings['enablePhone']; }],
[['name', 'address', 'phone', 'comment'], 'trim'],
['email', 'email'],
['name', 'string', 'max' => 32],
@@ -44,9 +48,22 @@ public function attributeLabels()
return [
'name' => Yii::t('easyii', 'Name'),
'email' => Yii::t('easyii', 'E-mail'),
- 'address' => Yii::t('easyii/shopcart', 'Delivery address'),
+ 'address' => Yii::t('easyii/shopcart', 'Address'),
'phone' => Yii::t('easyii/shopcart', 'Phone'),
'comment' => Yii::t('easyii/shopcart', 'Comment'),
+ 'remark' => Yii::t('easyii/shopcart', 'Admin remark'),
+ ];
+ }
+
+ public function behaviors()
+ {
+ return [
+ 'cn' => [
+ 'class' => CalculateNotice::className(),
+ 'callback' => function(){
+ return self::find()->where(['new' => 1])->count();
+ }
+ ]
];
}
@@ -59,9 +76,9 @@ public static function statusName($status)
public static function states()
{
return [
- self::STATUS_NEW => Yii::t('easyii/shopcart', 'New'),
+ self::STATUS_BLANK => Yii::t('easyii/shopcart', 'Blank'),
self::STATUS_PENDING => Yii::t('easyii/shopcart', 'Pending'),
- self::STATUS_CONFIRMED => Yii::t('easyii/shopcart', 'Confirmed'),
+ self::STATUS_PROCESSED => Yii::t('easyii/shopcart', 'Processed'),
self::STATUS_DECLINED => Yii::t('easyii/shopcart', 'Declined'),
self::STATUS_SENT => Yii::t('easyii/shopcart', 'Sent'),
self::STATUS_RETURNED => Yii::t('easyii/shopcart', 'Returned'),
@@ -70,6 +87,12 @@ public static function states()
];
}
+ public function getStatusName()
+ {
+ $states = self::states();
+ return !empty($states[$this->status]) ? $states[$this->status] : $this->status;
+ }
+
public function getGoods()
{
return $this->hasMany(Good::className(), ['order_id' => 'order_id']);
@@ -89,12 +112,13 @@ public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if($insert) {
+ $this->ip = Yii::$app->request->userIP;
$this->access_token = Yii::$app->security->generateRandomString(32);
- $this->status = self::STATUS_NEW;
$this->time = time();
} else {
- if($this->oldAttributes['status'] == self::STATUS_NEW && $this->status == self::STATUS_PENDING){
+ if($this->oldAttributes['status'] == self::STATUS_BLANK && $this->status == self::STATUS_PENDING){
$this->new = 1;
+ $this->mailAdmin();
}
}
return true;
@@ -112,15 +136,36 @@ public function afterDelete()
}
}
- public function behaviors()
+ public function mailAdmin()
{
- return [
- 'cn' => [
- 'class' => CalculateNotice::className(),
- 'callback' => function(){
- return self::find()->where(['new' => 1])->count();
- }
+ $settings = Yii::$app->getModule('admin')->activeModules['shopcart']->settings;
+
+ if(!$settings['mailAdminOnNewPost']){
+ return false;
+ }
+ return Mail::send(
+ Setting::get('admin_email'),
+ $settings['subjectOnNewOrder'],
+ $settings['templateOnNewOrder'],
+ [
+ 'order' => $this,
+ 'link' => Url::to(['/admin/shopcart/a/view', 'id' => $this->primaryKey], true)
]
- ];
+ );
+ }
+
+ public function notifyUser()
+ {
+ $settings = Yii::$app->getModule('admin')->activeModules['shopcart']->settings;
+
+ return Mail::send(
+ $this->email,
+ $settings['subjectNotifyUser'],
+ $settings['templateNotifyUser'],
+ [
+ 'order' => $this,
+ 'link' => Url::to([$settings['frontendShopcartRoute'], 'token' => $this->access_token], true)
+ ]
+ );
}
}
\ No newline at end of file
diff --git a/modules/shopcart/views/a/_menu.php b/modules/shopcart/views/a/_menu.php
index 0a69e20..c0c6830 100644
--- a/modules/shopcart/views/a/_menu.php
+++ b/modules/shopcart/views/a/_menu.php
@@ -6,18 +6,19 @@
$backTo = null;
$indexUrl = Url::to(['/admin/'.$module]);
-$confirmedUrl = Url::to(['/admin/'.$module.'/a/confirmed']);
+$processedUrl = Url::to(['/admin/'.$module.'/a/processed']);
$sentUrl = Url::to(['/admin/'.$module.'/a/sent']);
$completedUrl = Url::to(['/admin/'.$module.'/a/completed']);
$failsUrl = Url::to(['/admin/'.$module.'/a/fails']);
+$blankUrl = Url::to(['/admin/'.$module.'/a/blank']);
if($action === 'view')
{
$returnUrl = $this->context->getReturnUrl($indexUrl);
- if(strpos($returnUrl, 'confirmed') !== false){
- $backTo = 'confirmed';
- $confirmedUrl = $returnUrl;
+ if(strpos($returnUrl, 'processed') !== false){
+ $backTo = 'processed';
+ $processedUrl = $returnUrl;
} elseif(strpos($returnUrl, 'sent') !== false) {
$backTo = 'sent';
$sentUrl = $returnUrl;
@@ -27,7 +28,10 @@
} elseif(strpos($returnUrl, 'fails') !== false) {
$backTo = 'fails';
$failsUrl = $returnUrl;
- } else{
+ } elseif(strpos($returnUrl, 'blank') !== false) {
+ $backTo = 'blank';
+ $blankUrl = $returnUrl;
+ } else {
$backTo = 'index';
$indexUrl = $returnUrl;
}
@@ -45,14 +49,14 @@
- >
-
-
+ >
+
+
- = Yii::t('easyii/shopcart', 'Confirmed') ?>
- context->confirmed > 0) : ?>
- = $this->context->confirmed ?>
+ = Yii::t('easyii/shopcart', 'Processed') ?>
+ context->processed > 0) : ?>
+ = $this->context->processed ?>
@@ -83,5 +87,13 @@
= Yii::t('easyii/shopcart', 'Fails') ?>
+ >
+
+
+
+
+ = Yii::t('easyii/shopcart', 'Blank') ?>
+
+
\ No newline at end of file
diff --git a/modules/shopcart/views/a/view.php b/modules/shopcart/views/a/view.php
index fa05e2e..72242ba 100644
--- a/modules/shopcart/views/a/view.php
+++ b/modules/shopcart/views/a/view.php
@@ -6,19 +6,34 @@
$this->title = Yii::t('easyii/shopcart', 'Order') . ' #' . $order->primaryKey;
$this->registerCss('.shopcart-view dt{margin-bottom: 10px;}');
-$this->registerJs('
- $("#order-status").change(function(){
- location.href = "' . Url::to(['/admin/shopcart/a/status', 'id' => $order->primaryKey]) . '?status="+$(this).val();
- });
-');
+$states = Order::states();
+unset($states[Order::STATUS_BLANK]);
$module = $this->context->module->id;
+
+$this->registerJs('
+var oldStatus = '.$order->status.';
+$("#order-status").change(function(){
+ if($(this).val() != oldStatus){
+ $("#notify-user").slideDown();
+ } else {
+ $("#notify-user").slideUp();
+ }
+});
+');
?>
= $this->render('_menu') ?>
+= Html::beginForm() ?>
- = Yii::t('easyii', 'Status') ?>
- = Html::dropDownList('status', $order->status, Order::states(), ['id' => 'order-status'])?>
+ status != Order::STATUS_BLANK) : ?>
+ = Yii::t('easyii', 'Status') ?>
+
+
+ = Html::dropDownList('status', $order->status, $states, ['id' => 'order-status']) ?>
+
+
+
= Yii::t('easyii', 'Name') ?>
= $order->name ?>
@@ -26,18 +41,41 @@
= Yii::t('easyii/shopcart', 'Address') ?>
= $order->address ?>
- = Yii::t('easyii/shopcart', 'Phone') ?>
- = $order->phone ?>
+ context->module->settings['enablePhone']) : ?>
+ = Yii::t('easyii/shopcart', 'Phone') ?>
+ = $order->phone ?>
+
- = Yii::t('easyii', 'E-mail') ?>
- = $order->email ?>
+ context->module->settings['enableEmail']) : ?>
+ = Yii::t('easyii', 'E-mail') ?>
+ = $order->email ?>
+
= Yii::t('easyii', 'Date') ?>
= Yii::$app->formatter->asDatetime($order->time, 'medium') ?>
+ IP
+ = $model->ip ?> info
+
= Yii::t('easyii/shopcart', 'Comment') ?>
= nl2br($order->comment) ?>
+
+ = Yii::t('easyii/shopcart', 'Admin remark') ?>
+
+
+ = Html::textarea('remark', $order->remark, ['class' => 'form-control']) ?>
+
+ email) : ?>
+
+
+ = Html::checkbox('notify', true, ['uncheck' => 0]) ?> = Yii::t('easyii/shopcart', 'Notify user on E-mail') ?>
+
+
+
+ = Html::submitButton(Yii::t('easyii', 'Save'), ['class' => 'btn btn-primary']) ?>
+
+= Html::endForm() ?>
= Yii::t('easyii/shopcart', 'Items') ?>
@@ -52,7 +90,7 @@
- = Html::a($good->item->title, ['/admin/shop/items/edit', 'id' => $good->item->primaryKey]) ?>
+ = Html::a($good->item->title, ['/admin/catalog/items/edit', 'id' => $good->item->primaryKey]) ?>
= $good->options ?>
= $good->count ?>
= $good->discount ?>
diff --git a/modules/subscribe/api/Subscribe.php b/modules/subscribe/api/Subscribe.php
index e441774..39c7eab 100644
--- a/modules/subscribe/api/Subscribe.php
+++ b/modules/subscribe/api/Subscribe.php
@@ -10,38 +10,39 @@
class Subscribe extends \yii\easyii\components\API
{
- public $options = [
- 'buttonClass' => 'btn btn-primary',
- 'buttonText' => 'Subscribe'
+ const SENT_VAR = 'subscribe_sent';
+
+ private $_defaultFormOptions = [
+ 'showAlert' => true
];
public function api_form($options = [])
{
- if(is_array($options) && count($options)) $this->options = array_merge($this->options, $options);
-
$model = new Subscriber;
+ $options = array_merge($this->_defaultFormOptions, $options);
ob_start();
- $form = ActiveForm::begin([
- 'enableAjaxValidation' => true,
- 'action' => Url::to(['/admin/subscribe/send']),
- 'layout' => 'inline'
- ]);
-
- switch(Yii::$app->session->getFlash(Subscriber::FLASH_KEY)){
- case 'success' :
- Yii::$app->getView()->registerJs('alert("'.Yii::t('easyii/subscribe/api', 'You have successfully subscribed').'");');
- break;
- case 'error' :
- Yii::$app->getView()->registerJs('alert("'.Yii::t('easyii/subscribe/api', 'An error has occurred').'");');
- break;
+ $sent = Yii::$app->request->get(self::SENT_VAR);
+ if($options['showAlert'] && $sent !== null) {
+ if ($sent == "1") {
+ echo '' . Yii::t('easyii/subscribe/api', 'You have successfully subscribed') . ' ';
+ } else {
+ echo '' . Yii::t('easyii/subscribe/api', 'An error has occurred') . ' ';
+ }
+ } else {
+ $form = ActiveForm::begin([
+ 'enableAjaxValidation' => true,
+ 'action' => Url::to(['/admin/subscribe/send']),
+ 'layout' => 'inline'
+ ]);
+ echo Html::hiddenInput('errorUrl', Url::current([self::SENT_VAR => 0]));
+ echo Html::hiddenInput('successUrl', Url::current([self::SENT_VAR => 1]));
+ echo $form->field($model, 'email')->input('email', ['placeholder' => 'E-mail']);
+ echo Html::submitButton(Yii::t('easyii/subscribe/api', 'Subscribe'), ['class' => 'btn btn-primary', 'id' => 'subscriber-send']);
+
+ ActiveForm::end();
}
- echo $form->field($model, 'email')->input('email', ['placeholder' => 'E-mail']);
- echo Html::submitButton(Yii::t('easyii/subscribe/api', $this->options['buttonText']), ['class' => $this->options['buttonClass'], 'id' => 'subscriber-send']);
-
- ActiveForm::end();
-
return ob_get_clean();
}
@@ -50,7 +51,7 @@ public function api_create($email)
$model = new Subscriber(['email' => $email]);
if($model->save()){
return ['result' => 'success', 'error' => false];
- } else{
+ } else {
return ['result' => 'error', 'error' => $model->getErrors()];
}
}
diff --git a/modules/subscribe/controllers/AController.php b/modules/subscribe/controllers/AController.php
index f63a0ad..aa14dd1 100644
--- a/modules/subscribe/controllers/AController.php
+++ b/modules/subscribe/controllers/AController.php
@@ -81,7 +81,7 @@ public function actionDelete($id)
{
if(($model = Subscriber::findOne($id))){
$model->delete();
- } else{
+ } else {
$this->error = Yii::t('easyii', 'Not found');
}
return $this->formatResponse(Yii::t('easyii/subscribe', 'Subscriber deleted'));
diff --git a/modules/subscribe/controllers/SendController.php b/modules/subscribe/controllers/SendController.php
index 33070de..58c5b87 100644
--- a/modules/subscribe/controllers/SendController.php
+++ b/modules/subscribe/controllers/SendController.php
@@ -2,6 +2,7 @@
namespace yii\easyii\modules\subscribe\controllers;
use Yii;
+use yii\easyii\modules\subscribe\api\Subscribe;
use yii\widgets\ActiveForm;
use yii\easyii\modules\subscribe\models\Subscriber;
@@ -11,20 +12,16 @@ class SendController extends \yii\web\Controller
public function actionIndex()
{
$model = new Subscriber;
+ $request = Yii::$app->request;
- if ($model->load(Yii::$app->request->post())) {
- if(Yii::$app->request->isAjax){
+ if ($model->load($request->post())) {
+ if($request->isAjax){
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
else{
- if($model->save()){
- Yii::$app->session->setFlash(Subscriber::FLASH_KEY, 'success');
- }
- else{
- Yii::$app->session->setFlash(Subscriber::FLASH_KEY, 'error');
- }
- return $this->redirect(Yii::$app->request->referrer);
+ $returnUrl = $model->save() ? $request->post('successUrl') : $request->post('errorUrl');
+ return $this->redirect($returnUrl);
}
}
else {
diff --git a/modules/subscribe/views/a/_form.php b/modules/subscribe/views/a/_form.php
index 4b60ea9..6ac84cb 100644
--- a/modules/subscribe/views/a/_form.php
+++ b/modules/subscribe/views/a/_form.php
@@ -3,7 +3,9 @@
use yii\widgets\ActiveForm;
use yii\easyii\widgets\Redactor;
?>
- true]); ?>
+ true
+]); ?>
= $form->field($model, 'subject') ?>
= $form->field($model, 'body')->widget(Redactor::className(),[
'options' => [
diff --git a/modules/text/controllers/AController.php b/modules/text/controllers/AController.php
index ba8163d..6572aec 100644
--- a/modules/text/controllers/AController.php
+++ b/modules/text/controllers/AController.php
@@ -87,7 +87,7 @@ public function actionDelete($id)
{
if(($model = Text::findOne($id))){
$model->delete();
- } else{
+ } else {
$this->error = Yii::t('easyii', 'Not found');
}
return $this->formatResponse(Yii::t('easyii/text', 'Text deleted'));
diff --git a/modules/text/views/a/_form.php b/modules/text/views/a/_form.php
index 0fcdc24..5ba5ecf 100644
--- a/modules/text/views/a/_form.php
+++ b/modules/text/views/a/_form.php
@@ -2,7 +2,10 @@
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
- true]); ?>
+ true,
+ 'options' => ['class' => 'model-form']
+]); ?>
= $form->field($model, 'text')->textarea() ?>
= (IS_ROOT) ? $form->field($model, 'slug') : '' ?>
= Html::submitButton(Yii::t('easyii', 'Save'), ['class' => 'btn btn-primary']) ?>
diff --git a/views/category/_menu.php b/views/category/_menu.php
index c836e45..307935e 100644
--- a/views/category/_menu.php
+++ b/views/category/_menu.php
@@ -6,7 +6,7 @@
>
-
+
= Yii::t('easyii', 'Categories') ?>
diff --git a/views/category/index.php b/views/category/index.php
index e4f15b3..662bfd4 100644
--- a/views/category/index.php
+++ b/views/category/index.php
@@ -6,67 +6,48 @@
$this->title = Yii::$app->getModule('admin')->activeModules[$this->context->module->id]->title;
-$module = $this->context->module->id;
-
-
-
-function renderNode($node, $baseUrl)
-{
- $html = '';
- $html .= ''.$node['category_id'].' ';
- $html .= '';
- if(sizeof($node['children'])){
- $html .= ' ';
- }
- if(!count($node['children']) || !empty(Yii::$app->controller->module->settings['itemsInFolder'])) {
- $html .= '' . $node['title'] . ' ';
- } else {
- $html .= '' . $node['title'] . ' ';
- }
- $html .= ' ';
-
- if($node['status'] == CategoryModel::STATUS_ON){
- $switchButton = ' '.Yii::t('easyii', 'Turn Off').' ';
- } else {
- $switchButton = ' '.Yii::t('easyii', 'Turn On').' ';
- }
-
- $html .= '
-
-
-
-
-
-
- ';
- $html .= ' ';
-
- if(sizeof($node['children'])){
- foreach($node['children'] as $child){
- $html .= renderNode($child, $baseUrl);
- }
- }
-
- return $html;
-}
-
+$baseUrl = '/admin/'.$this->context->moduleName;
?>
= $this->render('_menu') ?>
- 0) : ?>
+ 0) : ?>
diff --git a/widgets/Redactor.php b/widgets/Redactor.php
index a8a3e9b..dbc8dde 100644
--- a/widgets/Redactor.php
+++ b/widgets/Redactor.php
@@ -2,12 +2,12 @@
namespace yii\easyii\widgets;
use Yii;
+use yii\easyii\helpers\Data;
use yii\widgets\InputWidget;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\JsExpression;
use yii\web\AssetBundle;
-use yii\helpers\ArrayHelper;
use yii\easyii\assets\RedactorAsset;
@@ -44,7 +44,7 @@ public function run()
public function registerRegional()
{
- list($lang,) = explode('-', \Yii::$app->language);
+ $lang = Data::getLocale();
if ($lang != 'en') {
$langAsset = 'lang/' . $lang . '.js';
if (file_exists(Yii::getAlias($this->assetBundle->sourcePath . '/' . $langAsset))) {