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) |
64
|
|
|
{ |
65
|
|
|
// Work only when event fired for User database record |
66
|
|
|
if ($object instanceof \samson\activerecord\user) { |
|
|
|
|
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) |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
if (!dbQuery('material')->cond('UserID', $identifier)->cond('Active', 1)->first()) { |
|
|
|
|
90
|
|
|
return parent::__async_remove2($identifier); |
91
|
|
|
} |
92
|
|
|
else { |
93
|
|
|
return array('status' => 1, 'error_message' => t('Пока у этого пользователя есть материалы, его удаление невозможно.', true)); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
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 thecomposer.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
orrequire-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 you have not tested against this specific condition, such errors might go unnoticed.