Skip to content

Commit

Permalink
breaking changes! updated API Controller, Tree model and db table str…
Browse files Browse the repository at this point in the history
…ucture, name_id -> domain_id + access_domain, name_id -> virtual attribute
  • Loading branch information
Chris Stebe committed Apr 15, 2016
1 parent 2096cbc commit 77c11c6
Show file tree
Hide file tree
Showing 17 changed files with 249 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test:
- docker-compose up -d
- docker-compose run --rm phpfpm setup.sh
- docker-compose run --rm phpfpm codecept clean
- docker-compose run --rm -e YII_ENV=test phpfpm codecept run --html=_report.html unit,acceptance; TESTS_EXIT_CODE=$?
- docker-compose run --rm -e YII_ENV=test phpfpm codecept run --html=_report.html acceptance,unit; TESTS_EXIT_CODE=$?
- set -e
- mv _output /tmp/${BUILD_PREFIX}
- exit $TESTS_EXIT_CODE
Expand Down
2 changes: 1 addition & 1 deletion Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function bootstrap($app)
$app->urlManager->addRules(
[
// pages default page route
'<parentLeave:[a-zA-Z0-9_\-\.]*>/<pageName:[a-zA-Z0-9_\-\.]*>-<id:[0-9]*>' => 'pages/default/page',
'<parentLeave:[a-zA-Z0-9_\- \.]*>/<pageName:[a-zA-Z0-9_\-\.]*>-<id:[0-9]*>' => 'pages/default/page',
'<pageName:[a-zA-Z0-9_\-\.]*>-<id:[0-9]*>' => 'pages/default/page',
],
true
Expand Down
5 changes: 3 additions & 2 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ public function init()
*/
public function getLocalizedRootNode()
{
$localizedRoot = 'root_' . \Yii::$app->language;
$localizedRoot = Tree::ROOT_NODE_PREFIX . '_' . \Yii::$app->language;
\Yii::trace('localizedRoot: ' . $localizedRoot, __METHOD__);
$page = Tree::findOne(
[
Tree::ATTR_NAME_ID => $localizedRoot,
Tree::ATTR_DOMAIN_ID => Tree::ROOT_NODE_PREFIX,
Tree::ATTR_ACCESS_DOMAIN => mb_strtolower(\Yii::$app->language),
Tree::ATTR_ACTIVE => Tree::ACTIVE,
Tree::ATTR_VISIBLE => Tree::VISIBLE
]
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Yii2 Page Manager

Application sitemap and navigation manager module for Yii 2.0 Framework

**:warning: Breaking changes in 0.14.0 :warning:**

`data structure` and `public properties` are updated and query menu items from now on via `domain_id`

Requirements
------------
Expand All @@ -19,13 +22,13 @@ The preferred way to install this extension is through [composer](http://getcomp
Either run

```
composer require dmstr/yii2-pages-module "*"
composer require dmstr/yii2-pages-module "^0.14.0"
```

or add

```
"dmstr/yii2-pages-module": "*"
"dmstr/yii2-pages-module": "^0.14.0"
```

to the require section of your `composer.json` file.
Expand Down Expand Up @@ -69,24 +72,22 @@ Usage

*find a root node / leave node*

by `name_id`
by `domain_id` i.e. `root`

```
$localizedRoot = 'root_' . \Yii::$app->language;
$menuItems = \dmstr\modules\pages\models\Tree::getMenuItems($localizedRoot);
$menuItems = \dmstr\modules\pages\models\Tree::getMenuItems('root');
```

*use for example with bootstrap Navbar*

```
$localizedRoot = 'root_' . \Yii::$app->language;
echo yii\bootstrap\Nav::widget(
[
'options' => ['class' => 'navbar-nav navbar-right'],
'activateItems' => false,
'encodeLabels' => false,
'activateParents' => true,
'items' => Tree::getMenuItems($localizedRoot),
'items' => Tree::getMenuItems('root'),
]
);
```
Expand All @@ -95,7 +96,7 @@ $localizedRoot = 'root_' . \Yii::$app->language;

- visit `/pages` to create a root-node for your current application language.
- click the *tree* icon
- enter `root_LANG` as *Name ID* and *Name* and save
- enter `name identifier (no spaces and special chars)` as *Domain ID* and *Menu name* and save
- create child node
- assign name, title, language and route/view
- save
Expand Down
6 changes: 3 additions & 3 deletions controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ class DefaultController extends Controller
*/
public function actionIndex()
{

if (!$this->module->getLocalizedRootNode()) {
$language = \Yii::$app->language;
$language = mb_strtolower(\Yii::$app->language);
$rootNodePrefix = Tree::ROOT_NODE_PREFIX;

$msg = <<<HTML
<b>Localized root-node missing</b>
<p>
Please create a new root-node for the current language.
</p>
<p>
<a onclick="$('#tree-name_id').val('root_{$language}');$('#tree-name').val('root_{$language}');$('.kv-detail-container button[type=submit]').click()" class="btn btn-warning btn-lg">Create root-node for <b>{$language}</b></a>
<a onclick="$('#tree-domain_id').val('{$rootNodePrefix}');$('#tree-name').val('{$rootNodePrefix}_{$language}');$('.kv-detail-container button[type=submit]').click()" class="btn btn-warning btn-lg">Create root-node for <b>{$language}</b></a>
</p>
HTML;

Expand Down
14 changes: 8 additions & 6 deletions controllers/api/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function actions()
* Supported $_GET params for /pages/api/default/index
*
* @param dmstr\modules\pages\models\Tree::ATTR_ID
* @param dmstr\modules\pages\models\Tree::ATTR_NAME_ID
* @param dmstr\modules\pages\models\Tree::ATTR_DOMAIN_ID
* @param dmstr\modules\pages\models\Tree::ATTR_ROOT
* @param dmstr\modules\pages\models\Tree::ATTR_ACCESS_DOMAIN
*/
Expand All @@ -45,15 +45,17 @@ public function actions()
if (isset($_GET[$modelClass::ATTR_ID])) {
$query->andFilterWhere([$modelClass::ATTR_ID => $_GET[$modelClass::ATTR_ID]]);
}
if (isset($_GET[$modelClass::ATTR_NAME_ID])) {
$query->andFilterWhere([$modelClass::ATTR_NAME_ID => $_GET[$modelClass::ATTR_NAME_ID]]);
if (isset($_GET[$modelClass::ATTR_DOMAIN_ID]) && isset($_GET[$modelClass::ATTR_ACCESS_DOMAIN])) {
$query->andFilterWhere(
[$modelClass::ATTR_DOMAIN_ID => $_GET[$modelClass::ATTR_DOMAIN_ID]]
);
$query->andFilterWhere(
[$modelClass::ATTR_ACCESS_DOMAIN => $_GET[$modelClass::ATTR_ACCESS_DOMAIN]]
);
}
if (isset($_GET[$modelClass::ATTR_ROOT])) {
$query->andFilterWhere([$modelClass::ATTR_ROOT => $_GET[$modelClass::ATTR_ROOT]]);
}
if (isset($_GET[$modelClass::ATTR_ACCESS_DOMAIN])) {
$query->andFilterWhere([$modelClass::ATTR_ACCESS_DOMAIN => $_GET[$modelClass::ATTR_ACCESS_DOMAIN]]);
}

return new \yii\data\ActiveDataProvider(
[
Expand Down
21 changes: 21 additions & 0 deletions migrations/m160411_082658_rename_name_id_column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use yii\db\Migration;

class m160411_082658_rename_name_id_column extends Migration
{
public function up()
{
$this->dropIndex('name_id_UNIQUE', 'dmstr_page');
$this->renameColumn('dmstr_page', 'name_id', 'domain_id');
$this->execute("ALTER TABLE dmstr_page MODIFY COLUMN domain_id VARCHAR(255) NOT NULL;");
$this->execute(
"ALTER TABLE `dmstr_page` ADD UNIQUE INDEX `name_id_UNIQUE` (`domain_id`, `access_domain`);"
);
}

public function down()
{
return false;
}
}
29 changes: 29 additions & 0 deletions migrations/m160411_111111_name_id_to_domain_id_renamer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use yii\db\Migration;

class m160411_111111_name_id_to_domain_id_renamer extends Migration
{
public function up()
{
$languages = explode(',', getenv('APP_LANGUAGES'));

if (count($languages) > 0 && $languages[0] !== '') {
foreach ($languages as $language) {

$this->execute(
"
UPDATE dmstr_page SET domain_id = REPLACE (domain_id, '_$language', '') WHERE domain_id LIKE '%_$language';
"
);
}
return true;
}
return false;
}

public function down()
{
return false;
}
}
Binary file modified migrations/workbench/dmstr_yii2-pages-module.mwb
Binary file not shown.
Loading

0 comments on commit 77c11c6

Please sign in to comment.