Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tecnocen-com/yii2-rmdb
Browse files Browse the repository at this point in the history
  • Loading branch information
Faryshta committed Oct 23, 2017
2 parents b1d5795 + 3ba292a commit 58ccf65
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,32 @@ class m170101_000001_sale extends \tecnocen\rmdb\migrations\CreateEntity
}
```

### RMDB Module

This library uses a custom module to help configure all the extended models
in an unified way.

configure it in your `common\config\main.php` in `yii-app-advanced` and
`common\config.php` in `yii-app-basic`.

```php
use tecnoceno\rmdb\Module as RmdbModule;

return [
// ...
'modules' => [
'rmdb' => [
'class' => RmdbModule::class,
'timestampClass' => ..., // optional
'blameableClass' => ..., // optional
'softDeleteClass' => ..., // optional
'timestampValue' => time(), // optional by default uses `now()`
'defaultUserId' => 5, // optional
],
],
];
```

### Models

Like the migrations there are 3 classes for models.
Expand Down
8 changes: 4 additions & 4 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class Module extends \yii\base\Module
public $timestampValue;

/**
* @var mixed id of the active user.
* @var mixed value to be used when the user id can't be determined.
*/
public $userId;
public $defaultUserId = 1;

/**
* @var mixed value to be used when the user id can't be determined.
* @var mixed id of the active user.
*/
public $defaultUserId;
private $userId;

/**
* @inheritdoc
Expand Down
4 changes: 2 additions & 2 deletions src/models/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ protected function attributeTypecast()
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['blameable']['updateByAttribute']
$behaviors['blameable']['updatedByAttribute']
= $this->updatedByAttribute;
$behaviors['timestamp']['updateAtAttribute']
$behaviors['timestamp']['updatedAtAttribute']
= $this->updatedAtAttribute;

return $behaviors;
Expand Down
2 changes: 1 addition & 1 deletion src/models/Pivot.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function behaviors()
],
'timestamp' => [
'class' => $module->timestampClass,
'createdAtAttribute' => $this->createdByAttribute,
'createdAtAttribute' => $this->createdAtAttribute,
'updatedAtAttribute' => null,
'value' => $module->timestampValue,
],
Expand Down

0 comments on commit 58ccf65

Please sign in to comment.