`system_id` INTEGER UNSIGNED,
`user_id` INTEGER UNSIGNED NOT NULL,
`name` TEXT NOT NULL,
+ `main_picture` VARCHAR(255) NULL,
+ `full_length` VARCHAR(255) NULL,
`notes` TEXT NOT NULL,
`public_flag` ENUM('public','private') NOT NULL DEFAULT 'public',
`status` ENUM('active', 'npc', 'inactive') NOT NULL DEFAULT 'active',
`user_id` INTEGER UNSIGNED NOT NULL,
`character_id` INTEGER UNSIGNED NOT NULL,
`public_flag` ENUM('public','private') NOT NULL DEFAULT 'public',
- `main_picture` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
- `full_length` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
`created` DATETIME NULL,
`modified` DATETIME NULL,
PRIMARY KEY(`id`),
return $user;
}
+ function _get_character4character_id($character_id, $user_id = null, $public_flag = null, $is_deleted = 0)
+ {
+ $conditions = array(
+ 'Character.id' => $character_id,
+ 'Character.deleted' => $is_deleted,
+ );
+ if ($user_id) {
+ $conditions['Character.user_id'] = $user_id;
+ }
+ if ($public_flag) {
+ $conditions['Character.public_flag'] = $public_flag;
+ }
+ if (!isset($this->Character)) {
+ $this->Character = CorePlus::set_model('Character');
+ }
+ $character = $this->Character->find('first', array(
+ 'conditions' => $conditions,
+ 'contain' => array(
+ 'CharacterPicture' => array(
+ 'Attachment',
+ ),
+ ),
+ 'recursive' => 2,
+ ));
+ if (empty($character)) {
+ $this->Session->setFlash(__('Invalid Character.', true));
+ $this->redirect(array('controller' => 'characters', 'action'=>'index'));
+ }
+ return $character;
+ }
+
}
/* ACL */
// 追加アクション用 crudMap
var $actionMapPlus = array(
- 'set_status' => 'update',
);
var $disableTokenActions = array();
var $post_data = array();
- var $_default_character_picture = array(
- 'id' => null,
- 'user_id' => null,
- 'character_id' => null,
- 'public_flag' => null,
- 'main_picture' => null,
- 'full_length' => null,
- 'created' => null,
- 'modified' => null,
- 'actions' => null,
- );
-
/* メソッド */
function beforeFilter() {
),
'recursive' => -1,
));
-
if (empty($character)) {
$this->Session->setFlash(__('Invalid Character.', true));
$this->redirect(array('controller' => 'characters', 'action'=>'index'));
'fields' => array(
'CharacterPicture.id',
'CharacterPicture.public_flag',
- 'CharacterPicture.main_picture',
- 'CharacterPicture.full_length',
'CharacterPicture.created',
),
'contain' => array(
'recursive' => 1,
'order' => array('CharacterPicture.id' => 'asc'),
));
+ if ($isOwner) {
+ $character_pictures = $this->_set_image_config($character_pictures, $character['Character']);
+ }
$this->set('characterPictures', $character_pictures);
}
$this->set(compact('users','characters'));
}
- function set_status($character_id = null) {
- if (!$character_id || !isset($this->params['named']['mode'])) {
- $this->Session->setFlash(__('Invalid URL.', true));
- $this->redirect(array('controller' => 'characters', 'action'=>'index'));
- }
- $character = $this->_get_character4character_id($character_id, $this->user_id);
-
- if (!isset($this->params['named']['mode']) || ($this->params['named']['mode'] != 'main_picture' && 'main_picture' || $this->params['named']['mode'] != 'full_length')) {
- } else {
- $this->Session->setFlash(__('Invalid URL.', true));
- $this->redirect(array('controller' => 'character_pictures', 'action'=>'index', $character_id));
- }
-
- // 新設定チェック
- if (isset($this->params['named']['new_picture_id']) && $this->params['named']['new_picture_id'] != 'null') {
- $new_character_picture = $this->__get_character4character_picture_id($this->params['named']['new_picture_id'], $this->user_id);
-
- }
-
- // 現在の設定削除
- $fields = array('CharacterPicture.'.$this->params['named']['mode'] => 0);
- $conditions = array(
- 'CharacterPicture.character_id' => $character_id,
- 'CharacterPicture.'.$this->params['named']['mode'] => 1,
- );
- $this->CharacterPicture->updateAll(
- $fields,
- $conditions
- );
- // 新設定
- $fields = array('CharacterPicture.'.$this->params['named']['mode'] => 1);
- $conditions = array('CharacterPicture.id' => $this->params['named']['new_picture_id']);
- $this->CharacterPicture->updateAll(
- $fields,
- $conditions
- );
-
- $this->redirect(array('action'=>'index', $character_id));
- }
-
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for CharacterPicture', true));
}
- function _get_character4character_id($character_id, $user_id = null, $public_flag = null, $is_deleted = 0)
- {
- $conditions = array(
- 'Character.id' => $character_id,
- 'Character.deleted' => $is_deleted,
- );
- if ($user_id) {
- $conditions['Character.user_id'] = $user_id;
- }
- if ($public_flag) {
- $conditions['Character.public_flag'] = $public_flag;
- }
- $character = $this->CharacterPicture->Character->find('first', array(
- 'conditions' => $conditions,
- 'contain' => array(
- 'CharacterPicture' => array(
- 'Attachment',
- ),
- ),
- 'recursive' => 1,
- ));
- if (empty($character)) {
- $this->Session->setFlash(__('Invalid Character.', true));
- $this->redirect(array('controller' => 'characters', 'action'=>'index'));
- }
- return $character;
- }
-
function __get_character4character_picture_id($character_picture_id, $user_id = null, $public_flag = null)
{
$conditions = array(
return $characterPicture;
}
+ function _set_image_config($character_pictures, $character)
+ {
+ if (!empty($character) && !empty($character_pictures)) {
+ foreach ($character_pictures as $k => $v) {
+ if (!empty($character['main_picture']) && $v['Attachment'][0]['basename'] == $character['main_picture'] && $v['CharacterPicture']['public_flag'] == 'public') {
+ $character_pictures[$k]['CharacterPicture']['main_picture'] = true;
+ } else {
+ $character_pictures[$k]['CharacterPicture']['main_picture'] = false;
+ }
+
+ if (!empty($character['full_length']) && $v['Attachment'][0]['basename'] == $character['full_length'] && $v['CharacterPicture']['public_flag'] == 'public') {
+ $character_pictures[$k]['CharacterPicture']['full_length'] = true;
+ } else {
+ $character_pictures[$k]['CharacterPicture']['full_length'] = false;
+ }
+ }
+ }
+
+ return $character_pictures;
+ }
+
}
?>
\ No newline at end of file
// 追加アクション用 crudMap
var $actionMapPlus = array(
'add_milti_profiles' => 'update',
+ 'set_status' => 'update',
);
var $disableTokenActions = array();
}
+ function set_status($id = null) {
+ if (!$id || !isset($this->params['named']['mode'])) {
+ $this->Session->setFlash(__('Invalid ID.', true));
+ $this->redirect(array('controller' => 'characters', 'action'=>'index'));
+ }
+
+ $character = $this->_get_character4character_id($id, $this->user_id, 'public');
+
+ if ($this->params['named']['mode'] != 'main_picture' && $this->params['named']['mode'] != 'full_length') {
+ $this->Session->setFlash(__('Invalid URL.', true));
+ $this->redirect(array('controller' => 'character_pictures', 'action'=>'index', $id));
+ }
+
+ // 新picture設定
+ $new_character_picture = null;
+ if (isset($this->params['named']['new_picture_id']) && $this->params['named']['new_picture_id'] != 'null') {
+ if ($character['CharacterPicture']) {
+ foreach($character['CharacterPicture'] as $k => $v) {
+ if ($v['id'] == $this->params['named']['new_picture_id']) {
+ $new_character_picture = CorePlus::get_value($v, 'Attachment.0.basename');
+ break;
+ }
+ }
+ }
+ if (!$new_character_picture) {
+ $this->Session->setFlash(__('Invalid data.', true));
+ $this->redirect(array('controller' => 'character_pictures', 'action'=>'index', $id));
+ }
+ }
+
+ // 設定変更
+ $this->Character->id = $id;
+ $this->data['Character'][$this->params['named']['mode']] = $new_character_picture;
+ var_dump($this->data);
+ $this->Character->save(
+ $this->data,
+ array(
+ 'fieldList' => array(
+ $this->params['named']['mode']
+ ),
+ )
+ );
+
+ $this->Session->setFlash(__('CharacterPicture Configuration has been saved.', true));
+ $this->redirect(array('controller' => 'character_pictures', 'action' => 'index', $id));
+ }
+
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Character', true));
if (empty($orig_character['Character'])) {
return $orig_character;
}
- $orig_character['Character']['image_filename'] = null;
- $orig_character['Character']['full_length'] = null;
if (!empty($orig_character['System']['Profile'])) {
$new_profile = array();
'rule' => 'notEmpty',
),
),
- 'image_filename' => array(
- 'url' => array(
- 'rule' => 'url',
- 'allowEmpty' => true,
- ),
- ),
'system_id' => array(
'validSystemId' => array(
'rule' => array('validSystemId', true),
'fields' => array(
'CharacterPicture.id',
'CharacterPicture.public_flag',
- 'CharacterPicture.main_picture',
- 'CharacterPicture.full_length',
'CharacterPicture.created',
),
'order' => array('CharacterPicture.id' => 'asc'),
'allowEmpty' => true,
),
),
- 'main_picture' => array(
- 'boolean' => array(
- 'rule' => array('boolean'),
- ),
- ),
- 'full_length' => array(
- 'boolean' => array(
- 'rule' => array('boolean'),
- ),
- )
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
echo $select->create_publicflag_select($public_flags, 'public_flag', array(
'label' => __('Public Flag', true)
));
- echo $form->input('main_picture');
- echo $form->input('full_length');
echo $token->create();
?>
<th><?php echo $paginator->sort('user_id');?></th>
<th><?php echo $paginator->sort('character_id');?></th>
<th><?php echo $paginator->sort('public_flag');?></th>
- <th><?php echo $paginator->sort('main_picture');?></th>
- <th><?php echo $paginator->sort('full_length');?></th>
<th><?php echo $paginator->sort('created');?></th>
<th><?php echo $paginator->sort('modified');?></th>
<th class="actions"><?php __('Actions');?></th>
<?php echo $characterPicture['CharacterPicture']['public_flag']; ?>
</td>
<td>
- <?php echo $characterPicture['CharacterPicture']['main_picture']; ?>
- </td>
- <td>
- <?php echo $characterPicture['CharacterPicture']['full_length']; ?>
- </td>
- <td>
<?php echo $characterPicture['CharacterPicture']['created']; ?>
</td>
<td>
<?php echo $characterPicture['CharacterPicture']['public_flag']; ?>
</dd>
- <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Main Picture'); ?></dt>
- <dd<?php if ($i++ % 2 == 0) echo $class;?>>
- <?php echo $characterPicture['CharacterPicture']['main_picture']; ?>
-
- </dd>
- <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Full Length'); ?></dt>
- <dd<?php if ($i++ % 2 == 0) echo $class;?>>
- <?php echo $characterPicture['CharacterPicture']['full_length']; ?>
-
- </dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Created'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $characterPicture['CharacterPicture']['created']; ?>
echo $form->input('user_id');
echo $form->input('character_id');
echo $form->input('public_flag');
- echo $form->input('main_picture');
- echo $form->input('full_length');
?>
</fieldset>
<?php echo $form->end('Submit');?>
$html->link(
__('Delete Main Picture', true),
array(
+ 'controller' => 'characters',
'action' => 'set_status',
$character['Character']['id'],
'mode:main_picture',
$html->link(
__('Set Main Picture', true),
array(
+ 'controller' => 'characters',
'action' => 'set_status',
$character['Character']['id'],
'mode:main_picture',
$html->link(
__('Delete Background Picture', true),
array(
+ 'controller' => 'characters',
'action' => 'set_status',
$character['Character']['id'],
'mode:full_length',
$html->link(
__('Set Background Picture', true),
array(
+ 'controller' => 'characters',
'action' => 'set_status',
$character['Character']['id'],
'mode:full_length',
<?php echo $characterPicture['CharacterPicture']['public_flag']; ?>
</dd>
- <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Main Picture'); ?></dt>
- <dd<?php if ($i++ % 2 == 0) echo $class;?>>
- <?php echo $characterPicture['CharacterPicture']['main_picture']; ?>
-
- </dd>
- <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Full Length'); ?></dt>
- <dd<?php if ($i++ % 2 == 0) echo $class;?>>
- <?php echo $characterPicture['CharacterPicture']['full_length']; ?>
-
- </dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Created'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $characterPicture['CharacterPicture']['created']; ?>