PHPackages                             neam/yii-qa-state - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. neam/yii-qa-state

ActiveYii-extension[Localization &amp; i18n](/categories/localization)

neam/yii-qa-state
=================

Transparent attribute translation for ActiveRecords, without requiring lookup tables for translated field contents.

1650PHP

Since Oct 12Pushed 11y ago4 watchersCompare

[ Source](https://github.com/neam/yii-qa-state)[ Packagist](https://packagist.org/packages/neam/yii-qa-state)[ RSS](/packages/neam-yii-qa-state/feed)WikiDiscussions develop Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Yii Extension: QaState
======================

[](#yii-extension-qastate)

Tools (a behavior and a console command) to track and store validation progress as well as proofreading and approval progress on a field-by-field basis. Created for content management systems to aid tracking completion progress of publishing workflows such as creation, draft, review, approval, proofreading, translation etc.

Features
--------

[](#features)

- Automatically sets the current item status (such as Temporary, Draft, Reviewable and Publishable) based on validation rules
- Supplies a convenient place to store the current overall status as well as approval and proofreading flags for attributes that are part of the content creation process
- Methods to calculate and read the current validation, approval and proofreading progress
- Stores the current progress of any validation scenarios, so that content items can be listed/filtered based on how close/far to completion they are
- Leverages Yii validation logic as the fundamental method of validating the fields
- Leverages Gii code generation to provide CRUD operations to set and change flags
- Console command automatically creates migrations for the necessary database changes
- (Optional) Leverages Yii extension [i18n-columns](http://www.yiiframework.com/extension/i18n-columns/) to provide individual quality assurance states for each translation language

Requirements
------------

[](#requirements)

- Yii 1.1 or above
- Use of Yii console
- Use of Gii (preferably [Gtc](https://github.com/schmunk42/gii-template-collection/)) and/or [giic](http://www.yiiframework.com/extension/giic/)
- MySQL 5.1.10+, SQL Server 2012 or similarly recent database (For the console command. The behavior itself works with any Yii-supported database)

Setup
-----

[](#setup)

### Download and install

[](#download-and-install)

Ensure that you have the following in your composer.json:

```
"repositories":[
    {
        "type": "vcs",
        "url": "https://github.com/neam/yii-qa-state"
    },
    ...
],
"require":{
    "neam/yii-qa-state":"dev-develop",
    ...
},

```

Then install through composer:

```
php composer.php update neam/yii-qa-state

```

If you don't use composer, clone or download this project into /path/to/your/app/vendor/neam/yii-qa-state

### Add Alias to both main.php and console.php

[](#add-alias-to-both-mainphp-and-consolephp)

```
'aliases' => array(
    ...
    'vendor'  => dirname(__FILE__) . '/../../vendor',
    'qa-state' => 'vendor.neam.yii-qa-state',
    ...
),

```

### Import the behavior in main.php

[](#import-the-behavior-in-mainphp)

```
'import' => array(
    ...
    'qa-state.behaviors.QaStateBehavior',
    ...
),

```

### Reference the qa-state command in console.php

[](#reference-the-qa-state-command-in-consolephp)

```
'commandMap' => array(
    ...
    'qa-state'    => array(
        'class' => 'qa-state.commands.QaStateCommand',
    ),
    ...
),

```

### Configure models to be part of the qa process

[](#configure-models-to-be-part-of-the-qa-process)

#### 1. Set up validation rules in your model, stating what fields are required for draft, reviewable and publishable scenarios.

[](#1-set-up-validation-rules-in-your-model-stating-what-fields-are-required-for-draft-reviewable-and-publishable-scenarios)

Example:

```
// Chapter.php

class Chapter extends BaseChapter
{
    ...
    public function rules()
    {
        return array_merge(
            parent::rules(), array(
                array('title, slug', 'required', 'on' => 'draft,reviewable,publishable'),
                array('thumbnail, about, video, teachers_guide, exercises, snapshots, credits', 'required', 'on' => 'publishable'),
            )
        );
    }
    ...
}

```

This example only uses the validation rule "required", but of course any validation rules can be used. The attributes can be ordinary model attributes, relations or virtual attributes that use custom validation rules etc. The important part is that they are applied on the scenarios that the behavior is configured to use (default: draft,reviewable,publishable).

#### 2. Add the behavior to the models that you want to track qa state and progress of

[](#2-add-the-behavior-to-the-models-that-you-want-to-track-qa-state-and-progress-of)

```
public function behaviors()
{
    return array(
        'qa-state' => array(
             'class' => 'QaStateBehavior',
             'scenarios' => array(
                   'draft',
                   'reviewable',
                   'publishable',
                   /* Example: tracking translation progress through language-specific validation scenarios - add the scenarios through configuration:
                   'translate_into_es',
                   'translate_into_de',
                   'translate_into_fr',
                   'translate_into_sv',
                   */
             ),
             'manualFlags' => array(
                   'allow_review',
                   'allow_publish'
             ),
        ),
    );
}

```

#### 3. Generate the necessary schema migration using the included console command:

[](#3-generate-the-necessary-schema-migration-using-the-included-console-command)

`./yiic qa-state process`

Run with `--verbose` to see more details.

#### 4. Apply the generated migration:

[](#4-apply-the-generated-migration)

`./yiic migrate`

This will add the relevant tables, relations and fields to be able to track the qa state of the configured models.

The schema has this general structure:

```
{table}_qa_state
    id
    foreach scenario: {scenario}_validation_progress
    approval_progress
    proofing_progress
    foreach manualFlag: {manualFlag}
    foreach attribute: {attribute}_approved - boolean (with null)
    foreach attribute: {attribute}_proofed - boolean (with null)
    created
    modified

```

Each progress field are integers between 0 and 100, reflecting percentage of total progress. Total progress is measured as all attributes under validation either validates, are approved, proofread or translated respectively.

Sample migration file:

```
