PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/baser/plugins/blog/controllers/blog_tags_controller.php

https://github.com/hashing/basercms
PHP | 238 lines | 110 code | 26 blank | 102 comment | 16 complexity | ce533f82896d3b89e7a0d2bde6dda202 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * ブログタグコントローラー
  5. *
  6. * PHP versions 5
  7. *
  8. * baserCMS : Based Website Development Project <http://basercms.net>
  9. * Copyright 2008 - 2012, baserCMS Users Community <http://sites.google.com/site/baserusers/>
  10. *
  11. * @copyright Copyright 2008 - 2012, baserCMS Users Community
  12. * @link http://basercms.net baserCMS Project
  13. * @package baser.plugins.blog.controllers
  14. * @since baserCMS v 0.1.0
  15. * @version $Revision$
  16. * @modifiedby $LastChangedBy$
  17. * @lastmodified $Date$
  18. * @license http://basercms.net/license/index.html
  19. */
  20. /**
  21. * Include files
  22. */
  23. /**
  24. * ブログタグコントローラー
  25. *
  26. * @package baser.plugins.blog.controllers
  27. */
  28. class BlogTagsController extends BlogAppController {
  29. /**
  30. * クラス名
  31. *
  32. * @var array
  33. * @access public
  34. */
  35. var $name = 'BlogTags';
  36. /**
  37. * モデル
  38. *
  39. * @var array
  40. * @access public
  41. */
  42. var $uses = array('Blog.BlogCategory', 'Blog.BlogTag');
  43. /**
  44. * コンポーネント
  45. *
  46. * @var array
  47. * @access public
  48. */
  49. var $components = array('BcAuth','Cookie','BcAuthConfigure');
  50. /**
  51. * ぱんくずナビ
  52. *
  53. * @var string
  54. * @access public
  55. */
  56. var $crumbs = array(
  57. array('name' => 'プラグイン管理', 'url' => array('plugin' => '', 'controller' => 'plugins', 'action' => 'index')),
  58. array('name' => 'ブログ管理', 'url' => array('controller' => 'blog_contents', 'action' => 'index'))
  59. );
  60. /**
  61. * サブメニューエレメント
  62. *
  63. * @var array
  64. * @access public
  65. */
  66. var $subMenuElements = array('blog_common');
  67. /**
  68. * [ADMIN] タグ一覧
  69. *
  70. * @return void
  71. * @access public
  72. */
  73. function admin_index () {
  74. $default = array('named' => array('num' => $this->siteConfigs['admin_list_num']));
  75. $this->setViewConditions('BlogTag', array('default' => $default));
  76. $this->paginate = array(
  77. 'order' => 'BlogTag.id',
  78. 'limit' => $this->passedArgs['num']
  79. );
  80. $this->set('datas', $this->paginate('BlogTag'));
  81. $this->pageTitle = 'ブログタグ一覧';
  82. }
  83. /**
  84. * [ADMIN] タグ登録
  85. *
  86. * @return void
  87. * @access public
  88. */
  89. function admin_add () {
  90. if(!empty($this->data)) {
  91. $this->BlogTag->create($this->data);
  92. if($this->BlogTag->save()) {
  93. $message = 'タグ「'.$this->data['BlogTag']['name'].'」を追加しました。';
  94. $this->Session->setFlash($message);
  95. $this->BlogTag->saveDbLog($message);
  96. $this->redirect(array('action' => 'index'));
  97. }else {
  98. $this->Session->setFlash('エラーが発生しました。内容を確認してください。');
  99. }
  100. }
  101. $this->pageTitle = '新規ブログタグ登録';
  102. $this->render('form');
  103. }
  104. /**
  105. * [ADMIN] タグ編集
  106. *
  107. * @param int $id タグID
  108. * @return void
  109. * @access public
  110. */
  111. function admin_edit ($id) {
  112. if(!$id) {
  113. $this->Session->setFlash('無効な処理です。');
  114. $this->redirect(array('action' => 'index'));
  115. }
  116. if(empty($this->data)) {
  117. $this->data = $this->BlogTag->read(null, $id);
  118. } else {
  119. $this->BlogTag->set($this->data);
  120. if($this->BlogTag->save()) {
  121. $message = 'タグ「'.$this->data['BlogTag']['name'].'」を更新しました。';
  122. $this->Session->setFlash($message);
  123. $this->BlogTag->saveDbLog($message);
  124. $this->redirect(array('action' => 'index'));
  125. }else {
  126. $this->Session->setFlash('エラーが発生しました。内容を確認してください。');
  127. }
  128. }
  129. $this->pageTitle = 'ブログタグ編集: '.$this->data['BlogTag']['name'];
  130. $this->render('form');
  131. }
  132. /**
  133. * [ADMIN] 削除処理
  134. *
  135. * @param int $id
  136. * @return void
  137. * @access public
  138. */
  139. function admin_delete($id = null) {
  140. if(!$id) {
  141. $this->Session->setFlash('無効な処理です。');
  142. $this->redirect(array('action' => 'index'));
  143. }
  144. $data = $this->BlogTag->read(null, $id);
  145. if($this->BlogTag->del($id)) {
  146. $message = 'タグ「' . $this->BlogTag->data['BlogTag']['name'] . '」を削除しました。';
  147. $this->Session->setFlash($message);
  148. $this->BlogTag->saveDbLog($message);
  149. }else {
  150. $this->Session->setFlash('データベース処理中にエラーが発生しました。');
  151. }
  152. $this->redirect(array('action' => 'index'));
  153. }
  154. /**
  155. * [ADMIN] 削除処理 (ajax)
  156. *
  157. * @param int $id
  158. * @return void
  159. * @access public
  160. */
  161. function admin_ajax_delete($id = null) {
  162. if(!$id) {
  163. $this->ajaxError(500, '無効な処理です。');
  164. }
  165. $data = $this->BlogTag->read(null, $id);
  166. if($this->BlogTag->del($id)) {
  167. $message = 'タグ「' . $this->BlogTag->data['BlogTag']['name'] . '」を削除しました。';
  168. $this->BlogTag->saveDbLog($message);
  169. exit(true);
  170. }
  171. exit();
  172. }
  173. /**
  174. * [ADMIN] 一括削除
  175. *
  176. * @param int $id
  177. * @return void
  178. * @access public
  179. */
  180. function _batch_del($ids) {
  181. if($ids) {
  182. foreach($ids as $id) {
  183. $data = $this->BlogTag->read(null, $id);
  184. if($this->BlogTag->del($id)) {
  185. $message = 'タグ「' . $this->BlogTag->data['BlogTag']['name'] . '」を削除しました。';
  186. $this->BlogTag->saveDbLog($message);
  187. }
  188. }
  189. }
  190. return true;
  191. }
  192. /**
  193. * [ADMIN] AJAXタグ登録
  194. *
  195. * @return void
  196. * @access public
  197. */
  198. function admin_ajax_add () {
  199. if(!empty($this->data)) {
  200. $this->BlogTag->create($this->data);
  201. if($data = $this->BlogTag->save()) {
  202. $result = array($this->BlogTag->id => $data['BlogTag']['name']);
  203. $this->set('result', $result);
  204. } else {
  205. $this->ajaxError(500, $this->BlogTag->validationErrors);
  206. }
  207. } else {
  208. $this->ajaxError(500, '無効な処理です。');
  209. }
  210. }
  211. }
  212. ?>