UserLog.class.php 1.95 KB
Newer Older
Игорь's avatar
init    
Игорь committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

/**
 * UserLog
 * 
 * This class has been auto-generated by the Doctrine ORM Framework
 * 
 * @package    sf
 * @subpackage model
 * @author     Atma
 * @version    SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
 */
class UserLog extends PluginUserLog
{
    static public $log_types = array('create' => 'Добавление', 'update' => 'Изменение', 'delete' => 'Удаление', 'return' => 'Восстановление',);

    static public function saveObject($record)
    {
        if (count($record['object']->getModified(true, true)) > 0) {
            self::logObject($record['object'], 'update');
        }
    }

    static public function deleteObject($record)
    {
        self::logObject($record['object'], 'delete');
    }

    static public function logObject($object, $log_type)
    {
        if (get_class($object) != 'UserLog') {
            $user_id = -1;
            if (strpos($_SERVER['PHP_SELF'], './symfony') === false) {
                $context = sfContext::getInstance();
                if ($context->getUser() && $context->getUser()->getUserId()) {
                    $user_id = $context->getUser()->getUserId();
                }
            }
            $user_log = new UserLog();
            $user_log->setUserId($user_id);
            if ($object->isNew()) {
                $log_type = 'create';
            }

            $user_log->setLogType($log_type);
            $user_log->setModel(get_class($object));
            $user_log->setModelId($object->getPrimaryKey());
            $user_log->setLog(serialize($object));
            $user_log->save();


            if (in_array(get_class($object), array('Course', 'ProfessionCourse', 'DivisionCourse', 'Protocol', 'Bid'))) {
                ProjectUtils::cubeRecreate();
            }
        }
    }

    public function getModule()
    {
        return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), '\\1_\\2', $this->getModel()));
    }
}