OSDN Git Service

Document追加
[trpgtools-onweb/cake-frame.git] / app / models / user.php
1 <?php
2 class User extends AppModel {
3
4         var $name = 'User';
5         var $belongsTo = array('Group');
6
7         //The Associations below have been created with all possible keys, those that are not needed can be removed
8         var $hasMany = array(
9                 // ユーザ画像
10                 'Attachment' => array(
11                         'className' => 'Media.AttachmentEx',
12                         'foreignKey' => 'foreign_key',
13                         'dependent' => true,
14                         'conditions' => array('Attachment.model' => 'User'),
15                         'fields' => array(
16                                 'Attachment.id',
17                                 'Attachment.user_id',
18                                 'Attachment.foreign_key',
19                                 'Attachment.dirname',
20                                 'Attachment.basename',
21                                 'Attachment.alternative',
22                                 'Attachment.size',
23                                 'Attachment.created',
24                         ),
25                         'order' => '',
26                         'limit' => '',
27                         'offset' => '',
28                 ),
29                 'Character' => array(
30                         'className' => 'Character',
31                         'foreignKey' => 'user_id',
32                         'dependent' => false,
33                         'conditions' => array(
34                                 'Character.public_flag' => 'public',
35                                 'Character.deleted' => '0',
36                         ),
37                         'fields' => array(
38                                 'Character.id',
39                                 'Character.system_id',
40                                 'Character.user_id',
41                                 'Character.name',
42                                 'Character.main_picture',
43                                 'Character.public_flag',
44                                 'Character.status',
45                                 'Character.modified',
46                         ),
47                         'order' => array(
48                                 'Character.modified' => 'DESC',
49                         ),
50                         'limit' => '5',
51                         'offset' => '',
52                 )
53         );
54
55         var $fields = array(
56                 'add' => array('group_id', 'name', 'username', 'password', 'useragent', 'host'),
57                 'edit' => array('name', 'url', 'notes'),
58                 'escape' => array(
59                         'name' => array(
60                                 'html' => true,
61                                 'all' => true,
62                         ),
63                         'url' => array(
64                                 'url' => array(
65                                         'rule' => array('url', true),
66                                         'allowEmpty' => true,
67                                 ),
68                         ),
69                         'notes' => array(
70                                 'html' => true,
71                                 'images' => true,
72                                 'sctipts' => true,
73                         ),
74                 ),
75                 // other 'mobile_mail'
76         );
77
78         var $validate = array(
79                 'name' => array(
80                         'maxLengthJP' => array(
81                                 'rule' => array('maxLengthJP', 64),
82                         ),
83                         'notEmpty' => array(
84                                 'rule' => 'notEmpty',
85                         ),
86                 ),
87                 'username' => array(
88                         'isUnique' => array(
89                                 'rule' => array('isUnique'),
90                         ),
91                         'betweenWrapper' => array(
92                                 'rule' => array('betweenUsername'),
93                         ),
94                         'alphaNumeric' => array(
95                                 'rule' => 'alphaNumeric',
96                         ),
97                         'notEmpty' => array(
98                                 'rule' => 'notEmpty',
99                         ),
100                 ),
101                 'password1' => array(
102                         'betweenWrapper' => array(
103                                 'rule' => array('betweenPassword'),
104                         ),
105                         'alphaNumeric' => array(
106                                 'rule' => 'alphaNumeric',
107                         ),
108                         'notEmpty' => array(
109                                 'rule' => 'notEmpty',
110                         ),
111                 ),
112                 'password2' => array(
113                         'compare2fields' => array(
114                                 'rule' => array('compare2fields', 'password1', false),
115                         ),
116                         'alphaNumeric' => array(
117                                 'rule' => 'alphaNumeric',
118                         ),
119                         'notEmpty' => array(
120                                 'rule' => 'notEmpty',
121                         ),
122                 ),
123                 'pcmail' => array(
124                         'isUniquePcMail' => array(
125                                 'rule' => array('isUniquePcMail'),
126                         ),
127                         'isPcMail' => array(
128                                 'rule' => array('isPcMail'),
129                         ),
130                 ),
131 /*              'mobile_mail' => array(
132                         'isUnique' => array(
133                                 'rule' => array('isUnique'),
134                         ),
135                 ),*/
136         );
137
138         /* コールバックメソッド */
139         function beforeValidate($options = array())
140         {
141
142                 return parent::beforeValidate($options);
143
144         }
145         function beforeSave($options = array())
146         {
147                 $result = parent::beforeSave($options);
148                 if ($result === false) {
149                         return $result;
150                 }
151
152                 // textarea
153                 if (!empty($this->data['User']['notes'])) {
154                         $this->data['User']['notes'] = str_replace(array("\n\r", '\n', "\r"), '<br />', $this->data['User']['notes']);
155                 }
156
157                 return $result;
158         }
159         function afterSave($created) {
160                 $this->deleteCache4User();
161
162                 return parent::afterSave($created);
163         }
164         function afterDelete() {
165                 $this->deleteCache4User();
166
167                 return parent::afterDelete();
168         }
169
170
171         /* validation */
172         function betweenUsername($data)
173         {
174                 $idLength = Configure::read('User.UserId.Length');
175                 return self::betweenWrapper($data, $idLength);
176         }
177
178         function betweenPassword($data)
179         {
180                 $idLength = Configure::read('User.Password.Length');
181                 return self::betweenWrapper($data, $idLength);
182         }
183
184         function betweenWrapper($data, $idLength)
185         {
186                 $check = array_values($data);
187
188                 return parent::betweenWrapper($check[0], $idLength['min'], $idLength['max']);
189         }
190
191         /* キャッシュ削除 */
192         function deleteCache4User()
193         {
194                 // 自セッション関連
195                 $this->deleteCacheMyData();
196
197                 $this->deleteCacheHome();
198                 $this->deleteCacheUser($this->id);
199         }
200
201
202 }