PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/baser/controllers/global_menus_controller.php

https://github.com/hashing/basercms
PHP | 348 lines | 171 code | 40 blank | 137 comment | 27 complexity | a32c65ee89cea845e280067ba013cfcc 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.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. * メニューコントローラー
  22. *
  23. * @package baser.controllers
  24. */
  25. class GlobalMenusController extends AppController {
  26. /**
  27. * クラス名
  28. *
  29. * @var string
  30. * @access public
  31. */
  32. var $name = 'GlobalMenus';
  33. /**
  34. * モデル
  35. *
  36. * @var array
  37. * @access public
  38. */
  39. var $uses = array('GlobalMenu');
  40. /**
  41. * コンポーネント
  42. *
  43. * @var array
  44. * @accesspublic
  45. */
  46. var $components = array('BcAuth','Cookie','BcAuthConfigure','RequestHandler');
  47. /**
  48. * ヘルパ
  49. *
  50. * @var array
  51. * @access public
  52. */
  53. var $helpers = array(BC_TIME_HELPER, BC_FORM_HELPER);
  54. /**
  55. * サブメニューエレメント
  56. *
  57. * @var array
  58. * @access public
  59. */
  60. var $subMenuElements = array();
  61. /**
  62. * ぱんくずナビ
  63. *
  64. * @var array
  65. * @access public
  66. */
  67. var $crumbs = array(
  68. array('name' => 'システム設定', 'url' => array('controller' => 'site_configs', 'action' => 'form')),
  69. array('name' => 'メニュー管理', 'url' => array('controller' => 'global_menus', 'action' => 'index'))
  70. );
  71. /**
  72. * メニューの一覧を表示する
  73. *
  74. * @return void
  75. * @access public
  76. */
  77. function admin_index() {
  78. /* セッション処理 */
  79. if($this->data) {
  80. $this->Session->write('Filter.GlobalMenu.status',$this->data['GlobalMenu']['status']);
  81. }
  82. if(isset($this->params['named']['sortmode'])){
  83. $this->Session->write('SortMode.GlobalMenu', $this->params['named']['sortmode']);
  84. }
  85. $this->data = am($this->data,$this->_checkSession());
  86. /* 並び替えモード */
  87. if(!$this->Session->check('SortMode.GlobalMenu')){
  88. $this->set('sortmode', 0);
  89. }else{
  90. $this->set('sortmode', $this->Session->read('SortMode.GlobalMenu'));
  91. }
  92. $conditions = $this->_createAdminIndexConditions($this->data);
  93. // TODO CSVドライバーが複数の並び替えフィールドを指定できないがtypeを指定したい
  94. $listDatas = $this->GlobalMenu->find( 'all', array('conditions' => $conditions, 'order' => 'GlobalMenu.sort'));
  95. $this->set('listDatas',$listDatas);
  96. if($this->RequestHandler->isAjax() || !empty($this->params['url']['ajax'])) {
  97. $this->render('ajax_index');
  98. return;
  99. }
  100. // 表示設定
  101. $this->subMenuElements = array('site_configs','global_menus');
  102. $this->pageTitle = 'メニュー一覧';
  103. $this->search = 'global_menus_index';
  104. $this->help = 'global_menus_index';
  105. }
  106. /**
  107. * [ADMIN] 登録処理
  108. *
  109. * @return void
  110. * @access public
  111. */
  112. function admin_add() {
  113. if(!$this->data) {
  114. $this->data['GlobalMenu']['status'] = 0;
  115. }else {
  116. /* 登録処理 */
  117. if(!preg_match('/^http/is', $this->data['GlobalMenu']['link']) && !preg_match('/^\//is', $this->data['GlobalMenu']['link'])){
  118. $this->data['GlobalMenu']['link'] = '/'.$this->data['GlobalMenu']['link'];
  119. }
  120. $this->data['GlobalMenu']['no'] = $this->GlobalMenu->getMax('no')+1;
  121. $this->data['GlobalMenu']['sort'] = $this->GlobalMenu->getMax('sort')+1;
  122. $this->GlobalMenu->create($this->data);
  123. // データを保存
  124. if($this->GlobalMenu->save()) {
  125. clearViewCache();
  126. $message = '新規メニュー「'.$this->data['GlobalMenu']['name'].'」を追加しました。';
  127. $this->Session->setFlash($message);
  128. $this->GlobalMenu->saveDbLog($message);
  129. $this->redirect(array('action' => 'index'));
  130. }else {
  131. $this->Session->setFlash('入力エラーです。内容を修正してください。');
  132. }
  133. }
  134. /* 表示設定 */
  135. $this->subMenuElements = array('site_configs','global_menus');
  136. $this->pageTitle = '新規メニュー登録';
  137. $this->help = 'global_menus_form';
  138. $this->render('form');
  139. }
  140. /**
  141. * [ADMIN] 編集処理
  142. *
  143. * @param int ID
  144. * @return void
  145. * @access public
  146. */
  147. function admin_edit($id) {
  148. /* 除外処理 */
  149. if(!$id) {
  150. $this->Session->setFlash('無効なIDです。');
  151. $this->redirect(array('action' => 'index'));
  152. }
  153. if(empty($this->data)) {
  154. $this->data = $this->GlobalMenu->read(null, $id);
  155. }else {
  156. /* 更新処理 */
  157. if(!preg_match('/^http/is', $this->data['GlobalMenu']['link']) && !preg_match('/^\//is', $this->data['GlobalMenu']['link'])){
  158. $this->data['GlobalMenu']['link'] = '/'.$this->data['GlobalMenu']['link'];
  159. }
  160. $this->GlobalMenu->set($this->data);
  161. if($this->GlobalMenu->save()) {
  162. clearViewCache();
  163. $message = 'メニュー「'.$this->data['GlobalMenu']['name'].'」を更新しました。';
  164. $this->Session->setFlash($message);
  165. $this->GlobalMenu->saveDbLog($message);
  166. $this->redirect(array('action' => 'index', $id));
  167. }else {
  168. $this->Session->setFlash('入力エラーです。内容を修正してください。');
  169. }
  170. }
  171. /* 表示設定 */
  172. $this->subMenuElements = array('site_configs','global_menus');
  173. $this->pageTitle = 'メニュー編集:'.$this->data['GlobalMenu']['name'];
  174. $this->help = 'global_menus_form';
  175. $this->render('form');
  176. }
  177. /**
  178. * [ADMIN] 一括削除
  179. *
  180. * @param int ID
  181. * @return void
  182. * @access public
  183. */
  184. function _batch_del($ids) {
  185. if($ids) {
  186. foreach($ids as $id) {
  187. // メッセージ用にデータを取得
  188. $post = $this->GlobalMenu->read(null, $id);
  189. /* 削除処理 */
  190. if($this->GlobalMenu->del($id)) {
  191. clearViewCache();
  192. $message = 'メニュー「'.$post['GlobalMenu']['name'].'」 を削除しました。';
  193. $this->GlobalMenu->saveDbLog($message);
  194. }
  195. }
  196. }
  197. return true;
  198. }
  199. /**
  200. * [ADMIN] 削除処理 (ajax)
  201. *
  202. * @param int ID
  203. * @return void
  204. * @access public
  205. */
  206. function admin_ajax_delete($id = null) {
  207. /* 除外処理 */
  208. if(!$id) {
  209. $this->ajaxError(500, '無効な処理です。');
  210. }
  211. // メッセージ用にデータを取得
  212. $post = $this->GlobalMenu->read(null, $id);
  213. /* 削除処理 */
  214. if($this->GlobalMenu->del($id)) {
  215. clearViewCache();
  216. $message = 'メニュー「'.$post['GlobalMenu']['name'].'」 を削除しました。';
  217. $this->GlobalMenu->saveDbLog($message);
  218. exit(true);
  219. }
  220. exit();
  221. }
  222. /**
  223. * [ADMIN] 削除処理
  224. *
  225. * @param int ID
  226. * @return void
  227. * @access public
  228. */
  229. function admin_delete($id = null) {
  230. /* 除外処理 */
  231. if(!$id) {
  232. $this->Session->setFlash('無効なIDです。');
  233. $this->redirect(array('action' => 'index'));
  234. }
  235. // メッセージ用にデータを取得
  236. $post = $this->GlobalMenu->read(null, $id);
  237. /* 削除処理 */
  238. if($this->GlobalMenu->del($id)) {
  239. clearViewCache();
  240. $message = 'メニュー「'.$post['GlobalMenu']['name'].'」 を削除しました。';
  241. $this->Session->setFlash($message);
  242. $this->GlobalMenu->saveDbLog($message);
  243. }else {
  244. $this->Session->setFlash('データベース処理中にエラーが発生しました。');
  245. }
  246. $this->redirect(array('action' => 'index'));
  247. }
  248. /**
  249. * 並び替えを更新する [AJAX]
  250. *
  251. * @access public
  252. * @return boolean
  253. */
  254. function admin_ajax_update_sort () {
  255. if($this->data){
  256. $this->data = am($this->data,$this->_checkSession());
  257. $conditions = $this->_createAdminIndexConditions($this->data);
  258. if($this->GlobalMenu->changeSort($this->data['Sort']['id'],$this->data['Sort']['offset'],$conditions)){
  259. echo true;
  260. }else{
  261. $this->ajaxError(500, '一度リロードしてから再実行してみてください。');
  262. }
  263. }else{
  264. $this->ajaxError(500, '無効な処理です。');
  265. }
  266. exit();
  267. }
  268. /**
  269. * セッションをチェックする
  270. *
  271. * @return array()
  272. * @access protected
  273. */
  274. function _checkSession(){
  275. $data = array();
  276. if($this->Session->check('Filter.GlobalMenu.menu_type')) {
  277. $data['menu_type'] = $this->Session->read('Filter.GlobalMenu.menu_type');
  278. }else {
  279. $this->Session->delete('Filter.GlobalMenu.menu_type');
  280. $data['menu_type'] = 'default';
  281. }
  282. if($this->Session->check('Filter.GlobalMenu.status')) {
  283. $data['status'] = $this->Session->read('Filter.GlobalMenu.status');
  284. }else {
  285. $this->Session->delete('Filter.GlobalMenu.status');
  286. }
  287. return array('GlobalMenu'=>$data);
  288. }
  289. /**
  290. * 管理画面ページ一覧の検索条件を取得する
  291. *
  292. * @param array $data
  293. * @return string
  294. * @access protected
  295. */
  296. function _createAdminIndexConditions($data){
  297. if(isset($data['GlobalMenu'])){
  298. $data = $data['GlobalMenu'];
  299. }
  300. /* 条件を生成 */
  301. $conditions = array();
  302. if(isset($data['status']) && $data['status'] !== '') {
  303. $conditions['GlobalMenu.status'] = $data['status'];
  304. }
  305. return $conditions;
  306. }
  307. }
  308. ?>