Application::__new()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
namespace samsoncms\app\user;
3
4
use samson\activerecord\user;
5
6
/**
7
 * Class Application
8
 * @package samson\cms\web\user
9
 */
10
class Application extends \samsoncms\Application
11
{
12
    /** @var string Application name */
13
    public $name = 'Пользователь';
14
15
    /** Application description */
16
    public $description = 'Пользователи системы';
17
18
    /** @var string Application icon */
19
    public $icon = 'user';
20
21
    /** @var string Module identifier */
22
    protected $id = 'user';
23
24
    /** @var string Module identifier */
25
    protected $entity = '\samson\activerecord\user';
26
27
    /** @var string Form class */
28
    protected $formClassName = '\samsoncms\app\user\form\Form';
29
30
    /** Module initialization */
31
    public function init(array $params = array())
32
    {
33
        // Subscribe to input change event
34
        \samsonphp\event\Event::subscribe('samson.cms.input.change', array($this, 'inputUpdateHandler'));
35
    }
36
37
    /**
38
     * New entity creation generic controller action
39
     * @param int $parentID Parent identifier
40
     */
41
    public function __new($parentID = null)
42
    {
43
        /** @var user $entity */
44
        $entity = new $this->entity();
45
46
        // Persist
47
        $entity->group_id = 1;
48
        $entity->active = 1;
49
        $entity->confirmed = 1;
50
        $entity->save();
51
52
        // Go to correct form URL
53
        url()->redirect($this->system->module('cms')->baseUrl.'/'.$this->id . '/form/' . $entity->id);
54
    }
55
56
    /**
57
     * Input field saving handler
58
     * @param \samsonframework\orm\Record $object
59
     * @param string $param Field
60
     * @param string $previousValue Previous object field value
61
     * @param string $response Response
62
     */
63
    public function inputUpdateHandler(& $object, $param, $previousValue, $response = null)
0 ignored issues
show
Unused Code introduced by
The parameter $previousValue is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
    {
65
        // Work only when event fired for User database record
66
        if ($object instanceof \samson\activerecord\user) {
0 ignored issues
show
Bug introduced by
The class samson\activerecord\user does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
67
            $social = $this->system->module('socialemail');
68
            $object->md5_email  = $param == 'email' ? md5($object->email) : $object->md5_email;
69
            $object->hash_email = $param == 'email' ? $social->hash($object->email) : $object->hash_email;
70
71
            $object->md5_password  = $param == 'hash_password' ? md5($object->hash_password) : $object->md5_password;
72
            $object->hash_password = $param == 'hash_password' ? $social->hash($object->hash_password) : $object->hash_password;
73
74
            // Refresh session user object on any field change
75
            /*$auth_user_id = unserialize($_SESSION[m('socialemail')->identifier()]);
76
            if ($auth_user_id['user_id'] == $object['user_id']) {
77
                m('socialemail')->update($object);
78
            }*/
79
        }
80
    }
81
    
82
    /**
83
     * User entity delete controller action
84
     * @param int $identifier Entity identifier
85
     * @return array Asynchronous response array
86
     */
87
    public function __async_remove2($identifier)
0 ignored issues
show
Coding Style introduced by
Method name "Application::__async_remove2" is not in camel caps format
Loading history...
88
    {
89
        if (!dbQuery('material')->cond('UserID', $identifier)->cond('Active', 1)->first()) {
0 ignored issues
show
Deprecated Code introduced by
The method samson\activerecord\dbQuery::cond() has been deprecated with message: @see self::where()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
90
            return parent::__async_remove2($identifier);
91
        }
92
        else {
93
            return array('status' => 1, 'error_message' => t('Пока у этого пользователя есть материалы, его удаление невозможно.', true));
0 ignored issues
show
Deprecated Code introduced by
The function t() has been deprecated with message: Should be used as $this->system->getContainer()->geti18n()->translate()|plural()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
94
        }
95
    }
96
}
97