OSDN Git Service

Profile種類の選択肢追加
[trpgtools-onweb/cake-frame.git] / app / models / profile.php
1 <?php
2 class Profile extends AppModel {
3
4         var $name = 'Profile';
5
6         var $profile_type = array(
7                 'input',
8                 'textarea',
9                 'select',
10                 'checkbox',
11                 'm-input',
12                 'm-select',
13                 'table'
14         );
15
16         var $fields = array(
17                 'id' => array(
18                         'auto' => true,
19                 ),
20                 'system_id' => array(
21                         'auto' => true,
22                 ),
23                 'name' => array(
24                         'auto' => false,
25                         'add' => true,
26                         'edit' => true,
27                         'escape' => array(
28                                 'html' => true,
29                                 'all' => true,
30                         ),
31                 ),
32                 'key_name' => array(
33                         'auto' => false,
34                         'add' => true,
35                         'edit' => true,
36                 ),
37                 'profile_type' => array(
38                         'auto' => false,
39                         'add' => true,
40                         'edit' => true,
41                 ),
42                 'required' => array(
43                         'auto' => false,
44                         'add' => true,
45                         'edit' => true,
46                 ),
47                 'editable' => array(
48                         'auto' => false,
49                         'add' => true,
50                         'edit' => true,
51                 ),
52                 'public_flag_default' => array(
53                         'auto' => false,
54                         'add' => true,
55                         'edit' => true,
56                 ),
57                 'sort_order' => array(
58                         'auto' => false,
59                         'add' => true,
60                         'edit' => true,
61                 ),
62         );
63
64         var $validate = array(
65                 'name' => array(
66                         'maxLengthJP' => array(
67                                 'rule' => array('maxLengthJP', 255),
68                         ),
69                         'notEmpty' => array(
70                                 'rule' => 'notEmpty',
71                         ),
72                 ),
73                 'key_name' => array(
74                         'keyName' => array(
75                                 'rule' => 'keyName',
76                         ),
77                         'maxLengthJP' => array(
78                                 'rule' => array('maxLengthJP', 64),
79                         ),
80                         'notEmpty' => array(
81                                 'rule' => 'notEmpty',
82                         ),
83                 ),
84                 'profile_type' => array(
85                         'profileType' => array(
86                                 'rule' => 'profileType',
87                         ),
88                 ),
89                 'required' => array(
90                         'boolean' => array(
91                                 'rule' => 'boolean',
92                         ),
93                 ),
94                 'editable' => array(
95                         'boolean' => array(
96                                 'rule' => 'boolean',
97                         ),
98                 ),
99                 'public_flag_default' => array(
100                         'publicFlag' => array(
101                                 'rule' => 'publicFlagDefault',
102                         ),
103                 ),
104                 'sort_order' => array(
105                         'numeric' => array(
106                                 'rule' => array('numeric'),
107                                 'allowEmpty' => true,
108                         ),
109                 ),
110         );
111
112         //The Associations below have been created with all possible keys, those that are not needed can be removed
113         var $belongsTo = array(
114                 'System' => array(
115                         'className' => 'System',
116                         'foreignKey' => 'system_id',
117                         'conditions' => '',
118                         'fields' => array('id', 'name'),
119                         'order' => ''
120                 )
121         );
122
123         var $hasMany = array(
124                 'ProfileSelect' => array(
125                         'className' => 'ProfileSelect',
126                         'foreignKey' => 'profile_id',
127                         'dependent' => true,
128                         'conditions' => '',
129                         'fields' => '',
130                         'order' => array('ProfileSelect.sort_order' => 'asc'),
131                         'limit' => '',
132                         'offset' => '',
133                         'exclusive' => '',
134                         'finderQuery' => '',
135                         'counterQuery' => ''
136                 ),
137                 'ProfileTable' => array(
138                         'className' => 'ProfileTable',
139                         'foreignKey' => 'profile_id',
140                         'dependent' => true,
141                         'conditions' => '',
142                         'fields' => '',
143                         'order' => array('ProfileTable.sort_order' => 'asc'),
144                         'limit' => '',
145                         'offset' => '',
146                         'exclusive' => '',
147                         'finderQuery' => '',
148                         'counterQuery' => ''
149                 ),
150                 'CharactersHasProfiles' => array(
151                         'className' => 'CharactersHasProfiles',
152                         'foreignKey' => 'profile_id',
153                         'associationForeignKey' => 'id',
154                         'dependent' => true,
155                         'conditions' => '',
156                         'fields' => array('id', 'value', 'public_flag'),
157                         'order' => '',
158                         'limit' => 10,
159                         'offset' => '',
160                         'finderQuery' => '',
161                         'deleteQuery' => '',
162                         'insertQuery' => ''
163                 )
164         );
165
166         /* validation Rule */
167
168         /* 同システム中に同じkey_nameは不可 */
169         function isUniqueKeyname4system($data, $system_id, $id = null) 
170         {
171                 $params = array(
172                         'conditions' => array(
173                                 'Profile.system_id' => $system_id,
174                                 'Profile.key_name' => $data['key_name'],
175                         ),
176                         'recursive' => -1,
177                 );
178
179                 if($id) {
180                         $params['conditions']['Profile.id !='] = $id;
181                 }
182
183                 return !($this->find('count', $params));
184         }
185
186         /* プロフィールの入力型 */
187         function profileType($data) 
188         {
189                 if (isset($data['profile_type']) && in_array($data['profile_type'], $this->profile_type)) {
190                         return true;
191                 } else {
192                         return false;
193                 }
194         }
195
196         function publicFlagDefault($data) 
197         {
198                 if (isset($data["public_flag_default"]) && in_array($data["public_flag_default"], $this->public_flag)) {
199                         return true;
200                 } else {
201                         return false;
202                 }
203         }
204
205 }
206 ?>