OSDN Git Service

Document追加
[trpgtools-onweb/cake-frame.git] / app / models / character_profile_archive.php
1 <?php
2 class CharacterProfileArchive extends AppModel {
3
4         var $name = 'CharacterProfileArchive';
5
6         var $fields = array(
7                 'add' => array('character_id', 'value', 'title', 'memo', 'public_flag', 'disp_date'),
8                 'edit' => array('title', 'memo', 'public_flag', 'disp_date'),
9                 'escape' => array(
10                         'title' => array(
11                                 'html' => true,
12                                 'all' => true,
13                         ),
14                         'memo' => array(
15                                 'html' => true,
16                                 'images' => true,
17                                 'sctipts' => true,
18                         ),
19                 ),
20         );
21
22         var $validate = array(
23                 'title' => array(
24                         'maxLengthJP' => array(
25                                 'rule' => array('maxLengthJP', 64),
26                         ),
27                 ),
28                 'public_flag' => array(
29                         'publicFlag' => array(
30                                 'rule' => 'publicFlag',
31                         ),
32                 ),
33         );
34
35         //The Associations below have been created with all possible keys, those that are not needed can be removed
36         var $belongsTo = array(
37                 'Character' => array(
38                         'className' => 'Character',
39                         'foreignKey' => 'character_id',
40                         'conditions' => '',
41                         'fields' => array(
42                                 'Character.id',
43                                 'Character.user_id',
44                                 'Character.name',
45                                 'Character.public_flag',
46                         ),
47                         'order' => ''
48                 )
49         );
50
51         /* コールバックメソッド */
52         function afterFind($results, $primary = false) {
53                 if (empty($results)) {
54                         return $results;
55                 }
56
57                 foreach ($results as $key => $result) {
58                         /* valueのunsecape */
59                         if (isset($result[$this->alias]['value'])) {
60                                 $results[$key][$this->alias]['value'] = $this->restore_escape($result[$this->alias]['value']);
61                         }
62                 }
63
64                 return parent::afterFind($results, $primary);
65         }
66
67         function afterSave($created) {
68                 $this->deleteCache4ProfileArchive($this->data['clearCache']['character_id']);
69
70                 return parent::afterSave($created);
71         }
72         function afterDelete() {
73                 $this->deleteCache4ProfileArchive($this->data['clearCache']['character_id']);
74
75                 return parent::afterDelete($model);
76         }
77
78         /* キャッシュ削除 */
79         function deleteCache4ProfileArchive($character_id)
80         {
81                 // index, view
82                 $this->deleteCache4ProfileArchives($character_id);
83
84                 // キャラクターview
85                 $this->deleteCacheCharacterView($character_id, true);
86         }
87
88         function deleteCache4ProfileArchives($character_id)
89         {
90                 $Session = CorePlus::set_behavoir('Session');
91
92                 // index
93                 @unlink(CACHE.'views'.DS.'element_'.$character_id.'_character_profile_archive_index');
94                 @unlink(CACHE.'views'.DS.'element_'.$Session->id().'_'.$character_id.'_character_profile_archive_index');
95                 $this->cacheDelete();
96
97                 // view
98                 $this->deleteCache4views($this->id);
99         }
100         function deleteCache4views()
101         {
102                 if (!is_array($ids)) {
103                         $ids = (array)$ids;
104                 }
105
106                 if (!empty($ids)) {
107                         $Session = CorePlus::set_behavoir('Session');
108
109                         foreach ($ids as $id) {
110                                 @unlink(CACHE.'views'.DS.'element_'.$id.'_character_profile_archive_view');
111                                 @unlink(CACHE.'views'.DS.'element_'.$Session->id().'_'.$id.'_character_profile_archive_view');
112                         }
113                 }
114         }
115 }
116