From d0c66642bfb475d1a14f46c7505a01740708832c Mon Sep 17 00:00:00 2001 From: yarik Date: Wed, 9 Nov 2016 14:25:20 +0200 Subject: [PATCH] Namespaces --- behaviors/ArtBoxAccessBehavior.php | 2 +- behaviors/ImageBehavior.php | 4 ++-- behaviors/MultipleImgBehavior.php | 6 +++--- behaviors/SaveImgBehavior.php | 4 ++-- behaviors/SaveMultipleFileBehavior.php | 4 ++-- behaviors/Slug.php | 3 +-- components/SmsSender.php | 2 +- components/artboximage/ArtboxImage.php | 2 +- components/artboximage/ArtboxImageHelper.php | 4 ++-- components/artboxtree/ArtboxTreeBehavior.php | 2 +- components/artboxtree/ArtboxTreeHelper.php | 2 +- components/artboxtree/ArtboxTreeQueryTrait.php | 2 +- components/artboxtree/ArtboxTreeWidget.php | 2 +- components/artboxtree/treegrid/TreeGridColumn.php | 3 +-- components/artboxtree/treegrid/TreeGridWidget.php | 6 +++--- components/artboxtree/treelist/TreeListWidget.php | 5 ++--- components/artboxtree/treemenu/TreeMenuWidget.php | 5 ++--- composer.json | 13 ++++++++++++- console/GenerateController.php | 285 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- console/ImportController.php | 57 --------------------------------------------------------- console/SiteMapController.php | 220 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- models/Customer.php | 3 ++- models/CustomerSearch.php | 4 ++-- models/Feedback.php | 2 +- models/FeedbackSearch.php | 2 +- models/Page.php | 4 ++-- models/PageLang.php | 6 +++--- models/PageSearch.php | 4 ++-- 28 files changed, 52 insertions(+), 606 deletions(-) delete mode 100644 console/GenerateController.php delete mode 100755 console/ImportController.php delete mode 100755 console/SiteMapController.php diff --git a/behaviors/ArtBoxAccessBehavior.php b/behaviors/ArtBoxAccessBehavior.php index 38130bc..05e6ad8 100755 --- a/behaviors/ArtBoxAccessBehavior.php +++ b/behaviors/ArtBoxAccessBehavior.php @@ -1,6 +1,6 @@ =7.0", "yiisoft/yii2": "*", - "developeruz/yii2-db-rbac": "*" + "developeruz/yii2-db-rbac": "*", + "yurkinx/yii2-image": "dev-master", + "artweb/artbox-ecommerce": "dev-master", + "artweb/artbox-language": "dev-master", + "kartik-v/yii2-widget-select2": "@dev", + "kartik-v/yii2-grid": "@dev", + "kartik-v/yii2-mpdf": "@dev", + "kartik-v/yii2-widget-fileinput": "@dev", + "mihaildev/yii2-ckeditor": "*", + "mihaildev/yii2-elfinder": "^1.1", + "kartik-v/yii2-widget-colorinput": "*", + "kartik-v/yii2-widget-datepicker": "*" }, "autoload": { "psr-4": { diff --git a/console/GenerateController.php b/console/GenerateController.php deleted file mode 100644 index 7217bfe..0000000 --- a/console/GenerateController.php +++ /dev/null @@ -1,285 +0,0 @@ - 'ru_RU', - 3 => 'uk_UA', - ]; - - /** - * Faker Generators instances - * - * @var Generator[] $fakers - */ - private $fakers = []; - - /** - * Create faker Generators for all $locales - * - * @param \yii\base\Action $action - * - * @return bool - */ - public function beforeAction($action) - { - $parent = parent::beforeAction($action); - $fakers = []; - foreach ($this->locales as $locale_id => $locale) { - $fakers[ $locale_id ] = Factory::create($locale); - } - $this->fakers = $fakers; - return $parent; - } - - /** - * Generate fake Brands - * - * @param int $count Brands count - * - * @return int - */ - public function actionBrand(int $count = 10): int - { - /** - * @var Brand[] $models - */ - $models = []; - $fakers = $this->fakers; - for ($i = 0; $i < $count; $i++) { - $models[ $i ] = \Yii::createObject(Brand::className()); - $models[ $i ]->generateLangs(); - foreach ($models[ $i ]->modelLangs as $language_id => $modelLang) { - $modelLang->title = $fakers[ $language_id ]->company; - } - if ($models[ $i ]->save() && $models[ $i ]->transactionStatus) { - $title = $this->ansiFormat($models[ $i ]->modelLangs[ 2 ]->title, Console::FG_YELLOW); - $id = $this->ansiFormat($models[ $i ]->id, Console::FG_YELLOW); - echo "Brand '$title' inserted under $id ID.\n"; - }; - } - return 0; - } - - /** - * Generate fake categories - * - * @param int $count Category count - * - * @return int - */ - public function actionCategory(int $count = 10):int - { - /** - * @var Category[] $models - */ - $models = []; - $fakers = $this->fakers; - for ($i = 0; $i < $count; $i++) { - $models[ $i ] = \Yii::createObject( - [ - 'class' => Category::className(), - 'depth' => 0, - 'parent_id' => 0, - ] - ); - $models[ $i ]->generateLangs(); - foreach ($models[ $i ]->modelLangs as $language_id => $modelLang) { - $modelLang->title = ucfirst($fakers[ $language_id ]->word); - } - if ($models[ $i ]->save() && $models[ $i ]->transactionStatus) { - $title = $this->ansiFormat($models[ $i ]->modelLangs[ 2 ]->title, Console::FG_YELLOW); - $id = $this->ansiFormat($models[ $i ]->id, Console::FG_YELLOW); - echo "Category '$title' inserted under $id ID.\n"; - }; - } - return 0; - } - - /** - * Generate fake products with variants, categories and tax options - * - * @param int $count Product count - * - * @return int - */ - public function actionProduct(int $count = 10):int - { - /** - * @var Product[] $models - */ - $models = []; - $fakers = $this->fakers; - $brands = Brand::find() - ->limit(20) - ->asArray() - ->column(); - $categories = Category::find() - ->limit(100) - ->asArray() - ->column(); - $product_options = TaxOption::find() - ->joinWith('taxGroup') - ->where([ 'tax_group.level' => TaxGroup::GROUP_PRODUCT ]) - ->limit(50) - ->asArray() - ->column(); - $variant_options = TaxOption::find() - ->joinWith('taxGroup') - ->where([ 'tax_group.level' => TaxGroup::GROUP_VARIANT ]) - ->limit(50) - ->asArray() - ->column(); - for ($i = 0; $i < $count; $i++) { - $models[ $i ] = \Yii::createObject( - [ - 'class' => Product::className(), - 'brand_id' => $fakers[ 2 ]->randomElement($brands), - ] - ); - $models[ $i ]->setCategories( - $fakers[ 2 ]->randomElements($categories, $fakers[ 2 ]->randomDigitNotNull) - ); - $models[ $i ]->setOptions( - $fakers[ 2 ]->randomElements($product_options, $fakers[ 2 ]->randomDigitNotNull) - ); - $models[ $i ]->generateLangs(); - foreach ($models[ $i ]->modelLangs as $language_id => $modelLang) { - $modelLang->title = ucfirst($fakers[ $language_id ]->word); - } - if ($models[ $i ]->save() && $models[ $i ]->transactionStatus) { - $title = $this->ansiFormat($models[ $i ]->modelLangs[ 2 ]->title, Console::FG_YELLOW); - $id = $this->ansiFormat($models[ $i ]->id, Console::FG_YELLOW); - echo "Product '$title' inserted under $id ID.\n"; - $variant_count = $fakers[ 2 ]->numberBetween(4, 10); - for ($j = 0; $j < $variant_count; $j++) { - /** - * @var ProductVariant $variant - */ - $variant = \Yii::createObject( - [ - 'class' => ProductVariant::className(), - 'product_id' => $models[ $i ]->id, - 'sku' => $fakers[ 2 ]->uuid, - 'price' => $fakers[ 2 ]->randomFloat(2, 100, 10000), - 'stock' => 10, - 'product_unit_id' => 1, - ] - ); - $variant->setOptions( - $fakers[ 2 ]->randomElements($variant_options, $fakers[ 2 ]->randomDigitNotNull) - ); - $variant->generateLangs(); - foreach ($variant->modelLangs as $variant_language_id => $variantLang) { - $variantLang->title = ucfirst($fakers[ $variant_language_id ]->word); - } - if ($variant->save() && $variant->transactionStatus) { - $variant_title = $this->ansiFormat($variant->modelLangs[ 2 ]->title, Console::FG_YELLOW); - $variant_id = $this->ansiFormat($variant->id, Console::FG_YELLOW); - echo "Variant '$variant_title' inserted under $variant_id ID for product $title.\n"; - } - } - }; - } - return 0; - } - - /** - * Generate fake tax groups with tax options. - * - * @param int $count_product Tax Groups for Product - * @param int $count_variant Tax Groups for ProductVariant - * - * @return int - */ - public function actionTax(int $count_product = 10, int $count_variant = 10):int - { - $categories = Category::find() - ->asArray() - ->column(); - $this->generateTax(TaxGroup::GROUP_PRODUCT, $count_product, $categories); - $this->generateTax(TaxGroup::GROUP_VARIANT, $count_variant, $categories); - return 0; - } - - /** - * Generates tax groups amd tax options for actionTax - * - * @param int $level Tax Group for Product or ProductVariant - * @param int $count Tax Group count - * @param array $categories Categories for Tax Groups - * - * @see GenerateController::actionTax() - */ - private function generateTax(int $level, int $count, array $categories = []) - { - $count_option = 10; - $fakers = $this->fakers; - /** - * @var TaxGroup[] $models - */ - $models = []; - for ($i = 0; $i < $count; $i++) { - $models[ $i ] = \Yii::createObject( - [ - 'class' => TaxGroup::className(), - 'is_filter' => true, - 'display' => true, - ] - ); - $models[ $i ]->level = $level; - $models[ $i ]->setCategories($categories); - $models[ $i ]->generateLangs(); - foreach ($models[ $i ]->modelLangs as $language_id => $modelLang) { - $modelLang->title = ucfirst($fakers[ $language_id ]->word); - } - if ($models[ $i ]->save() && $models[ $i ]->transactionStatus) { - for ($j = 0; $j < $count_option; $j++) { - /** - * @var TaxOption $option - */ - $option = \Yii::createObject( - TaxOption::className() - ); - $option->tax_group_id = $models[ $i ]->id; - $option->generateLangs(); - foreach ($option->modelLangs as $option_language_id => $taxOptionLang) { - $taxOptionLang->value = ucfirst($fakers[ $option_language_id ]->word); - } - $option->save(); - } - $title = $this->ansiFormat($models[ $i ]->modelLangs[ 2 ]->title, Console::FG_YELLOW); - $id = $this->ansiFormat($models[ $i ]->id, Console::FG_YELLOW); - $element = $this->ansiFormat( - ( $level === TaxGroup::GROUP_PRODUCT ) ? 'Product' : 'Variant', - Console::FG_RED - ); - echo "Category '$title' inserted for $element under $id ID.\n"; - }; - } - } - } - \ No newline at end of file diff --git a/console/ImportController.php b/console/ImportController.php deleted file mode 100755 index 445a60c..0000000 --- a/console/ImportController.php +++ /dev/null @@ -1,57 +0,0 @@ -stderr('Task already executed'); - return Controller::EXIT_CODE_ERROR; - } - return fopen ($filename, 'r'); - } - - public function actionProducts() { -// if (file_exists(Yii::getAlias('@uploadDir/goProducts.lock'))) { -// $this->errors[] = 'Task already executed'; -// return Controller::EXIT_CODE_ERROR; -// } -// $ff = fopen(Yii::getAlias('@uploadDir/goProducts.lock'), 'w+'); -// fclose($ff); - $model = new Import(); - $model->goProducts(0, null); -// unlink(Yii::getAlias('@uploadDir/goProducts.lock')); - return Controller::EXIT_CODE_NORMAL; - } - - public function actionPrices() { - if (file_exists(Yii::getAlias('@uploadDir/goPrices.lock'))) { - $this->stderr('Task already executed'); - return Controller::EXIT_CODE_ERROR; - } - $ff = fopen(Yii::getAlias('@uploadDir/goPrices.lock'), 'w+'); - fclose($ff); - $model = new Import(); - $data = $model->goPrices(0, null); - unlink(Yii::getAlias('@uploadDir/goPrices.lock')); - return Controller::EXIT_CODE_NORMAL; - } - - private function saveNotFoundRecord (array $line, $filename) - { - $str = implode (';', $line)."\n"; - $str = iconv ("UTF-8//TRANSLIT//IGNORE", "windows-1251", $str); - - $fg = fopen (Yii::getAlias('@uploadDir') .'/'. $filename, 'a+'); - fputs ($fg, $str); - fclose ($fg); - } -} \ No newline at end of file diff --git a/console/SiteMapController.php b/console/SiteMapController.php deleted file mode 100755 index 842c2f1..0000000 --- a/console/SiteMapController.php +++ /dev/null @@ -1,220 +0,0 @@ -search($category, $filter); - if(!empty($productProvider->models)){ - return true; - } else { - return false; - } - } - - - - public function getAddStatic(){ - return [ - 'http://www.rukzachok.com.ua', - 'http://www.rukzachok.com.ua/catalog' - ]; - } - - - public function getProducts() { - return Product::find()->all(); - - } - - - public function getSeoLinks() { - return Seo::find()->where(['meta' => ''])->all(); - - } - - public function getStaticPages(){ - return Page::find()->all(); - } - - - public function getCategories(){ - return Category::find()->all(); - } - - - public function getArticles(){ - return Article::find()->all(); - } - - public function getBrands($category){ - - return $category->brands; - } - - /** - * @param $category Category; - * @return mixed - */ - - public function getFilters($category){ - - return $category->getActiveFilters()->all(); - - } - - - public function checkUrl($url){ - if(!in_array($url, $this->urlList)){ - $this->urlList[] = $url; - return true; - } else { - return false; - } - } - - - public function createRow( $url, $priority, &$content ){ - if($this->checkUrl($url)){ - print $this->count++ . "\n"; - $content .= '' . - '' . $url . '' . - '' . date('Y-m-d') . '' . - 'Daily' . - '' . $priority .'' . - ''; - } - } - - - public function actionProcess() { - - $config = ArrayHelper::merge( - require(__DIR__ . '/../../frontend/config/main.php'), - require(__DIR__ . '/../../common/config/main.php') - - ); - - Yii::$app->urlManager->addRules($config['components']['urlManager']['rules']); - - - - $dirName = Yii::getAlias('@frontend').'/web'; - - $filename = 'sitemap.xml'; - - setlocale(LC_ALL, 'ru_RU.CP1251'); - $handle = fopen($dirName .'/'. $filename, "w"); - - $content = ''; - - foreach ($this->getAddStatic() as $page) { - $this->createRow($page , 1,$content); - } - - foreach ($this->getStaticPages() as $page) { - $url = Url::to(['text/index','translit' => $page->translit]); - $this->createRow($url , 1,$content); - } - - foreach ($this->getCategories() as $category) { - $url = Url::to(['catalog/category', 'category' => $category]); - $this->createRow($url , 1,$content); - } - - - foreach ($this->getProducts() as $product) { - - $url = Url::to(['catalog/product', 'product' => $product]); - $this->createRow($url , 0.9, $content); - } - - - foreach ($this->getArticles() as $article) { - - $url = Url::to(['articles/show', 'translit' => $article->translit, 'id' => $article->id,]); - $this->createRow($url , 0.8,$content); - - } - - - foreach($this->getCategories() as $category){ - foreach ($this->getBrands($category) as $brand) { - if($this->checkFilter($category, ['brands' => [$brand->id]])){ - $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias]]]) ; - $this->createRow($url , 0.8, $content); - } - } - } - - - foreach($this->getCategories() as $category){ - foreach ($this->getFilters($category) as $filter) { - if($this->checkFilter($category, [$filter['group_alias'] => [$filter['option_alias']]])){ - $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter['group_alias'] => [$filter['option_alias']]] ]); - $this->createRow($url , 0.8, $content); - } - - } - } - - foreach($this->getSeoLinks() as $link){ - $url = Yii::$app->urlManager->baseUrl.$link->url; - $this->createRow($url , 0.7, $content); - - } - - - -// foreach($this->getCategories() as $category){ -// foreach ($this->getFilters($category) as $filter1) { -// foreach ($this->getFilters($category) as $filter2) { -// if($this->checkFilter($category, [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] )){ -// $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] ]); -// $this->createRow($url , 0.7, $content); -// } -// -// } -// -// foreach ($this->getBrands($category) as $brand) { -// if($this->checkFilter($category, ['brands' => [$brand->id], $filter1['group_alias'] => [$filter1['option_alias']]] )){ -// $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias],$filter1['group_alias'] => [$filter1['option_alias']]]]); -// $this->createRow($url , 0.7,$content); -// } -// -// } -// } -// } - - - - $content .= ''; - - fwrite($handle, $content); - fclose($handle); - - print $dirName .'/'. $filename; - } - -} diff --git a/models/Customer.php b/models/Customer.php index 92e2372..f5c0ce4 100755 --- a/models/Customer.php +++ b/models/Customer.php @@ -1,7 +1,8 @@ [ - 'class' => 'common\behaviors\Slug', + 'class' => 'artweb\artbox\behaviors\Slug', ], ]; } diff --git a/models/PageSearch.php b/models/PageSearch.php index d13e26e..6f680fd 100755 --- a/models/PageSearch.php +++ b/models/PageSearch.php @@ -1,12 +1,12 @@