OSDN Git Service

Document追加
[trpgtools-onweb/cake-frame.git] / app / controllers / characters_has_profiles_controller.php
1 <?php
2 class CharactersHasProfilesController extends AppController {
3
4         var $name = 'CharactersHasProfiles';
5         var $helpers = array(
6         );
7
8         var $disableTokenActions = array();
9
10
11         /* メソッド */
12
13         /* アクションメソッド */
14
15         function delete($profile_id = null) {
16                 if (!$profile_id) {
17                         $this->Session->setFlash(__('Invalid URL.', true));
18                         $this->redirect(array('controller' => 'characters', 'action'=>'index'));
19                 }
20
21                 $character = $this->CharactersHasProfile->Character->find('first', array(
22                         'conditions' => array(
23                                 'Character.id' => $this->params['named']['character_id'],
24                         ),
25                         'fields' => array(
26                                 'Character.id',
27                                 'Character.user_id',
28                                 'Character.name',
29                         ),
30                         'recursive' => -1,
31                 ));
32
33                 if (empty($character)) {
34                         $this->Session->setFlash(__('No Character', true));
35                         $this->redirect(array('controller'=>'characters', 'action'=>'index'));
36                 }
37
38                 if (!$this->isOwner($character['Character'], $this->user_id)) {
39                         $this->Session->setFlash(__('No Permission', true));
40                         $this->redirect(array('controller'=>'characters', 'action'=>'index'));
41                 }
42
43                 $this->CharactersHasProfile->deleteAll(
44                          array(
45                                 'CharactersHasProfile.profile_id' => $profile_id,
46                                 'CharactersHasProfile.character_id' => $this->params['named']['character_id'],
47                         ),
48                         false
49                 );
50
51                 $this->Session->setFlash(__('Profile deleted', true));
52                 $this->redirect(array('controller'=>'characters', 'action'=>'view',$this->params['named']['character_id'] ));
53         }
54
55 }