OSDN Git Service

Document追加
[trpgtools-onweb/cake-frame.git] / app / models / system.php
1 <?php
2 class System extends AppModel {
3
4         var $name = 'System';
5
6         var $fields = array(
7                 'add' => array('name', 'sort_order', 'url', 'copyright', 'set_npc', 'public_flag', 'detail'),
8                 'edit' => array('name', 'sort_order', 'url', 'copyright', 'set_npc', 'public_flag', 'detail'),
9                 'image' => array(
10                         'user_id',
11                         'model',
12                         'foreign_key',
13                         'dirname',
14                         'basename',
15                         'checksum',
16                         'size',
17                         'group',
18                         'alternative',
19                         'file',
20                 ),
21                 'escape' => array(
22                         'name' => array(
23                                 'html' => true,
24                                 'all' => true,
25                         ),
26                         'copyright' => array(
27                                 'html' => true,
28                                 'images' => true,
29                                 'sctipts' => true,
30                         ),
31                         'detail' => array(
32                                 'html' => true,
33                                 'images' => true,
34                                 'sctipts' => true,
35                         ),
36                 ),
37         );
38
39         var $validate = array(
40                 'name' => array(
41                         'notEmpty' => array(
42                                 'rule' => array('notEmpty'),
43                         ),
44                 ),
45                 'sort_order' => array(
46                         'numeric' => array(
47                                 'rule' => array('numeric'),
48                                 'allowEmpty' => true,
49                         ),
50                 ),
51                 'url' => array(
52                         'url' => array(
53                                 'rule' => array('url', true),
54                                 'allowEmpty' => true,
55                         ),
56                 ),
57                 'set_npc' => array(
58                         'boolean' => array(
59                                 'rule' => array('boolean'),
60                         ),
61                 ),
62                 'public_flag' => array(
63                         'publicFlag' => array(
64                                 'rule' => array('publicFlag'),
65                         ),
66                 ),
67         );
68
69         //The Associations below have been created with all possible keys, those that are not needed can be removed
70         var $hasMany = array(
71                 'Character' => array(
72                         'className' => 'Character',
73                         'foreignKey' => 'system_id',
74                         'dependent' => false,
75                         'conditions' => array(
76                                 'Character.public_flag' => 'public',
77                                 'Character.deleted' => '0',
78                         ),
79                         'fields' => array(
80                                 'Character.id',
81                                 'Character.system_id',
82                                 'Character.user_id',
83                                 'Character.name',
84                                 'Character.main_picture',
85                                 'Character.public_flag',
86                                 'Character.status',
87                                 'Character.modified',
88                         ),
89                         'order' => 'Character.modified DESC',
90                         'limit' => '5',
91                 ),
92                 'CharacterSheet' => array(
93                         'className' => 'CharacterSheet',
94                         'foreignKey' => 'system_id',
95                         'dependent' => false,
96                         'conditions' => array(
97                                 'CharacterSheet.public_flag' => 'public'
98                         ),
99                         'fields' => array(
100                                 'CharacterSheet.id',
101                                 'CharacterSheet.key_name',
102                                 'CharacterSheet.name',
103                         ),
104                         'order' => array(
105                                 'CharacterSheet.sort_order' => 'ASC'
106                         ),
107                         'limit' => '',
108                 ),
109                 'Profile' => array(
110                         'className' => 'Profile',
111                         'foreignKey' => 'system_id',
112                         'dependent' => true,
113                         'fields' => array(
114                                 'Profile.id',
115                                 'Profile.name',
116                                 'Profile.key_name',
117                                 'Profile.profile_type',
118                                 'Profile.sort_order',
119                         ),
120 //                      'order' => 'Profile.sort_order ASC',
121                 ),
122                 // システムイメージ
123                 'Attachment' => array(
124                         'className' => 'Media.AttachmentEx',
125                         'foreignKey' => 'foreign_key',
126                         'dependent' => true,
127                         'conditions' => array('Attachment.model' => 'System'),
128                         'fields' => array(
129                                 'Attachment.id',
130                                 'Attachment.user_id',
131                                 'Attachment.foreign_key',
132                                 'Attachment.dirname',
133                                 'Attachment.basename',
134                                 'Attachment.alternative',
135                                 'Attachment.size',
136                                 'Attachment.created',
137                         ),
138                         'order' => '',
139                         'limit' => '',
140                         'offset' => '',
141                         'finderQuery' => '',
142                         'deleteQuery' => '',
143                         'insertQuery' => ''
144                 )
145         );
146
147         /* コールバックメソッド */
148         function beforeSave($options = array())
149         {
150                 if (empty($this->data['System']['sort_order'])) {
151                         $this->data['System']['sort_order'] = 0;
152                 }
153
154                 return parent::beforeSave($options);
155         }
156
157         function beforeDelete($cascade = true) {
158                 $this->data['System']['isAdmin'] = true;
159
160                 return parent::beforeDelete($cascade);
161         }
162 }
163