PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/baser/plugins/blog/controllers/blog_categories_controller.php

https://github.com/hashing/basercms
PHP | 339 lines | 161 code | 37 blank | 141 comment | 26 complexity | 528ec97e4cd51d2ea4c9733bbe48e727 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 BlogCategoriesController extends BlogAppController {
  29. /**
  30. * クラス名
  31. *
  32. * @var string
  33. * @access public
  34. */
  35. var $name = 'BlogCategories';
  36. /**
  37. * モデル
  38. *
  39. * @var array
  40. * @access public
  41. */
  42. var $uses = array('Blog.BlogCategory','Blog.BlogContent');
  43. /**
  44. * ヘルパー
  45. *
  46. * @var array
  47. * @access public
  48. */
  49. var $helpers = array(BC_TEXT_HELPER, BC_TIME_HELPER, BC_FORM_HELPER, 'Blog.Blog');
  50. /**
  51. * コンポーネント
  52. *
  53. * @var array
  54. * @access public
  55. */
  56. var $components = array('BcAuth','Cookie','BcAuthConfigure');
  57. /**
  58. * ぱんくずナビ
  59. *
  60. * @var string
  61. * @access public
  62. */
  63. var $crumbs = array(
  64. array('name' => 'プラグイン管理', 'url' => array('plugin' => '', 'controller' => 'plugins', 'action' => 'index')),
  65. array('name' => 'ブログ管理', 'url' => array('controller' => 'blog_contents', 'action' => 'index'))
  66. );
  67. /**
  68. * サブメニューエレメント
  69. *
  70. * @var array
  71. * @access public
  72. */
  73. var $subMenuElements = array();
  74. /**
  75. * beforeFilter
  76. *
  77. * @return void
  78. * @access public
  79. */
  80. function beforeFilter() {
  81. parent::beforeFilter();
  82. $this->BlogContent->recursive = -1;
  83. $this->blogContent = $this->BlogContent->read(null,$this->params['pass'][0]);
  84. $this->crumbs[] = array('name' => $this->blogContent['BlogContent']['title'].'管理', 'url' => array('controller' => 'blog_posts', 'action' => 'index', $this->params['pass'][0]));
  85. if($this->params['prefix'] == 'admin') {
  86. $this->subMenuElements = array('blog_posts', 'blog_categories', 'blog_common');
  87. }
  88. // バリデーション設定
  89. $this->BlogCategory->validationParams['blogContentId'] = $this->blogContent['BlogContent']['id'];
  90. }
  91. /**
  92. * beforeRender
  93. *
  94. * @return void
  95. * @access public
  96. */
  97. function beforeRender() {
  98. parent::beforeRender();
  99. $this->set('blogContent',$this->blogContent);
  100. }
  101. /**
  102. * [ADMIN] ブログを一覧表示する
  103. *
  104. * @return void
  105. * @access public
  106. */
  107. function admin_index($blogContentId) {
  108. $conditions = array('BlogCategory.blog_content_id'=>$blogContentId);
  109. $_dbDatas = $this->BlogCategory->generatetreelist($conditions);
  110. $dbDatas = array();
  111. foreach($_dbDatas as $key => $dbData) {
  112. $category = $this->BlogCategory->find(array('BlogCategory.id'=>$key));
  113. if(preg_match("/^([_]+)/i",$dbData,$matches)) {
  114. $prefix = str_replace('_','&nbsp&nbsp&nbsp',$matches[1]);
  115. $category['BlogCategory']['title'] = $prefix.'└'.$category['BlogCategory']['title'];
  116. }
  117. $dbDatas[] = $category;
  118. }
  119. /* 表示設定 */
  120. $this->set('owners', $this->BlogCategory->getControlSource('owner_id'));
  121. $this->set('dbDatas',$dbDatas);
  122. $this->pageTitle = '['.$this->blogContent['BlogContent']['title'].'] ブログカテゴリ一覧';
  123. $this->help = 'blog_categories_index';
  124. }
  125. /**
  126. * [ADMIN] 登録処理
  127. *
  128. * @param string $blogContentId
  129. * @return void
  130. * @access public
  131. */
  132. function admin_add($blogContentId) {
  133. if(!$blogContentId) {
  134. $this->Session->setFlash('無効なIDです。');
  135. $this->redirect(array('controller' => 'blog_contents', 'action' => 'index'));
  136. }
  137. if(empty($this->data)) {
  138. $this->data = $this->BlogCategory->getDefaultValue();
  139. }else {
  140. /* 登録処理 */
  141. $this->data['BlogCategory']['blog_content_id'] = $blogContentId;
  142. $this->data['BlogCategory']['no'] = $this->BlogCategory->getMax('no',array('BlogCategory.blog_content_id'=>$blogContentId))+1;
  143. $this->BlogCategory->create($this->data);
  144. // データを保存
  145. if($this->BlogCategory->save()) {
  146. $this->Session->setFlash('カテゴリー「'.$this->data['BlogCategory']['name'].'」を追加しました。');
  147. $this->BlogCategory->saveDbLog('カテゴリー「'.$this->data['BlogCategory']['name'].'」を追加しました。');
  148. $this->redirect(array('action' => 'index', $blogContentId));
  149. }else {
  150. $this->Session->setFlash('入力エラーです。内容を修正してください。');
  151. }
  152. }
  153. /* 表示設定 */
  154. $user = $this->BcAuth->user();
  155. $userModel = $this->getUserModel();
  156. $catOptions = array('blogContentId' => $this->blogContent['BlogContent']['id']);
  157. if($user[$userModel]['user_group_id'] != 1) {
  158. $catOptions['ownerId'] = $user[$userModel]['user_group_id'];
  159. }
  160. $parents = $this->BlogCategory->getControlSource('parent_id', $catOptions);
  161. if($this->checkRootEditable()) {
  162. if($parents) {
  163. $parents = array('' => '指定しない') + $parents;
  164. } else {
  165. $parents = array('' => '指定しない');
  166. }
  167. }
  168. $this->set('parents', $parents);
  169. $this->pageTitle = '['.$this->blogContent['BlogContent']['title'].'] 新規ブログカテゴリ登録';
  170. $this->help = 'blog_categories_form';
  171. $this->render('form');
  172. }
  173. /**
  174. * [ADMIN] 編集処理
  175. *
  176. * @param int $blogContentId
  177. * @param int $id
  178. * @return void
  179. * @access public
  180. */
  181. function admin_edit($blogContentId,$id) {
  182. /* 除外処理 */
  183. if(!$id && empty($this->data)) {
  184. $this->Session->setFlash('無効なIDです。');
  185. $this->redirect(array('action' => 'index'));
  186. }
  187. if(empty($this->data)) {
  188. $this->data = $this->BlogCategory->read(null, $id);
  189. }else {
  190. /* 更新処理 */
  191. if($this->BlogCategory->save($this->data)) {
  192. $this->Session->setFlash('カテゴリー「'.$this->data['BlogCategory']['name'].'」を更新しました。');
  193. $this->BlogCategory->saveDbLog('カテゴリー「'.$this->data['BlogCategory']['name'].'」を更新しました。');
  194. $this->redirect(array('action' => 'index', $blogContentId));
  195. }else {
  196. $this->Session->setFlash('入力エラーです。内容を修正してください。');
  197. }
  198. }
  199. /* 表示設定 */
  200. $user = $this->BcAuth->user();
  201. $userModel = $this->getUserModel();
  202. $catOptions = array(
  203. 'blogContentId' => $this->blogContent['BlogContent']['id'],
  204. 'excludeParentId' => $this->data['BlogCategory']['id']
  205. );
  206. if($user[$userModel]['user_group_id'] != 1) {
  207. $catOptions['ownerId'] = $user[$userModel]['user_group_id'];
  208. }
  209. $parents = $this->BlogCategory->getControlSource('parent_id', $catOptions);
  210. if($this->checkRootEditable()) {
  211. if($parents) {
  212. $parents = array('' => '指定しない') + $parents;
  213. } else {
  214. $parents = array('' => '指定しない');
  215. }
  216. }
  217. $this->set('parents', $parents);
  218. $this->pageTitle = '['.$this->blogContent['BlogContent']['title'].'] ブログカテゴリ編集';
  219. $this->help = 'blog_categories_form';
  220. $this->render('form');
  221. }
  222. /**
  223. * [ADMIN] 一括削除
  224. *
  225. * @param int $blogContentId
  226. * @param int $id
  227. * @return void
  228. * @access public
  229. */
  230. function _batch_del($ids) {
  231. if($ids) {
  232. foreach($ids as $id) {
  233. $this->_del($id);
  234. }
  235. }
  236. return true;
  237. }
  238. /**
  239. * [ADMIN] 削除処理 (ajax)
  240. *
  241. * @param int $blogContentId
  242. * @param int $id
  243. * @return void
  244. * @access public
  245. */
  246. function admin_ajax_delete($blogContentId, $id = null) {
  247. /* 除外処理 */
  248. if(!$id) {
  249. $this->ajaxError(500, '無効な処理です。');
  250. }
  251. if($this->_del($id)){
  252. exit(true);
  253. }else{
  254. exit();
  255. }
  256. }
  257. /**
  258. * 削除処理
  259. *
  260. * @param int $blogContentId
  261. * @param int $id
  262. * @return void
  263. * @access public
  264. */
  265. function _del($id = null) {
  266. // メッセージ用にデータを取得
  267. $data = $this->BlogCategory->read(null, $id);
  268. /* 削除処理 */
  269. if($this->BlogCategory->del($id)) {
  270. $this->BlogCategory->saveDbLog('カテゴリー「'.$data['BlogCategory']['name'].'」を削除しました。');
  271. return true;
  272. }else {
  273. return false;
  274. }
  275. }
  276. /**
  277. * [ADMIN] 削除処理
  278. *
  279. * @param int $blogContentId
  280. * @param int $id
  281. * @return void
  282. * @access public
  283. */
  284. function admin_delete($blogContentId, $id = null) {
  285. /* 除外処理 */
  286. if(!$id) {
  287. $this->Session->setFlash('無効なIDです。');
  288. $this->redirect(array('action' => 'index'));
  289. }
  290. // メッセージ用にデータを取得
  291. $post = $this->BlogCategory->read(null, $id);
  292. /* 削除処理 */
  293. if($this->BlogCategory->del($id)) {
  294. $this->Session->setFlash($post['BlogCategory']['name'].' を削除しました。');
  295. $this->BlogCategory->saveDbLog('カテゴリー「'.$post['BlogCategory']['name'].'」を削除しました。');
  296. }else {
  297. $this->Session->setFlash('データベース処理中にエラーが発生しました。');
  298. }
  299. $this->redirect(array('action'=>'index',$blogContentId));
  300. }
  301. }
  302. ?>