|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* _ __ __ _____ _____ ___ ____ _____ |
|
5
|
|
|
* | | / // // ___//_ _// || __||_ _| |
|
6
|
|
|
* | |/ // /(__ ) / / / /| || | | | |
|
7
|
|
|
* |___//_//____/ /_/ /_/ |_||_| |_| |
|
8
|
|
|
* @link https://vistart.me/ |
|
9
|
|
|
* @copyright Copyright (c) 2016 - 2017 vistart |
|
10
|
|
|
* @license https://vistart.me/license/ |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace rhosocial\user; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Simple Profile Model. |
|
17
|
|
|
* One Profile corresponds to only one [[User]]. |
|
18
|
|
|
* |
|
19
|
|
|
* If you're using MySQL, we recommend that you create a data table using the following statement: |
|
20
|
|
|
* ``` |
|
21
|
|
|
* CREATE TABLE `profile` ( |
|
22
|
|
|
* `guid` varbinary(16) NOT NULL COMMENT 'User GUID', |
|
23
|
|
|
* `nickname` varchar(255) NOT NULL COMMENT 'Nickname', |
|
24
|
|
|
* `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Email', |
|
25
|
|
|
* `phone` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Phone', |
|
26
|
|
|
* `first_name` varchar(255) NOT NULL COMMENT 'First Name', |
|
27
|
|
|
* `last_name` varchar(255) NOT NULL COMMENT 'Last Name', |
|
28
|
|
|
* `individual_sign` text NOT NULL COMMENT 'Individual Sign', |
|
29
|
|
|
* `created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Create Time', |
|
30
|
|
|
* `updated_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00' COMMENT 'Update Time', |
|
31
|
|
|
* PRIMARY KEY (`guid`), |
|
32
|
|
|
* CONSTRAINT `user_profile_fkey` FOREIGN KEY (`guid`) REFERENCES `user` (`guid`) ON DELETE CASCADE ON UPDATE CASCADE |
|
33
|
|
|
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Profile'; |
|
34
|
|
|
* ``` |
|
35
|
|
|
* |
|
36
|
|
|
* The extra fields of SimpleProfile table in database are following: |
|
37
|
|
|
* @property string $email |
|
38
|
|
|
* @property string $phone |
|
39
|
|
|
* |
|
40
|
|
|
* @version 1.0 |
|
41
|
|
|
* @author vistart <[email protected]> |
|
42
|
|
|
*/ |
|
43
|
|
|
class SimpleProfile extends Profile |
|
44
|
|
|
{ |
|
45
|
|
|
/** |
|
46
|
|
|
* Get rules associated with email attribute. |
|
47
|
|
|
* You can override this method if current rules do not satisfy your needs. |
|
48
|
|
|
* If you do not use email attribute, please override this method and return empty array. |
|
49
|
|
|
* @return array Rules associated with email. |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getEmailRules() |
|
52
|
|
|
{ |
|
53
|
|
|
return [ |
|
54
|
|
|
['email', 'email', 'skipOnEmpty' => true], |
|
55
|
|
|
['email', 'default', 'value' => ''], |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get rules associated with phone attribute. |
|
61
|
|
|
* You can override this method if current rules do not satisfy your needs. |
|
62
|
|
|
* If you do not use phone attribute, please override this method and return empty array. |
|
63
|
|
|
* @return array Rules associated with phone. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getPhoneRules() |
|
66
|
|
|
{ |
|
67
|
|
|
return [ |
|
68
|
|
|
['phone', 'string', 'max' => 255, 'skipOnEmpty' => true], |
|
69
|
|
|
['phone', 'default', 'value' => ''], |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @inheritdoc |
|
75
|
|
|
*/ |
|
76
|
|
|
public function rules() |
|
77
|
|
|
{ |
|
78
|
|
|
return array_merge($this->getEmailRules(), $this->getPhoneRules(), parent::rules()); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|