source: branches/camp/camp-2_13-plugin/data/class/pages/admin/system/LC_Page_Admin_System_Rank.php @ 22567

Revision 22567, 5.1 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
26
27/**
28 * システム管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_System_Rank extends LC_Page_Admin_Ex
35{
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init()
45    {
46        parent::init();
47    }
48
49    /**
50     * Page のプロセス.
51     *
52     * @return void
53     */
54    function process()
55    {
56        $this->action();
57        $this->sendResponse();
58    }
59
60    /**
61     * Page のアクション.
62     *
63     * @return void
64     */
65    function action()
66    {
67
68        // チェック後のデータを格納
69        $arrClean = array();
70
71        // $_GET['move'] が想定値かどうかチェック
72        switch ($_GET['move']) {
73            case 'up':
74            case 'down':
75                $arrClean['move'] = $_GET['move'];
76                break;
77            default:
78                $arrClean['move'] = '';
79                break;
80        }
81
82        // 正当な数値であればOK
83        if (SC_Utils_Ex::sfIsInt($_GET['id'])) {
84            $arrClean['id'] = $_GET['id'];
85
86            switch ($arrClean['move']) {
87                case 'up':
88                    $this->lfRunkUp($arrClean['id']);
89                    break;
90
91                case 'down':
92                    $this->lfRunkDown($arrClean['id']);
93                    break;
94
95                default:
96                    break;
97            }
98        }
99
100        // エラー処理
101        else {
102            GC_Utils_Ex::gfPrintLog('error id='.$_GET['id']);
103        }
104
105        // ページの表示
106        SC_Response_Ex::sendRedirect(ADMIN_SYSTEM_URLPATH);
107    }
108
109    /**
110     * デストラクタ.
111     *
112     * @return void
113     */
114    function destroy()
115    {
116        parent::destroy();
117    }
118
119    // ランキングを上げる。
120    function lfRunkUp($id)
121    {
122        $objQuery =& SC_Query_Ex::getSingletonInstance();
123
124        // 自身のランクを取得する。
125        $rank = $objQuery->getOne('SELECT rank FROM dtb_member WHERE member_id = ?', array($id));
126
127        // ランクの最大値を取得する。
128        $maxno = $objQuery->getOne('SELECT max(rank) FROM dtb_member');
129        // ランクが最大値よりも小さい場合に実行する。
130        if ($rank < $maxno) {
131            // ランクがひとつ上のIDを取得する。
132            $sqlse = 'SELECT member_id FROM dtb_member WHERE rank = ?';
133            $up_id = $objQuery->getOne($sqlse, $rank + 1);
134
135            // Updateする値を作成する.
136            $sqlVal1 = array();
137            $sqlVal2 = array();
138            $sqlVal1['rank'] = $rank + 1;
139            $sqlVal2['rank'] = $rank;
140            $where = 'member_id = ?';
141
142            // ランク入れ替えの実行
143            $objQuery->begin();
144            $objQuery->update('dtb_member', $sqlVal1, $where, array($id));
145            $objQuery->update('dtb_member', $sqlVal2, $where, array($up_id));
146            $objQuery->commit();
147        }
148    }
149
150    // ランキングを下げる。
151    function lfRunkDown($id)
152    {
153        $objQuery =& SC_Query_Ex::getSingletonInstance();
154
155        // 自身のランクを取得する。
156        $rank = $objQuery->getOne('SELECT rank FROM dtb_member WHERE member_id = ?', array($id));
157        // ランクの最小値を取得する。
158        $minno = $objQuery->getOne('SELECT min(rank) FROM dtb_member');
159        // ランクが最大値よりも大きい場合に実行する。
160        if ($rank > $minno) {
161            // ランクがひとつ下のIDを取得する。
162            $sqlse = 'SELECT member_id FROM dtb_member WHERE rank = ?';
163            $down_id = $objQuery->getOne($sqlse, $rank - 1);
164
165            // Updateする値を作成する.
166            $sqlVal1 = array();
167            $sqlVal2 = array();
168            $sqlVal1['rank'] = $rank - 1;
169            $sqlVal2['rank'] = $rank;
170            $where = 'member_id = ?';
171
172            // ランク入れ替えの実行
173            $objQuery->begin();
174            $objQuery->update('dtb_member', $sqlVal1, $where, array($id));
175            $objQuery->update('dtb_member', $sqlVal2, $where, array($down_id));
176            $objQuery->commit();
177        }
178    }
179}
Note: See TracBrowser for help on using the repository browser.