2017 © Pedro Peláez
 

yii-extension historizer

log your model's histories indepently from your model's table structure

image

albertborsos/historizer

log your model's histories indepently from your model's table structure

  • Monday, April 21, 2014
  • by albertborsos
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Yii Model Historizer

Simple extension to log your models change history. Independent from your models table structure, because it stores the attributes in one field in JSON format., (*1)

Installation steps

1.) Via composer:, (*2)

    "require":{
        "albertborsos/historizer": "dev-master",
    }

2.) Create the table for the histories by the initialize schema in datas folder, (*3)

3.) Then, add this line to your protected/config/main.php, (*4)

    'import' => array(
        'application.vendor.albertborsos.historizer',
    ),

How To Use

In your model's class modify the beforeSave() and beforeDelete() methods If the new attributes are different from the old one, it saves the old model's attributes automatically. If save happened the historize() methods return value is true, else false., (*5)

public function beforeSave(){
        if (parent::beforeSave()){
            if (!$this->isNewRecord){
               if (AHistorizer::historize($this)){
                   // if attributes are modified, update fields
                   $this->date_update = date('Y-m-d H:i:s');
                   $this->user_update = Yii::app()->user->id;
               }
            }else{
               $this->user_create = Yii::app()->user->id;
               $this->date_create = date('Y-m-d H:i:s');
            }
            return true;
        }else{
            return false;
        }
    }

    public function beforeDelete() {
        if (parent::beforeDelete()){
            AHistorizer::historize($this);
            return true;
        }else{
            return false;
        }
    }

The Versions

21/04 2014

dev-master

9999999-dev

log your model's histories indepently from your model's table structure

  Sources   Download

log yii activerecord historizer historize