2017 © Pedro Peláez
 

yii2-extension yii2-numerator

Experemental extension that allows you to numerate whatever in your app

image

novikas/yii2-numerator

Experemental extension that allows you to numerate whatever in your app

  • Tuesday, February 16, 2016
  • by novikas
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Yii 2 Numerator extension

rapidly creating small projects., (*1)

The template contains the basic features including user login/logout and a contact page. It includes all commonly used configurations that would allow you to focus on adding new features to your application., (*2)

Latest Stable Version, (*3)

REQUIREMENTS

The minimum requirement by this extension that your Web server supports PHP 5.4.0., (*4)

INSTALLATION

Install via Composer

If you do not have Composer, you may install it by following the instructions at getcomposer.org., (*5)

You can then install this extension using the following command:, (*6)

php composer.phar require novikas/yii2-numerator: "@dev"

Database

First of all you need to execute migrations that is located in extensions directory:, (*7)

yii mirate --migrationsPath = @novikas/numerator/migrations

To create new simple numerator template, you need to call Numerator::createNumerator($config) just once. Argument config is an array:, (*8)

Numerator::createNumerator([
  'name' => 'doc_numerator1',
  'model_class' => 'common\models\Doc',
  'field' => 'number',
  'type_field' => 'type',
  'type_value' => 1,
  'mask' => '{УК-}999',
  'init_val' => 55
]);

If your models differs from each other by more than on field (property), you can use the following template:, (*9)

Numerator::createNumerator([
  'name' => 'doc_numerator2',
  'model_class' => 'common\models\Doc',
  'field' => 'number',
  'type_field' => 'type1&type2',
  'type_value' => "1&2",
  'mask' => '{UK-}999',
  'init_val' => 2
]);

So, according this template numerator will numerate your models by following condition, (*10)

WHERE type1 = 1 AND type2 = 2

NOTE Note that values of the properties Numerator::type_value and Numerator::type_field must corresponds., (*11)

If your models differs in properties of their relations, you can use the following template:, (*12)

Numerator::createNumerator([
  'name' => 'doc_numerator2',
  'model_class' => 'common\models\Doc',
  'field' => 'number',
  'type_field' => 'doc.type1&store.type2',
  'type_value' => "1&2",
  'mask' => '{UK-}999',
  'init_val' => 2,
  'join_table' => 'store',
  'join_on_condition' => 'doc.FK_store=store.id'
]);

NOTE Note that you need to set properties Numerator::join_table and Numerator::join_on_condition. Also it's recommended to add table prefix in property type_field to avoid ambiguity., (*13)

Fields description

  • name - unique template name.
  • model_class - Class of ActiveRecord model that need to be numerated.
  • field - field of model_class instance that contains number.
  • type_field - field of model_class instance that contains model type.
  • type_value - I suppose that is clear
  • mask - numerator's mask
  • init_val - initial value for number. Numeration will be proceed after this value.

Mask description

  • {} - text between curly brackets will display as it is.
  • 9 - means that this position is reserved as a number.
  • y - will be replaced with current year.
  • m - will be replaced with current month.
  • q - will be replaced with current quarter. NOTE
  • Current version of code allows only one block with curly brackets, only one sequence of symbol 9 (9999) and this sequence must be placed last.

Usage

After you created all templates for your models, you can use Numerator as the following code:, (*14)

$numerator = Numerator::getNumerator($templateName);
$doc->number = $numerator->nextNumber();

This code could be place in rules of models as a default value for number property for example., (*15)

The Versions

16/02 2016

dev-master

9999999-dev

Experemental extension that allows you to numerate whatever in your app

  Sources   Download

CC-0

The Requires

 

db numerator numeration