fitness-web/common/models/Log.php
2016-05-27 21:00:23 +02:00

132 lines
3.7 KiB
PHP

<?php
namespace common\models;
use Yii;
use yii\helpers\Url;
use yii\helpers\VarDumper;
use common\models\BaseFitnessActiveRecord;
use yii\helpers\Console;
/**
* This is the model class for table "log".
*
* @property integer $id_log
* @property integer $type
* @property string $message
* @property string $url
* @property string $app
* @property integer $id_user
* @property integer $id_transfer
* @property integer $id_money_movement
* @property integer $id_ticket
* @property integer $id_sale
* @property integer $id_customer
* @property integer $id_account
* @property integer $id_account_state
* @property integer $id_key
* @property integer $id_product
* @property integer $id_door_log
* @property string $created_at
* @property string $updated_at
*/
class Log extends BaseFitnessActiveRecord
{
public static $TYPE_INFO = 10;
public static $TYPE_ERR = 20;
public static $TYPE_TICKET_USAGE_FIRST = 30;
public static $TYPE_TICKET_USAGE_MULTIPLE = 40;
public static $TYPE_LOGIN = 50;
public static $TYPE_DEFAULT_ACCOUNT= 60;
public static $TYPE_CREATE_CUSTOMER= 70;
public static $TYPE_PROCUREMENT_UPDATE = 80;
public static $TYPE_TICKET_COUNT_MOVE_OUT = 90;
public static $TYPE_WASTE = 100;
public static $TYPE_NEWSLETTER_SUBSCRIBE = 110;
public static $TYPE_NEWSLETTER_UNSUBSCRIBE = 120;
public static $TYPE_NEWSLETTER_SENT = 130;
public static $TYPE_TICKET_EXPIRE_SENT = 140;
public static $TYPE_NEWSLETTER_SEND_START = 150;
public static $TYPE_NEWSLETTER_SEND_END = 160;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'log';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id_log' => Yii::t('common/log', 'Azonosító'),
'type' => Yii::t('common/log', 'Típus'),
'message' => Yii::t('common/log', 'Üzenet'),
'url' => Yii::t('common/log', 'Url'),
'app' => Yii::t('common/log', 'Alkalmazás'),
'id_user' => Yii::t('common/log', 'Felhasználó'),
'id_transfer' => Yii::t('common/log', 'Tranzakció'),
'id_money_movement' => Yii::t('common/log', 'Pénzmozgás'),
'id_ticket' => Yii::t('common/log', 'Bérlet'),
'id_sale' => Yii::t('common/log', 'Termékeladás'),
'id_customer' => Yii::t('common/log', 'Vendég'),
'id_account' => Yii::t('common/log', 'Kassza'),
'id_account_state' => Yii::t('common/log', 'Id Account State'),
'id_key' => Yii::t('common/log', 'Kulcs'),
'id_product' => Yii::t('common/log', 'Termék'),
'id_door_log' => Yii::t('common/log', 'Kapu log'),
'created_at' => Yii::t('common/log', 'Dátum idő'),
'updated_at' => Yii::t('common/log', 'Módosítás'),
'start' => 'Időszak kezdete',
'end' => 'Időszak vége'
];
}
public static function info($message ){
self::log(['type' =>self::$TYPE_INFO, 'message' => $message]);
}
/**
* example
* Log::log([
'type' =>Log::$TYPE_LOGIN,
'message' => $message
]);
* @param unknown $config
*/
public static function log( $config ){
$model = new Log($config);
$model->app = \Yii::$app->name;
$model->url = Url::canonical();
$model->id_user = \Yii::$app->user->id;
$model->save(false);
}
/**
* create a log from the console app
* */
public static function logC( $config ){
$model = new Log($config);
$model->app = "Fitness rendszer";
$model->url = "console";
$model->id_user = 1;
$model->save(false);
}
}