OSDN Git Service

バージョン記載追加
[trpgtools-onweb/cake-frame.git] / app / models / character_picture.php
1 <?php
2 /**
3  * PHP version 5
4  *
5  * @category Model
6  * @package  Chara-Shee!
7  * @version  beta
8  * @author   Cake <cake_67@users.sourceforge.jp>
9  * @license  http://www.opensource.org/licenses/mit-license.php The MIT License
10  * @link     http://trpgtools-onweb.sourceforge.jp/
11  */
12 class CharacterPicture extends AppModel {
13
14         var $name = 'CharacterPicture';
15
16         var $fields = array(
17                 'add' => array('user_id', 'character_id', 'public_flag'),
18                 'edit' => array('public_flag'),
19                 'image' => array(
20                         'user_id',
21                         'model',
22                         'foreign_key',
23                         'dirname',
24                         'basename',
25                         'checksum',
26                         'size',
27                         'group',
28                         'alternative',
29                         'file',
30                 ),
31                 'escape' => array(
32                 ),
33         );
34
35         var $validate = array(
36                 'public_flag' => array(
37                         'publicFlag' => array(
38                                 'rule' => 'publicFlag',
39                                 'allowEmpty' => true,
40                         ),
41                 ),
42         );
43
44         //The Associations below have been created with all possible keys, those that are not needed can be removed
45         var $belongsTo = array(
46                 'User' => array(
47                         'className' => 'User',
48                         'foreignKey' => 'user_id',
49                         'conditions' => '',
50                         'fields' => '',
51                         'order' => ''
52                 ),
53                 'Character' => array(
54                         'className' => 'Character',
55                         'foreignKey' => 'character_id',
56                         'conditions' => '',
57                         'fields' => array(
58                                 'Character.id',
59                                 'Character.name',
60                                 'Character.public_flag',
61                                 'Character.main_picture',
62                                 'Character.full_length',
63                         ),
64                         'order' => ''
65                 )
66         );
67
68         var $hasMany = array(
69                 'Attachment' => array(
70                         'className' => 'Media.AttachmentEx',
71                         'foreignKey' => 'foreign_key',
72                         'dependent' => true,
73                         'conditions' => array('Attachment.model' => 'CharacterPicture'),
74                         'fields' => array(
75                                 'Attachment.id',
76                                 'Attachment.user_id',
77                                 'Attachment.foreign_key',
78                                 'Attachment.dirname',
79                                 'Attachment.basename',
80                                 'Attachment.alternative',
81                                 'Attachment.size',
82                                 'Attachment.created',
83                         ),
84                         'order' => '',
85                         'limit' => '',
86                         'offset' => '',
87                         'exclusive' => '',
88                         'finderQuery' => '',
89                         'counterQuery' => ''
90                 )
91         );
92
93         /* コールバックメソッド */
94         function beforeSave($options = array())
95         {
96                 // 登録者ID
97                 $this->data['CharacterPicture']['user_id'] = $_SESSION['Auth']['User']['id'];
98
99                 return parent::beforeSave($options);
100         }
101         function afterSave($created) {
102                 $this->deleteCache4CharacterPicture($this->data['clearCache']['character_id']);
103                 $this->deleteCacheCharacterView($this->data['clearCache']['character_id'], true);
104
105                 return parent::afterSave($created);
106         }
107         function afterDelete() {
108                 $this->deleteCache4CharacterPicture($this->data['clearCache']['character_id']);
109
110                 $this->Character->deleteCache4Charcter();
111
112                 return parent::afterDelete($model);
113         }
114 }