README.md 3.05 KB
Newer Older
Marcello Pivanti's avatar
Marcello Pivanti committed
1
2
3
4
5
6
7
8
9
10
11
12
#Amos Tag

Extension for tags and interest areas.

Installation
------------

1. The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```bash
Aster's avatar
Aster committed
13
composer require arter/amos-tag
Marcello Pivanti's avatar
Marcello Pivanti committed
14
15
16
17
18
```

or add this row

```
Aster's avatar
Aster committed
19
"arter/amos-tag": "dev-master"
Marcello Pivanti's avatar
Marcello Pivanti committed
20
21
22
23
24
25
26
27
28
29
```

to the require section of your `composer.json` file.

2. Add module to your main config in backend:
	
    ```php
    
    'modules' => [
        'tag' => [
Aster's avatar
Aster committed
30
            'class' => 'arter\amos\tag\AmosTag',
Marcello Pivanti's avatar
Marcello Pivanti committed
31
32
33
            'modelsEnabled' => [
                /**
                 * Add here the classnames of the models for whose you want to enable tags
Aster's avatar
Aster committed
34
                 * (i.e. 'arter\amos\news\models\News')
Marcello Pivanti's avatar
Marcello Pivanti committed
35
36
37
38
39
40
41
42
43
44
45
46
47
                 */
            ]
        ],
    ],
    ```

3. To enable user-profile interest areas (tags to match with content tags), amos-cwh installation is needed
 

4. Apply migrations

    a. amos-tag migrations
    ```bash
Aster's avatar
Aster committed
48
    php yii migrate/up --migrationPath=@vendor/arter/amos-tag/src/migrations
Marcello Pivanti's avatar
Marcello Pivanti committed
49
50
51
52
53
54
55
56
57
    ```
    
    or add this row to your migrations config in console:
    
    ```php
    return [
        .
        .
        .
Aster's avatar
Aster committed
58
        '@vendor/arter/amos-tag/src/migrations',
Marcello Pivanti's avatar
Marcello Pivanti committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        .
        .
        .
    ];
    ```
    
Configuration
------------

Tag management is available for admin role - url PlatformUrl **/tag/manager**.
In tag manager it is possible to:
 - To add new trees or tags
 - enable tag trees (by root selection) for specific models - to all roles (rbac) or to the specified ones
 - change tree settings eg. root visible will allow the user to select all tags by root in TagWidget (see below) 

Widgets
-----------

Amos Tag provides two Widgets:
Aster's avatar
Aster committed
78
* **TagWidget** *arter\amos\tag\widgets\TagWidget*  
Marcello Pivanti's avatar
Marcello Pivanti committed
79
80
81
Draws tag tree to select values for a model.
example of use in a form:
```php
Aster's avatar
Aster committed
82
    echo arter\amos\tag\widgets\TagWidget::widget([
Marcello Pivanti's avatar
Marcello Pivanti committed
83
84
85
86
87
88
89
90
91
92
93
94
        'model' => $model,
        'attribute' => 'tagValues',
        'form' => \yii\base\Widget::$stack[0],
        'singleFixedTreeId' => $treeRoot,
        'id' => 'third-tree',
        'hideHeader' => true
    ]);
```

In a search form you can use the same widget with options :
```php
$params = \Yii::$app->request->getQueryParams();
Aster's avatar
Aster committed
95
echo \arter\amos\tag\widgets\TagWidget::widget([
Marcello Pivanti's avatar
Marcello Pivanti committed
96
97
98
99
100
101
102
103
104
105
106
    'model' => $model,
    'attribute' => 'tagValues',
    'form' => $form,
    'isSearch' => true,
    'form_values' => isset($params[$model->formName()]['tagValues']) ? $params[$model->formName()]['tagValues'] : []
]);
```

If singleFixedTreeId is not specified, all enabled trees for the $model are considered (table tag_models_auth_items_mm).
singleFixedTreeId is now possible an array (tag roots in singleFixedTreeId will be considered).

Aster's avatar
Aster committed
107
* **ShowTagsWidget** *arter\amos\tag\widgets\ShowTagsWidget*  
Marcello Pivanti's avatar
Marcello Pivanti committed
108
109
110
111
112
Draws the selected tags for a model (in view mode).
It is possible to specify a tree (property 'rootId') or a set of trees (property 'rootIdsArray') to show; if nothing is specified, all enabled trees for the model are considered. 
Example: 

```
Aster's avatar
Aster committed
113
 <?= \arter\amos\tag\widgets\ShowTagsWidget::widget([
Marcello Pivanti's avatar
Marcello Pivanti committed
114
115
116
117
118
    'model' => $model,
    'rootId' => $rootId
 ]) ?>
 ```