Пример #1
0
 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]);
 }
Пример #2
0
 public function actionList($id)
 {
     $model = CarouselCatalog::findOne($id);
     if ($model === null) {
         $this->flash('error', Yii::t('easyii', 'Not found'));
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     if (Yii::$app->request->post('save')) {
         $items = [];
         foreach (Yii::$app->request->post('Items', []) as $itemData) {
             $item = Json::decode($itemData, false);
             if ($item === null || empty($item->item_id) || !($item->item_id = trim($item->item_id))) {
                 continue;
             }
             $items[] = $item->item_id;
         }
         $model->items = $items;
         if ($model->save()) {
             $this->flash('success', Yii::t('easyii/carouselcatalog', 'Item updated'));
         } else {
             $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
         }
         return $this->refresh();
     } else {
         $items = Item::find()->where(['not in', 'item_id', $model->items])->all();
         $already = Item::find()->where(['in', 'item_id', $model->items])->orderBy(['FIELD(item_id, ' . join(', ', $model->items) . ')' => ''])->all();
         foreach ($already as &$_already) {
             $_already = new ItemObject($_already);
         }
         foreach ($items as &$item) {
             $item = new ItemObject($item);
         }
     }
     return $this->render('list', ['model' => $model, 'items' => $items, 'already' => $already]);
 }
Пример #3
0
 /**
  * @param array $options
  * @return Item[]
  */
 public function items($options = [])
 {
     if (!$this->_items) {
         $this->_items = [];
         $query = Item::find()->with('seo')->where(['category_id' => $this->id]);
         //->status(Item::STATUS_ON);
         if (!empty($options['where'])) {
             $query->andFilterWhere($options['where']);
         }
         if (!empty($options['orderBy'])) {
             // $query->orderBy($options['orderBy']);
         } else {
             $query->getSortBehavior()->sort();
             //$query->sortDate();
         }
         if (!empty($options['filters'])) {
             $query = Catalog::applyFilters($options['filters'], $query);
         }
         $this->_adp = new ActiveDataProvider(['query' => $query, 'pagination' => !empty($options['pagination']) ? $options['pagination'] : []]);
         // var_dump($query->createCommand()); die;
         foreach ($this->_adp->models as $model) {
             $this->_items[] = $model;
         }
     }
     return $this->_items;
 }
Пример #4
0
 public function api_add($item_id, $count = 1, $options = '', $increaseOnDuplicate = true)
 {
     $item = Item::findOne($item_id);
     if (!$item) {
         return ['result' => 'error', 'code' => self::ERROR_ITEM_NOT_FOUND, 'error' => 'Item no found'];
     }
     if (!$this->order->id) {
         if (!$this->order->model->save()) {
             return ['result' => 'error', 'code' => self::ERROR_CREATE_ORDER, 'error' => 'Cannot create order. ' . $this->order->formatErrors()];
         }
         Yii::$app->session->set(Order::SESSION_KEY, $this->order->model->access_token);
     }
     $good = Good::findOne(['order_id' => $this->order->id, 'item_id' => $item->primaryKey, 'options' => $options]);
     if ($good && !$increaseOnDuplicate) {
         return ['result' => 'error', 'code' => self::ERROR_GOOD_DUPLICATE, 'error' => 'Dublicate good in order.'];
     }
     if ($good) {
         $good->count += $count;
     } else {
         $good = new Good(['order_id' => $this->order->id, 'item_id' => $item->primaryKey, 'count' => (int) $count, 'options' => $options, 'discount' => $item->discount, 'price' => $item->price]);
     }
     if ($good->save()) {
         $response = ['result' => 'success', 'order_id' => $this->order->id, 'good_id' => $good->primaryKey, 'item_id' => $item->primaryKey, 'options' => $good->options, 'discount' => $good->discount];
         if ($response['discount']) {
             $response['price'] = round($good->price * (1 - $good->discount / 100));
             $response['old_price'] = $good->price;
         } else {
             $response['price'] = $good->price;
         }
         return $response;
     } else {
         return ['result' => 'error', 'code' => self::ERROR_CREATE_GOOD, 'error' => $good->formatErrors()];
     }
 }
Пример #5
0
 public static function FetchProducts()
 {
     $sql = 'SELECT * FROM easyii_catalog_items where category_id=2';
     $allProducts = Item::findBySql($sql)->all();
     $listData = ArrayHelper::map($allProducts, 'item_code', 'title');
     return $listData;
 }
Пример #6
0
 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;
 }
Пример #7
0
 public function actionIndex2()
 {
     $items = Item::find()->all();
     foreach ($items as $index => $item) {
         /** @var Item $item */
         echo "{$index}/" . (count($items) - 1) . PHP_EOL;
         $itemObject = new ItemObject($item);
         $item->getFieldManager()->getValueField('divan-common', 'title')->setValue($item->title);
         $item->getFieldManager()->getValueField('divan-common', 'description')->setValue($itemObject->getDescription());
         $item->getFieldManager()->getValueField('divan-common', 'price')->setValue($item->price);
         $item->getFieldManager()->getValueField('divan-common', 'price-old')->setValue($item->old_price);
         $item->getFieldManager()->save();
     }
 }
Пример #8
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();
 }
Пример #9
0
 /**
  * @param string $attributeName
  * @return string[]|int[]
  */
 public function getRange($attributeName)
 {
     $attribute = $this->model->getAttributesBehavior()->getAttributeInfo($attributeName);
     /** @var ActiveRecord $modelClass */
     $modelClass = $this->query->modelClass;
     $tableName = $modelClass::tableName();
     /* Если такой параметр не описан, то будет взят список из таблицы */
     if (!$attribute) {
         $query = $modelClass::find();
         $query->select([$attributeName]);
         $query->groupBy([$attributeName]);
         $query->filterWhere(['and', ['not', $attributeName, null], ['>', new Expression('LENGTH(TRIM(' . $attributeName . '))'), 0]]);
         $result = $query->createCommand()->cache(300)->queryAll();
         $return = [];
         foreach ($result as $row) {
             $return[] = $row[$attributeName];
         }
         return $return;
     }
     return null;
 }
Пример #10
0
 private function findItem($id_slug)
 {
     if (is_numeric($id_slug)) {
         $item = Item::find()->where('item_id=:id_slug', [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one();
     } else {
         $item = Item::find()->where('slug=:id_slug', [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one();
     }
     /* asline
             if(!($item = Item::find()->where(['or', 'item_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one())){
                 return null;
             }
     */
     if (!$item) {
         return null;
     } else {
         return new ItemObject($item);
     }
 }
Пример #11
0
 public function actionSortInsert($id, $position)
 {
     $this->item->getSortBehavior()->insertTo($position);
 }
 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.';
 }
Пример #13
0
 public function getServices()
 {
     $model = \yii\easyii\modules\catalog\models\Item::find()->all();
     $listData = ArrayHelper::map($model, 'item_id', 'title');
     return $listData;
 }
Пример #14
0
 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());
 }
Пример #15
0
 private function findItem($id_slug)
 {
     if (!($item = Item::find()->where(['or', 'item_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->one())) {
         return null;
     }
     $itemObject = $this->parseItem($item);
     $itemObject->photos = $this->parsePhotos($item->photos);
     $itemObject->seo_h1 = $item->seo_h1;
     $itemObject->seo_title = $item->seo_title;
     $itemObject->seo_keywords = $item->seo_keywords;
     $itemObject->seo_description = $item->seo_description;
     return $itemObject;
 }
Пример #16
0
 public function rules()
 {
     return [['data', 'required'], ['item_id', 'exists', Item::className(), 'item_id']];
 }
Пример #17
0
 public function getItems()
 {
     return $this->hasMany(Item::className(), ['category_id' => 'category_id'])->sort();
 }
Пример #18
0
<?php

use yii\easyii\modules\article\api\Article;
use yii\easyii\modules\carousel\api\Carousel;
use yii\easyii\modules\gallery\api\Gallery;
use yii\easyii\modules\guestbook\api\Guestbook;
use yii\easyii\modules\news\api\News;
use yii\easyii\modules\page\api\Page;
use yii\easyii\modules\text\api\Text;
use yii\helpers\Html;
use yii\easyii\models\Setting;
$page = Page::get('about');
$this->title = yii::t('easyii', 'Dry Site Map');
$products = \yii\easyii\modules\catalog\models\Item::find()->where('category_id =2')->all();
?>

<div class="content">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <h2 class="title"><?php 
echo yii::t('easyii', 'site map');
?>
 </h2>
            </div>
        </div>
        <div class="row">
            <div class="site-map center-block">
                <a href="/"><i class="fa fa-circle"></i> <?php 
echo yii::t('easyii', 'home');
?>
Пример #19
0
 public function export($file = '')
 {
     if (empty($file)) {
         $file = static::generateFile();
     }
     $this->_phpExcel = new \PHPExcel();
     $this->_worksheet = $this->_phpExcel->setActiveSheetIndex(0);
     $file = str_ireplace(['{categoryId}'], [$this->categoryId], $file);
     $templateItem = new Item();
     $templateSeo = new SeoText();
     $export = $this->getExport();
     $this->_worksheet->setTitle($this->_category->title);
     // Пишем заголовки
     foreach ($export as $exportIndex => $exportValue) {
         $columnIndex = \PHPExcel_Cell::stringFromColumnIndex($exportIndex) . '1';
         if (isset($exportValue[2]) && is_array($exportValue[2]) && isset($exportValue[2]['label'])) {
             $label = $exportValue[2]['label'];
         } else {
             switch ($exportValue[0]) {
                 case static::TYPE_ATTRIBUTE:
                     $label = $templateItem->getAttributeLabel($exportValue[1]);
                     break;
                 case static::TYPE_FIELD:
                     $field = $this->_category->getFieldByName($exportValue[1]);
                     $label = $field->title;
                     break;
                 case static::TYPE_SEO:
                     $label = $templateSeo->getAttributeLabel($exportValue[1]);
                     break;
                 case static::TYPE_CUSTOM:
                     $label = $exportValue[2]['label'];
                     break;
             }
         }
         $this->_worksheet->setCellValue($columnIndex, $label);
     }
     $items = $this->_category->getItems()->all();
     foreach ($items as $itemIndex => $item) {
         foreach ($export as $exportIndex => $exportValue) {
             $value = '';
             switch ($exportValue[0]) {
                 case static::TYPE_FIELD:
                     $value = ArrayHelper::getValue($item->data, $exportValue[1]);
                     break;
                 case static::TYPE_ATTRIBUTE:
                     $value = $item->{$exportValue[1]};
                     break;
                 case static::TYPE_CUSTOM:
                     $value = $exportValue[2]['get']($item);
                     break;
                 case static::TYPE_SEO:
                     $value = $item->seo->{$exportValue[1]};
                     break;
             }
             $this->_worksheet->setCellValue(\PHPExcel_Cell::stringFromColumnIndex($exportIndex) . ($itemIndex + 2), $value);
             if (isset($exportValue[2]['type'])) {
                 switch ($exportValue[2]['type']) {
                     case static::CELL_TYPE_HYPERLINK:
                         $this->_worksheet->getCell(\PHPExcel_Cell::stringFromColumnIndex($exportIndex) . ($itemIndex + 2))->getHyperlink()->setUrl('"' . $value . '"');
                         break;
                 }
             }
             if (isset($exportValue[2]['width'])) {
                 $this->_worksheet->getColumnDimension(\PHPExcel_Cell::stringFromColumnIndex($exportIndex))->setWidth($exportValue[2]['width']);
             }
         }
     }
     $writer = \PHPExcel_IOFactory::createWriter($this->_phpExcel, 'Excel2007');
     @\yii\helpers\FileHelper::createDirectory(dirname($file));
     $writer->save($file);
     return $file;
     header('Content-Type: application/vnd.ms-excel');
     header('Content-Disposition: attachment;filename="' . basename($file) . '"');
     header('Cache-Control: max-age=0');
     readfile($file);
     exit;
 }
Пример #20
0
 public static function applyFilters($filters, $query)
 {
     if (is_array($filters)) {
         if (!empty($filters['country'])) {
             $query->andFilterWhere(['=', 'country', $filters['country']]);
             unset($filters['country']);
         }
         if (!empty($filters['government'])) {
             $query->andFilterWhere(['=', 'government', $filters['government']]);
             unset($filters['government']);
         }
         if (!empty($filters['city'])) {
             $query->andFilterWhere(['=', 'city', $filters['city']]);
             unset($filters['city']);
         }
         if (!empty($filters['district'])) {
             $query->andFilterWhere(['=', 'district', $filters['district']]);
             unset($filters['district']);
         }
         if (!empty($filters['product_id'])) {
             //get all pharmacies for this product
             $sql = 'SELECT customer_id FROM customer_items where item_id=' . $filters['product_id'];
             $allpharmacies = \yii\easyii\modules\catalog\models\Item::findBySql($sql)->asArray()->all();
             $data[] = null;
             foreach ($allpharmacies as $key => $value) {
                 $data[] = $value[customer_id] . ',';
             }
             $query->andFilterWhere(['in', 'item_id', $data]);
             unset($filters['product_id']);
         }
     }
     return $query;
 }
Пример #21
0
 public function getPhotos($index = null)
 {
     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);
         }
     }
     if (is_numeric($index)) {
         if (isset($this->_photos[$index])) {
             return $this->_photos[$index];
         } else {
             return null;
         }
     }
     return $this->_photos;
 }
Пример #22
0
 private function findItem($id_slug)
 {
     if (!($item = Item::find()->where(['or', 'item_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one())) {
         return null;
     }
     return new ItemObject($item);
 }
Пример #23
0
 public function actionDelete($id)
 {
     if ($model = Item::findOne($id)) {
         $model->delete();
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse(Yii::t('easyii/catalog', 'Item deleted'));
 }
Пример #24
0
 public function getItem()
 {
     return $this->hasOne(Item::className(), ['item_id' => 'item_id']);
 }
Пример #25
0
 public function getPhotos()
 {
     return $this->hasMany(Photo::className(), ['item_id' => 'item_id'])->where(['model' => Item::className()])->sort();
 }