Example #1
1
 private function findCategory($id_slug)
 {
     $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;
 }
 public function actionIndex($id)
 {
     $staticUrl = $this->category->getStaticUrl()->notEmpty();
     $dataProvider = new ActiveDataProvider(['query' => $staticUrl]);
     $search = new StaticUrlSearchFormModel();
     return $this->render('index', ['category' => $this->category, 'dataProvider' => $dataProvider, 'search' => $search]);
 }
 public function actionCategory($id)
 {
     /** @var Item $modelClass */
     $modelClass = $this->category->getItems()->modelClass;
     /** @var Item $model */
     $model = new $modelClass();
     $attributesBehavior = $model->getAttributesBehavior();
     $query = AttributeRuleRecord::find()->byCategory($this->category->id);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $this->render('category', ['dataProvider' => $dataProvider, 'categoryId' => $id]);
 }
Example #4
0
 public function searchByCategory(Category $category, array $params = [])
 {
     $query = $category->getItems();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => 10000, 'pageSizeLimit' => false]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Example #5
0
 public function actionCreate($id)
 {
     if (!($category = Category::findOne($id))) {
         return $this->redirect(['/admin/catalog']);
     }
     $model = new Item();
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             $model->category_id = $category->primaryKey;
             $model->data = Yii::$app->request->post('Data');
             if (isset($_FILES) && $this->module->settings['itemThumb']) {
                 $model->thumb = UploadedFile::getInstance($model, 'thumb');
                 if ($model->thumb && $model->validate(['thumb'])) {
                     $model->thumb = Image::upload($model->thumb, 'catalog', $this->module->settings['itemThumbWidth'], $this->module->settings['itemThumbHeight'], $this->module->settings['itemThumbCrop']);
                 } else {
                     $model->thumb = '';
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii/catalog', 'Item created'));
                 return $this->redirect(['/admin/catalog/items/edit/', 'id' => $model->primaryKey]);
             } else {
                 $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors()));
                 return $this->refresh();
             }
         }
     } else {
         return $this->render('create', ['model' => $model, 'category' => $category, 'dataForm' => $this->generateForm($category->fields)]);
     }
 }
 public function actionGenerate($id)
 {
     $category = Category::findOne($id);
     /** @var StaticUrl $class */
     $class = AdminModule::getInstance()->getCatalog()->staticUrlClass;
     $class::generate($category);
 }
 public function up()
 {
     //ADMINS
     $this->createTable(models\Admin::tableName(), ['admin_id' => 'pk', 'username' => Schema::TYPE_STRING . '(32) NOT NULL', 'password' => Schema::TYPE_STRING . '(64) NOT NULL', 'auth_key' => Schema::TYPE_STRING . '(128) NOT NULL', 'access_token' => Schema::TYPE_STRING . '(128) DEFAULT NULL'], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('access_token', models\Admin::tableName(), 'access_token', true);
     //LOGINFORM
     $this->createTable(models\LoginForm::tableName(), ['log_id' => 'pk', 'username' => Schema::TYPE_STRING . '(128) NOT NULL', 'password' => Schema::TYPE_STRING . '(128) NOT NULL', 'ip' => Schema::TYPE_STRING . '(16) NOT NULL', 'user_agent' => Schema::TYPE_STRING . '(1024) NOT NULL', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'success' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     //MODULES
     $this->createTable(models\Module::tableName(), ['module_id' => 'pk', 'name' => Schema::TYPE_STRING . '(64) NOT NULL', 'class' => Schema::TYPE_STRING . '(128) NOT NULL', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'icon' => Schema::TYPE_STRING . '(32) NOT NULL', 'settings' => Schema::TYPE_TEXT . ' NOT NULL', 'notice' => 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('name', models\Module::tableName(), 'name', true);
     //PHOTOS
     $this->createTable(models\Photo::tableName(), ['photo_id' => 'pk', 'model' => Schema::TYPE_STRING . '(128) NOT NULL', 'item_id' => Schema::TYPE_INTEGER . " NOT NULL", 'thumb' => Schema::TYPE_STRING . '(128) 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']);
     //SEOTEXT
     $this->createTable(models\SeoText::tableName(), ['seotext_id' => 'pk', 'model' => 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);
     //SETTINGS
     $this->createTable(models\Setting::tableName(), ['setting_id' => 'pk', 'name' => Schema::TYPE_STRING . '(64) NOT NULL', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'value' => Schema::TYPE_STRING . '(1024) NOT NULL', 'visibility' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('name', models\Setting::tableName(), 'name', true);
     //CAROUSEL MODULE
     $this->createTable(Carousel::tableName(), ['carousel_id' => 'pk', 'image' => Schema::TYPE_STRING . '(128) NOT NULL', 'title' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'text' => Schema::TYPE_TEXT . ' DEFAULT NULL', 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     //CATALOG MODULE
     $this->createTable(catalog\models\Category::tableName(), ['category_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'fields' => Schema::TYPE_TEXT . ' NOT NULL', 'thumb' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', catalog\models\Category::tableName(), 'slug', true);
     $this->createTable(catalog\models\Item::tableName(), ['item_id' => 'pk', 'category_id' => Schema::TYPE_INTEGER . ' NOT NULL', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'description' => Schema::TYPE_TEXT . ' DEFAULT NULL', 'data' => Schema::TYPE_TEXT . ' NOT NULL', 'thumb' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'created_at' => Schema::TYPE_DATETIME . " DEFAULT NULL", 'updated_at' => Schema::TYPE_DATETIME . " DEFAULT NULL", 'created_by' => Schema::TYPE_INTEGER . " DEFAULT NULL", 'updated_by' => Schema::TYPE_INTEGER . " DEFAULT NULL"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', catalog\models\Item::tableName(), 'slug', true);
     //FEEDBACK MODULE
     $this->createTable(Feedback::tableName(), ['feedback_id' => 'pk', 'name' => Schema::TYPE_STRING . '(64) NOT NULL', 'email' => Schema::TYPE_STRING . '(128) NOT NULL', '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', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'ip' => Schema::TYPE_STRING . '(16) NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     //FILE MODULE
     $this->createTable(File::tableName(), ['file_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'file' => Schema::TYPE_STRING . '(255) NOT NULL', 'size' => Schema::TYPE_INTEGER . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'downloads' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL'], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', File::tableName(), 'slug', true);
     //GALLERY MODULE
     $this->createTable(Album::tableName(), ['album_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'thumb' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', Album::tableName(), 'slug', true);
     //GUESTBOOK MODULE
     $this->createTable(Guestbook::tableName(), ['guestbook_id' => 'pk', 'name' => Schema::TYPE_STRING . '(128) NOT NULL', 'title' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'text' => Schema::TYPE_TEXT . ' NOT NULL', 'answer' => Schema::TYPE_TEXT . ' DEFAULT NULL', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'ip' => Schema::TYPE_STRING . '(16) NOT NULL', 'new' => Schema::TYPE_BOOLEAN . " DEFAULT '0'", 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     //NEWS MODULE
     $this->createTable(News::tableName(), ['news_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'thumb' => Schema::TYPE_STRING . '(128) DEFAULT NULL', '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'", 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'", 'created_by' => Schema::TYPE_INTEGER . " DEFAULT NULL", 'updated_by' => Schema::TYPE_INTEGER . " DEFAULT NULL"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', News::tableName(), 'slug', true);
     //ARTICLE MODULE
     $this->createTable(article\models\Category::tableName(), ['category_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'thumb' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', article\models\Category::tableName(), 'slug', true);
     $this->createTable(article\models\Item::tableName(), ['item_id' => 'pk', 'category_id' => Schema::TYPE_INTEGER . ' NOT NULL', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'thumb' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'short' => Schema::TYPE_STRING . '(1024) DEFAULT NULL', 'text' => Schema::TYPE_TEXT . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'views' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'", 'created_by' => Schema::TYPE_INTEGER . " DEFAULT NULL", 'updated_by' => Schema::TYPE_INTEGER . " DEFAULT NULL"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', article\models\Item::tableName(), 'slug', true);
     //PAGE MODULE
     $this->createTable(Page::tableName(), ['page_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'text' => Schema::TYPE_TEXT . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL'], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', Page::tableName(), 'slug', true);
     //FAQ MODULE
     $this->createTable(Faq::tableName(), ['faq_id' => 'pk', 'question' => Schema::TYPE_TEXT . ' NOT NULL', 'answer' => Schema::TYPE_TEXT . ' NOT NULL', 'order_num' => Schema::TYPE_INTEGER . ' NOT NULL', 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     //SUBSCRIBE MODULE
     $this->createTable(Subscriber::tableName(), ['subscriber_id' => 'pk', 'email' => Schema::TYPE_STRING . '(128) NOT NULL', 'ip' => Schema::TYPE_STRING . '(16) NOT NULL', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('email', Subscriber::tableName(), 'email', true);
     $this->createTable(History::tableName(), ['history_id' => 'pk', 'subject' => Schema::TYPE_STRING . '(128) NOT NULL', 'body' => Schema::TYPE_TEXT . ' NOT NULL', 'sent' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'"], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     //TEXT MODULE
     $this->createTable(Text::tableName(), ['text_id' => 'pk', 'text' => Schema::TYPE_TEXT . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL'], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
     $this->createIndex('slug', Text::tableName(), 'slug', true);
     //INSERT VERSION
     $this->delete(models\Setting::tableName(), ['name' => 'easyii_version']);
     $this->insert(models\Setting::tableName(), ['name' => 'easyii_version', 'value' => self::VERSION, 'title' => 'EasyiiCMS version', 'visibility' => models\Setting::VISIBLE_NONE]);
 }
Example #8
0
 private function findCategories()
 {
     $result = [];
     $query = Category::find()->status(Category::STATUS_ON)->sort();
     if ($this->_catsOptions['where']) {
         $query->andWhere($this->_catsOptions['where']);
     }
     $this->_adp = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $this->_catsOptions['pageSize']]]);
     foreach ($this->_adp->models as $category) {
         $result[] = $this->parseCategory($category);
     }
     return $result;
 }
Example #9
0
 public function dbInstall()
 {
     $db = Yii::$app->db;
     $tableOptions = null;
     if ($db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=MyISAM';
     }
     $db->createCommand()->createTable(Category::tableName(), ['category_id' => 'pk', 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'image' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'fields' => Schema::TYPE_TEXT . ' NOT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'tree' => Schema::TYPE_INTEGER, 'lft' => Schema::TYPE_INTEGER, 'rgt' => Schema::TYPE_INTEGER, 'depth' => Schema::TYPE_INTEGER, 'order_num' => Schema::TYPE_INTEGER, 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '1'"], $tableOptions)->execute();
     $db->createCommand()->createIndex('slug', Category::tableName(), 'slug', true)->execute();
     $db->createCommand()->createTable(Item::tableName(), ['item_id' => 'pk', 'category_id' => Schema::TYPE_INTEGER, 'title' => Schema::TYPE_STRING . '(128) NOT NULL', 'description' => Schema::TYPE_TEXT . ' DEFAULT NULL', 'available' => Schema::TYPE_INTEGER . " DEFAULT '1'", 'price' => Schema::TYPE_FLOAT . " DEFAULT '0'", 'discount' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'data' => Schema::TYPE_TEXT . ' NOT NULL', 'image' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'slug' => Schema::TYPE_STRING . '(128) DEFAULT NULL', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'status' => Schema::TYPE_BOOLEAN . " DEFAULT '1'"], $tableOptions)->execute();
     $db->createCommand()->createIndex('slug', Item::tableName(), 'slug', true)->execute();
     $db->createCommand()->createTable(ItemData::tableName(), ['data_id' => 'pk', 'item_id' => Schema::TYPE_INTEGER, 'name' => Schema::TYPE_STRING . '(128) NOT NULL', 'value' => Schema::TYPE_STRING . '(1024) DEFAULT NULL'], $tableOptions)->execute();
     $db->createCommand()->createIndex('value', ItemData::tableName(), 'value(300)')->execute();
     $db->createCommand()->createIndex('item_id_name', ItemData::tableName(), ['item_id', 'name'])->execute();
 }
 public function init()
 {
     parent::init();
     require_once Yii::$app->basePath . '/../vendor/phpoffice/phpexcel/Classes/PHPExcel.php';
     $this->_category = Category::findOne($this->categoryId);
     if ($this->_category === null) {
         throw new \Exception(Yii::t('app', 'Категория {categoryId} не найдена.', ['categoryId' => $this->categoryId]));
     }
     if (!$this->exportConfig) {
         throw new \Exception('Не настроено.');
     }
     if ($this->db === null) {
         $this->db = Yii::$app->getDb();
     }
 }
Example #11
0
 public function actionFields($id)
 {
     if (!($model = Category::findOne($id))) {
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     if (Yii::$app->request->post('save')) {
         $fields = Yii::$app->request->post('Field') ?: [];
         $result = [];
         foreach ($fields as $field) {
             $temp = json_decode($field);
             if ($temp === null && json_last_error() !== JSON_ERROR_NONE || empty($temp->name) || empty($temp->title) || empty($temp->type) || !($temp->name = trim($temp->name)) || !($temp->title = trim($temp->title)) || !array_key_exists($temp->type, Category::$fieldTypes)) {
                 continue;
             }
             $options = '';
             if ($temp->type == 'select' || $temp->type == 'checkbox') {
                 if (empty($temp->options) || !($temp->options = trim($temp->options))) {
                     continue;
                 }
                 $options = [];
                 foreach (explode(',', $temp->options) as $option) {
                     $options[] = trim($option);
                 }
             }
             $result[] = ['name' => \yii\helpers\Inflector::slug($temp->name), 'title' => $temp->title, 'type' => $temp->type, 'options' => $options];
         }
         $model->fields = $result;
         if ($model->save()) {
             $ids = [];
             foreach ($model->children()->all() as $child) {
                 $ids[] = $child->primaryKey;
             }
             if (count($ids)) {
                 Category::updateAll(['fields' => json_encode($model->fields)], ['in', 'category_id', $ids]);
             }
             $this->flash('success', Yii::t('easyii/catalog', 'Category updated'));
         } else {
             $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
         }
         return $this->refresh();
     } else {
         return $this->render('fields', ['model' => $model]);
     }
 }
Example #12
0
 public function actionGroups($id)
 {
     if (!($model = Category::findOne($id))) {
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     if (Yii::$app->request->post('save')) {
         $images = Yii::$app->request->post('image');
         $names = Yii::$app->request->post('name');
         $result = [];
         foreach ($names as $key => $name) {
             $r = new \stdClass();
             $r->name = $name;
             $r->file = $images[$key];
             $result[] = $r;
         }
         $model->groups = $result;
         if ($model->save()) {
             $ids = [];
             foreach ($model->children()->all() as $child) {
                 $ids[] = $child->primaryKey;
             }
             if (count($ids)) {
                 Category::updateAll(['groups' => json_encode($model->groups)], ['in', 'category_id', $ids]);
             }
             $this->flash('success', Yii::t('easyii/catalog', 'Category updated'));
         } else {
             $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
         }
         return $this->refresh();
     } else {
         return $this->render('groups', ['model' => $model]);
     }
 }
 public function down()
 {
     $this->dropTable(models\Admin::tableName());
     $this->dropTable(models\LoginForm::tableName());
     $this->dropTable(models\Module::tableName());
     $this->dropTable(models\Photo::tableName());
     $this->dropTable(models\Setting::tableName());
     $this->dropTable(Carousel::tableName());
     $this->dropTable(catalog\models\Category::tableName());
     $this->dropTable(catalog\models\Item::tableName());
     $this->dropTable(article\models\Category::tableName());
     $this->dropTable(article\models\Item::tableName());
     $this->dropTable(Feedback::tableName());
     $this->dropTable(File::tableName());
     $this->dropTable(gallery\models\Category::tableName());
     $this->dropTable(Guestbook::tableName());
     $this->dropTable(News::tableName());
     $this->dropTable(Page::tableName());
     $this->dropTable(Subscriber::tableName());
     $this->dropTable(History::tableName());
     $this->dropTable(Text::tableName());
 }
Example #14
0
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['category_id' => 'category_id']);
 }
Example #15
0
 public function getItems()
 {
     return $this->model->getItems();
 }
Example #16
0
<?php

use yii\widgets\ActiveForm;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
/**
 * @var \yii\easyii\modules\catalog\models\Category2CategoryField $model
 */
?>

<?php 
$form = ActiveForm::begin([]);
echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(\yii\easyii\modules\catalog\models\Category::find()->all(), 'id', 'title'));
?>

<?php 
echo $form->field($model, 'field_group_id')->dropDownList(ArrayHelper::map(\yii\easyii\modules\catalog\models\CategoryFieldGroup::find()->all(), 'id', 'title_system'));
?>


<?php 
echo Html::submitButton(Yii::t('easyii', 'Save'), ['class' => 'btn btn-primary']);
?>

<?php 
ActiveForm::end();
 public function insertCatalog()
 {
     if (catalog\models\Category::find()->count()) {
         return '`<b>' . catalog\models\Category::tableName() . '</b>` table is not empty, skipping...';
     }
     $this->db->createCommand('TRUNCATE TABLE `' . catalog\models\Category::tableName() . '`')->query();
     $fields = [['name' => 'brand', 'title' => 'Brand', 'type' => 'select', 'options' => ['Samsung', 'Apple', 'Nokia']], ['name' => 'storage', 'title' => 'Storage', 'type' => 'string', 'options' => ''], ['name' => 'touchscreen', 'title' => 'Touchscreen', 'type' => 'boolean', 'options' => ''], ['name' => 'cpu', 'title' => 'CPU cores', 'type' => 'select', 'options' => ['1', '2', '4', '8']], ['name' => 'features', 'title' => 'Features', 'type' => 'checkbox', 'options' => ['Wi-fi', '4G', 'GPS']], ['name' => 'color', 'title' => 'Color', 'type' => 'checkbox', 'options' => ['White', 'Black', 'Red', 'Blue']]];
     $root = new catalog\models\Category(['title' => 'Gadgets', 'fields' => $fields]);
     $root->makeRoot();
     $cat1 = new catalog\models\Category(['title' => 'Smartphones', 'fields' => $fields]);
     $cat1->appendTo($root);
     $this->attachSeo($cat1, 'Smartphones H1', 'Extended smartphones title');
     $cat2 = new catalog\models\Category(['title' => 'Tablets', 'fields' => $fields]);
     $cat2->appendTo($root);
     $this->attachSeo($cat2, 'Tablets H1', 'Extended tablets title');
     if (catalog\models\Item::find()->count()) {
         return '`<b>' . catalog\models\Item::tableName() . '</b>` table is not empty, skipping...';
     }
     $time = time();
     $item1 = new catalog\models\Item(['category_id' => $cat1->primaryKey, 'title' => 'Nokia 3310', 'description' => '<h3>The legend</h3><p>The Nokia 3310 is a GSMmobile phone announced on September 1, 2000, and released in the fourth quarter of the year, replacing the popular Nokia 3210. The phone sold extremely well, being one of the most successful phones with 126 million units sold worldwide.&nbsp;The phone has since received a cult status and is still widely acclaimed today.</p><p>The 3310 was developed at the Copenhagen Nokia site in Denmark. It is a compact and sturdy phone featuring an 84 × 48 pixel pure monochrome display. It has a lighter 115 g battery variant which has fewer features; for example the 133 g battery version has the start-up image of two hands touching while the 115 g version does not. It is a slightly rounded rectangular unit that is typically held in the palm of a hand, with the buttons operated with the thumb. The blue button is the main button for selecting options, with "C" button as a "back" or "undo" button. Up and down buttons are used for navigation purposes. The on/off/profile button is a stiff black button located on the top of the phone.</p>', 'available' => 5, 'discount' => 0, 'price' => 100, 'data' => ['brand' => 'Nokia', 'storage' => '1', 'touchscreen' => '0', 'cpu' => 1, 'color' => ['White', 'Red', 'Blue']], 'image' => '/uploads/catalog/3310.jpg', 'time' => $time]);
     $item1->save();
     $this->attachPhotos($item1, ['/uploads/photos/3310-1.jpg', '/uploads/photos/3310-2.jpg']);
     $this->attachSeo($item1, 'Nokia 3310');
     $item2 = new catalog\models\Item(['category_id' => $cat1->primaryKey, 'title' => 'Galaxy S6', 'description' => '<h3>Next is beautifully crafted</h3><p>With their slim, seamless, full metal and glass construction, the sleek, ultra thin edged Galaxy S6 and unique, dual curved Galaxy S6 edge are crafted from the finest materials.</p><p>And while they may be the thinnest smartphones we`ve ever created, when it comes to cutting-edge technology and flagship Galaxy experience, these 5.1" QHD Super AMOLED smartphones are certainly no lightweights.</p>', 'available' => 1, 'discount' => 10, 'price' => 1000, 'data' => ['brand' => 'Samsung', 'storage' => '32', 'touchscreen' => '1', 'cpu' => 8, 'features' => ['Wi-fi', 'GPS']], 'image' => '/uploads/catalog/galaxy.jpg', 'time' => $time - 86400]);
     $item2->save();
     $this->attachPhotos($item2, ['/uploads/photos/galaxy-1.jpg', '/uploads/photos/galaxy-2.jpg', '/uploads/photos/galaxy-3.jpg', '/uploads/photos/galaxy-4.jpg']);
     $this->attachSeo($item2, 'Samsung Galaxy S6');
     $item3 = new catalog\models\Item(['category_id' => $cat1->primaryKey, 'title' => 'Iphone 6', 'description' => '<h3>Next is beautifully crafted</h3><p>With their slim, seamless, full metal and glass construction, the sleek, ultra thin edged Galaxy S6 and unique, dual curved Galaxy S6 edge are crafted from the finest materials.</p><p>And while they may be the thinnest smartphones we`ve ever created, when it comes to cutting-edge technology and flagship Galaxy experience, these 5.1" QHD Super AMOLED smartphones are certainly no lightweights.</p>', 'available' => 0, 'discount' => 10, 'price' => 1100, 'data' => ['brand' => 'Apple', 'storage' => '64', 'touchscreen' => '1', 'cpu' => 4, 'features' => ['Wi-fi', '4G', 'GPS']], 'image' => '/uploads/catalog/iphone.jpg', 'time' => $time - 86400 * 2]);
     $item3->save();
     $this->attachPhotos($item3, ['/uploads/photos/iphone-1.jpg', '/uploads/photos/iphone-2.jpg', '/uploads/photos/iphone-3.jpg', '/uploads/photos/iphone-4.jpg']);
     $this->attachSeo($item3, 'Apple Iphone 6');
     return 'Catalog data inserted.';
 }
Example #18
0
 public function actionDelete($id)
 {
     if ($model = Category::findOne($id)) {
         $model->delete();
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse(Yii::t('easyii/catalog', 'Category deleted'));
 }
Example #19
0
 private function findCategory($id_slug)
 {
     //asline $category = Category::find()->where(['or', 'category_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one();
     if (is_numeric($id_slug)) {
         $category = Category::find()->where('category_id=:id_slug', [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one();
     } else {
         $category = Category::find()->where('slug=:id_slug', [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one();
     }
     return $category ? new CategoryObject($category) : null;
 }