source: branches/version-2_12-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents.php @ 21441

Revision 21441, 12.3 KB checked in by Seasoft, 12 years ago (diff)

#1613 (ソース整形・ソースコメントの改善)

  • Zend Framework PHP 標準コーディング規約への準拠を高めた
  • 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-2011 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_Contents extends LC_Page_Admin_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'contents/index.tpl';
47        $this->tpl_subno = 'index';
48        $this->tpl_mainno = 'contents';
49        $this->arrForm = array(
50            'year' => date('Y'),
51            'month' => date('n'),
52            'day' => date('j'),
53        );
54        $this->tpl_maintitle = 'コンテンツ管理';
55        $this->tpl_subtitle = '新着情報管理';
56        //---- 日付プルダウン設定
57        $objDate = new SC_Date_Ex(ADMIN_NEWS_STARTYEAR);
58        $this->arrYear = $objDate->getYear();
59        $this->arrMonth = $objDate->getMonth();
60        $this->arrDay = $objDate->getDay();
61    }
62
63    /**
64     * Page のプロセス.
65     *
66     * @return void
67     */
68    function process() {
69        $this->action();
70        $this->sendResponse();
71    }
72
73    /**
74     * Page のアクション.
75     *
76     * @return void
77     */
78    function action() {
79        $objDb = new SC_Helper_DB_Ex();
80        $objFormParam = new SC_FormParam_Ex();
81        $this->lfInitParam($objFormParam);
82        $objFormParam->setParam($_POST);
83        $objFormParam->convParam();
84        $news_id = $objFormParam->getValue('news_id');
85
86        //---- 新規登録/編集登録
87        switch ($this->getMode()) {
88        case 'regist':
89            $arrPost = $objFormParam->getHashArray();
90            $this->arrErr = $this->lfCheckError($objFormParam);
91            if (SC_Utils_Ex::isBlank($this->arrErr)) {
92                // ニュースIDの値がPOSTされて来た場合は既存データの編集とみなし、
93                // 更新メソッドを呼び出す。
94                // ニュースIDが存在しない場合は新規登録を行う。
95                $arrPost['link_method'] = $this->checkLinkMethod($arrPost['link_method']);
96                $arrPost['news_date'] = $this->getRegistDate($arrPost);
97                $member_id = $_SESSION['member_id'];
98                if (strlen($news_id) > 0 && is_numeric($news_id)) {
99                    $this->lfNewsUpdate($arrPost,$member_id);
100                } else {
101                    $this->lfNewsInsert($arrPost,$member_id);
102                }
103                $news_id = "";
104                $this->tpl_onload = "window.alert('編集が完了しました');";
105            } else {
106                $this->arrForm = $arrPost;
107            }
108            break;
109        case 'search':
110            if (is_numeric($news_id)) {
111                list($this->arrForm) = $this->getNews($news_id);
112                list($this->arrForm['year'],$this->arrForm['month'],$this->arrForm['day']) = $this->splitNewsDate($this->arrForm['cast_news_date']);
113                $this->edit_mode = 'on';
114            }
115            break;
116        case 'delete':
117        //---- データ削除
118            if (is_numeric($news_id)) {
119                $pre_rank = $this->getRankByNewsId($news_id);
120                $this->computeRankForDelete($news_id,$pre_rank);
121                SC_Response_Ex::reload();             //自分にリダイレクト(再読込による誤動作防止)
122            }
123            break;
124        case 'move':
125        //---- 表示順位移動
126            if (strlen($news_id) > 0 && is_numeric($news_id) == true ) {
127                $term = $objFormParam->getValue('term');
128                if ($term == 'up') {
129                    $objDb->sfRankUp("dtb_news", "news_id", $news_id);
130                } else if ($term == 'down') {
131                    $objDb->sfRankDown("dtb_news", "news_id", $news_id);
132                }
133                $this->objDisplay->reload();
134            }
135            break;
136        case 'moveRankSet':
137        //---- 指定表示順位移動
138            $input_pos = $this->getPostRank($news_id);
139            if (SC_Utils_Ex::sfIsInt($input_pos)) {
140                $objDb->sfMoveRank("dtb_news", "news_id", $news_id, $input_pos);
141                $this->objDisplay->reload();
142            }
143            break;
144        default:
145            break;
146        }
147
148        $this->arrNews = $this->getNews();
149        $this->tpl_news_id = $news_id;
150        $this->line_max = count($this->arrNews);
151        $this->max_rank = $this->getRankMax();
152    }
153
154    /**
155     * デストラクタ.
156     *
157     * @return void
158     */
159    function destroy() {
160        parent::destroy();
161    }
162
163    /**
164     * 入力されたパラメーターのエラーチェックを行う。
165     * @param Object $objFormParam
166     * @return Array エラー内容
167     */
168    function lfCheckError(&$objFormParam){
169        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
170        $objErr->arrErr = $objFormParam->checkError();
171        $objErr->doFunc(array("日付", 'year', 'month', 'day'), array("CHECK_DATE"));
172        return $objErr->arrErr;
173    }
174
175    /**
176     * パラメーターの初期化を行う
177     * @param Object $objFormParam
178     */
179    function lfInitParam(&$objFormParam){
180        $objFormParam->addParam("news_id", 'news_id');
181        $objFormParam->addParam("日付(年)", 'year', INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
182        $objFormParam->addParam("日付(月)", 'month', INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
183        $objFormParam->addParam("日付(日)", 'day', INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
184        $objFormParam->addParam("タイトル", 'news_title', MTEXT_LEN, 'KVa', array("EXIST_CHECK","MAX_LENGTH_CHECK","SPTAB_CHECK"));
185        $objFormParam->addParam('URL', 'news_url', URL_LEN, 'KVa', array("MAX_LENGTH_CHECK"));
186        $objFormParam->addParam("本文", 'news_comment', LTEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK"));
187        $objFormParam->addParam("別ウィンドウで開く", 'link_method', INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"));
188        $objFormParam->addParam("ランク移動", 'term', INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"));
189    }
190
191    /**
192     * 新着記事のデータの登録を行う
193     * @param Array $arrPost POSTデータの配列
194     * @param Integer $member_id 登録した管理者のID
195     */
196    function lfNewsInsert($arrPost,$member_id){
197        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
198
199        // rankの最大+1を取得する
200        $rank_max = $this->getRankMax();
201        $rank_max = $rank_max + 1;
202
203        $table = 'dtb_news';
204        $sqlval = array();
205        $news_id = $objQuery->nextVal('dtb_news_news_id');
206        $sqlval['news_id'] = $news_id;
207        $sqlval['news_date'] = $arrPost['news_date'];
208        $sqlval['news_title'] = $arrPost['news_title'];
209        $sqlval['creator_id'] = $member_id;
210        $sqlval['news_url'] = $arrPost['news_url'];
211        $sqlval['link_method'] = $arrPost['link_method'];
212        $sqlval['news_comment'] = $arrPost['news_comment'];
213        $sqlval['rank'] = $rank_max;
214        $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
215        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
216        $objQuery->insert($table, $sqlval);
217    }
218
219    function lfNewsUpdate($arrPost,$member_id){
220        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
221
222        $table = 'dtb_news';
223        $sqlval = array();
224        $sqlval['news_date'] = $arrPost['news_date'];
225        $sqlval['news_title'] = $arrPost['news_title'];
226        $sqlval['creator_id'] = $member_id;
227        $sqlval['news_url'] = $arrPost['news_url'];
228        $sqlval['news_comment'] = $arrPost['news_comment'];
229        $sqlval['link_method'] = $arrPost['link_method'];
230        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
231        $where = 'news_id = ?';
232        $arrValIn = array($arrPost['news_id']);
233        $objQuery->update($table, $sqlval, $where, $arrValIn);
234    }
235
236    /**
237     * データの登録日を返す。
238     * @param Array $arrPost POSTのグローバル変数
239     * @return string 登録日を示す文字列
240     */
241    function getRegistDate($arrPost){
242        $registDate = $arrPost['year'] ."/". $arrPost['month'] ."/". $arrPost['day'];
243        return $registDate;
244    }
245
246    /**
247     * チェックボックスの値が空の時は無効な値として1を格納する
248     * @param int $link_method
249     * @return int
250     */
251    function checkLinkMethod($link_method){
252        if (strlen($link_method) == 0) {
253            $link_method = 1;
254        }
255        return $link_method;
256    }
257
258    /**
259     * ニュース記事を取得する。
260     * @param Integer news_id ニュースID
261     */
262    function getNews($news_id = ''){
263        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
264        $col = '*, cast(news_date as date) as cast_news_date';
265        $table = 'dtb_news';
266        $order = 'rank DESC';
267        if (strlen($news_id) == 0) {
268            $where = 'del_flg = 0';
269            $arrval = array();
270        } else {
271            $where = 'del_flg = 0 AND news_id = ?';
272            $arrval = array($news_id);
273        }
274        $objQuery->setOrder($order);
275        return $objQuery->select($col, $table, $where,$arrval);
276    }
277
278    /**
279     * 指定されたニュースのランクの値を取得する。
280     * @param Integer $news_id
281     */
282    function getRankByNewsId($news_id){
283        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
284        $col = 'rank';
285        $table = 'dtb_news';
286        $where = 'del_flg = 0 AND news_id = ?';
287        $arrval = array($news_id);
288        list($rank) = $objQuery->select($col, $table, $where, $arrval);
289        return $rank['rank'];
290    }
291
292    /**
293     * 削除する新着情報以降のrankを1つ繰り上げる。
294     * @param Integer $news_id
295     * @param Integer $rank
296     */
297    function computeRankForDelete($news_id,$rank){
298        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
299        $objQuery->begin();
300        $table = 'dtb_news';
301        $sqlval = array();
302        $sqlval['rank'] = $rank;
303        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
304        $where = 'del_flg = 0 AND rank > ?';
305        $arrValIn = array($rank);
306        $objQuery->update($table, $sqlval, $where, $arrValIn);
307
308        $sqlval = array();
309        $sqlval['rank'] = '0';
310        $sqlval['del_flg'] = '1';
311        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
312        $where = 'news_id = ?';
313        $arrValIn = array($news_id);
314        $objQuery->update($table, $sqlval, $where, $arrValIn);
315        $objQuery->commit();
316    }
317
318    /**
319     * ニュースの日付の値をフロントでの表示形式に合わせるために分割
320     * @param String $news_date
321     */
322    function splitNewsDate($news_date){
323        return explode("-", $news_date);
324    }
325
326    /**
327     * ランクの最大値の値を返す。
328     * @return Intger $max ランクの最大値の値
329     */
330    function getRankMax(){
331        $objQuery =& SC_Query_Ex::getSingletonInstance();
332        $col = 'MAX(rank) as max';
333        $table = 'dtb_news';
334        $where = 'del_flg = 0';
335        list($result) = $objQuery->select($col, $table, $where);
336        return $result['max'];
337    }
338
339    /**
340     * POSTされたランクの値を取得する
341     * @param Object $objFormParam
342     * @param Integer $news_id
343     */
344    function getPostRank($news_id){
345        if (strlen($news_id) > 0 && is_numeric($news_id) == true) {
346           $key = "pos-".$news_id;
347           $input_pos = $_POST[$key];
348           return $input_pos;
349        }
350    }
351
352}
Note: See TracBrowser for help on using the repository browser.