Skip to content

Commit 698a0a2

Browse files
committed
init
0 parents  commit 698a0a2

File tree

9 files changed

+239
-0
lines changed

9 files changed

+239
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor/*
2+
3+
.idea/

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
message:
2+
php vendor/yiisoft/yii2/yii message src/messages/message.php
3+
vendors:
4+
composer update

README.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Yii2 Category
2+
===============
3+
[![Latest Stable Version](https://poser.pugx.org/nullref/yii2-category/v/stable)](https://packagist.org/packages/nullref/yii2-category) [![Total Downloads](https://poser.pugx.org/nullref/yii2-category/downloads)](https://packagist.org/packages/nullref/yii2-category) [![Latest Unstable Version](https://poser.pugx.org/nullref/yii2-category/v/unstable)](https://packagist.org/packages/nullref/yii2-category) [![License](https://poser.pugx.org/nullref/yii2-category/license)](https://packagist.org/packages/nullref/yii2-category)
4+
5+
Module for categories (WIP)
6+
7+
![](https://raw.githubusercontent.com/NullRefExcep/yii2-category/master/docs/assets/screen-demo.gif)
8+
9+
Installation
10+
------------
11+
12+
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
13+
14+
Either run
15+
16+
```
17+
php composer.phar require --prefer-dist nullref/yii2-category "*"
18+
```
19+
20+
or add
21+
22+
```
23+
"nullref/yii2-category": "*"
24+
```
25+
26+
to the require section of your `composer.json` file.
27+
28+
Then You have run console command for install this module:
29+
30+
```
31+
php yii module/install nullref/yii2-category
32+
```
33+
34+
and module will be added to your application config (`@app/config/installed_modules.php`)
35+
36+
Using with admin module
37+
----------------------------
38+
39+
You can use this module with modules:
40+
- [Yii2 Admin](https://github.com/NullRefExcep/yii2-admin).
41+
- [Yii2 Full Admin](https://github.com/NullRefExcep/yii2-full-admin).
42+
43+
Models overriding
44+
-----------------
45+
46+
```php
47+
48+
'category' => [
49+
'class' => 'nullref\category\Module',
50+
'classMap' => [
51+
'Category' => 'app\models\Category',
52+
'CategoryQuery' => 'app\models\CategoryQuery',
53+
],
54+
],
55+
```
56+
57+
Also you have to add module to bootstrap list of application:
58+
59+
```php
60+
...
61+
'bootstrap' => ['category',...],
62+
...
63+
```

composer.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "nullref/yii2-multisite",
3+
"type": "yii2-extension",
4+
"license": "MIT",
5+
"minimum-stability": "dev",
6+
"require": {
7+
"php": ">=5.4.0",
8+
"yiisoft/yii2": ">=2.0.4",
9+
"yiisoft/yii2-jui": "^2.0",
10+
"nullref/yii2-useful": "dev-master"
11+
},
12+
"autoload": {
13+
"psr-4": {
14+
"nullref\\multisite\\": "src/"
15+
}
16+
}
17+
}

src/Installer.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* @author Dmytro Karpovych
4+
* @copyright 2017 NRE
5+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
6+
*/
7+
8+
namespace nullref\multisite;
9+
10+
11+
use nullref\core\components\ModuleInstaller;
12+
13+
class Installer extends ModuleInstaller
14+
{
15+
public function getModuleId()
16+
{
17+
return 'multisite';
18+
}
19+
}

src/Module.php

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace nullref\multisite;
4+
5+
use nullref\core\interfaces\IAdminModule;
6+
use Yii;
7+
use yii\base\Application;
8+
use yii\base\BootstrapInterface;
9+
use yii\base\Module as BaseModule;
10+
use yii\i18n\PhpMessageSource;
11+
use yii\web\Application as WebApplication;
12+
13+
/**
14+
* shop module definition class
15+
*/
16+
class Module extends BaseModule implements IAdminModule, BootstrapInterface
17+
{
18+
/**
19+
* @var array
20+
*/
21+
public $classMap = [];
22+
23+
/**
24+
* @var array
25+
*/
26+
protected $_classMap = [
27+
'Site' => 'nullref\multisite\models\Site',
28+
'SiteQuery' => 'nullref\multisite\models\SiteQuery',
29+
];
30+
31+
/**
32+
* Item for admin menu
33+
* @return array
34+
*/
35+
public static function getAdminMenu()
36+
{
37+
return [
38+
'label' => Yii::t('multisite', 'Multisites'),
39+
'icon' => 'sitemap',
40+
'url' => ['/multisite/admin/default'],
41+
];
42+
}
43+
44+
/**
45+
* Bootstrap method to be called during application bootstrap stage.
46+
* @param Application $app the application currently running
47+
*/
48+
public function bootstrap($app)
49+
{
50+
$classMap = array_merge($this->_classMap, $this->classMap);
51+
foreach (['Site', 'SiteQuery'] as $item) {
52+
$className = __NAMESPACE__ . '\models\\' . $item;
53+
$postClass = $className::className();
54+
$definition = $classMap[$item];
55+
Yii::$container->set($postClass, $definition);
56+
}
57+
58+
if ($app instanceof WebApplication) {
59+
if (!isset($app->i18n->translations['multisite*'])) {
60+
$app->i18n->translations['multisite*'] = [
61+
'class' => PhpMessageSource::className(),
62+
'basePath' => '@nullref/multisite/messages',
63+
];
64+
}
65+
}
66+
67+
}
68+
}

src/helpers/Helper.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* @author Dmytro Karpovych
4+
* @copyright 2017 NRE
5+
*/
6+
7+
8+
namespace nullref\multisite\helpers;
9+
10+
11+
use yii\helpers\Html;
12+
13+
class Helper
14+
{
15+
}

src/messages/message.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
return [
4+
'sourcePath' => __DIR__ . '/src/',
5+
'messagePath' => __DIR__,
6+
'languages' => ['ar', 'az', 'bg', 'bs', 'ca', 'cs', 'da', 'de', 'el', 'es', 'et', 'fa', 'fi', 'fr', 'he', 'hr', 'hu', 'id', 'it', 'ja', 'ka', 'kk', 'ko', 'lt', 'lv', 'ms', 'nb-NO', 'nl', 'pl', 'pt', 'pt-BR', 'ro', 'ru', 'sk', 'sl', 'sr', 'sr-Latn', 'sv', 'th', 'tj', 'uk', 'vi', 'zh-CN', 'zh-TW'],
7+
'translator' => 'Yii::t',
8+
'sort' => false,
9+
'overwrite' => true,
10+
'removeUnused' => false,
11+
'only' => ['*.php'],
12+
'except' => [
13+
'.svn',
14+
'.git',
15+
'.gitignore',
16+
'.gitkeep',
17+
'.hgignore',
18+
'.hgkeep',
19+
'/messages',
20+
'/tests',
21+
'/vendor',
22+
],
23+
'format' => 'php',
24+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace nullref\category\migrations;
4+
5+
use nullref\core\traits\MigrationTrait;
6+
use yii\db\Migration;
7+
8+
class m170212_085035_add_site_table extends Migration
9+
{
10+
use MigrationTrait;
11+
12+
public function up()
13+
{
14+
$this->createTable('{{%site}}', [
15+
'id' => $this->primaryKey(),
16+
'baseUrl' => $this->string(),
17+
]);
18+
19+
}
20+
21+
public function down()
22+
{
23+
$this->dropTable('{{%site}}');
24+
}
25+
26+
}

0 commit comments

Comments
 (0)