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 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.