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

Revision 20541, 12.4 KB checked in by Seasoft, 13 years ago (diff)

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

  • LF
  • 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-2010 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_subnavi = 'contents/subnavi.tpl';
48        $this->tpl_subno = 'index';
49        $this->tpl_mainno = 'contents';
50        $this->arrForm = array(
51            'year' => date('Y'),
52            'month' => date('n'),
53            'day' => date('j'),
54        );
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                $this->tpl_onload = "window.alert('編集が完了しました');";
104            } else {
105                $this->arrForm = $arrPost;
106            }
107            break;
108        case 'search':
109            if (is_numeric($news_id)) {
110                list($this->arrForm) = $this->getNews($news_id);
111                list($this->arrForm['year'],$this->arrForm['month'],$this->arrForm['day']) = $this->splitNewsDate($this->arrForm['cast_news_date']);
112                $this->edit_mode = 'on';
113            }
114            break;
115        case 'delete':
116        //---- データ削除
117            if (is_numeric($news_id)) {
118                $pre_rank = $this->getRankByNewsId($news_id);
119                $this->computeRankForDelete($news_id,$pre_rank);
120                SC_Response_Ex::reload();             //自分にリダイレクト(再読込による誤動作防止)
121            }
122            break;
123        case 'move':
124        //---- 表示順位移動
125            if (strlen($news_id) > 0 && is_numeric($news_id) == true ) {
126                $term = $objFormParam->getValue('term');
127                if ($term == 'up') {
128                    $objDb->sfRankUp("dtb_news", "news_id", $news_id);
129                } else if ($term == 'down') {
130                    $objDb->sfRankDown("dtb_news", "news_id", $news_id);
131                }
132                $this->objDisplay->reload();
133            }
134            break;
135        case 'moveRankSet':
136        //---- 指定表示順位移動
137            $input_pos = $this->getPostRank($news_id);
138            if(SC_Utils_Ex::sfIsInt($input_pos)) {
139                $objDb->sfMoveRank("dtb_news", "news_id", $news_id, $input_pos);
140                $this->objDisplay->reload();
141            }
142            break;
143        default:
144            break;
145        }
146
147        $this->arrNews = $this->getNews();
148        $this->line_max = count($this->arrNews);
149        $this->max_rank = $this->getRankMax();
150    }
151
152    /**
153     * デストラクタ.
154     *
155     * @return void
156     */
157    function destroy() {
158        parent::destroy();
159    }
160
161    /**
162     * 入力されたパラメータのエラーチェックを行う。
163     * @param Object $objFormParam
164     * @return Array エラー内容
165     */
166    function lfCheckError(&$objFormParam){
167        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
168        $objErr->arrErr = $objFormParam->checkError();
169        $objErr->doFunc(array("日付", 'year', 'month', 'day'), array("CHECK_DATE"));
170        return $objErr->arrErr;
171    }
172
173    /**
174     * パラメータの初期化を行う
175     * @param Object $objFormParam
176     */
177    function lfInitParam(&$objFormParam){
178        $objFormParam->addParam("news_id", 'news_id');
179        $objFormParam->addParam("日付(年)", 'year', INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
180        $objFormParam->addParam("日付(月)", 'month', INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
181        $objFormParam->addParam("日付(日)", 'day', INT_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
182        $objFormParam->addParam("タイトル", 'news_title', MTEXT_LEN, 'KVa', array("EXIST_CHECK","MAX_LENGTH_CHECK","SPTAB_CHECK"));
183        $objFormParam->addParam('URL', 'news_url', URL_LEN, 'KVa', array("MAX_LENGTH_CHECK"));
184        $objFormParam->addParam("本文", 'news_comment', LTEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK"));
185        $objFormParam->addParam("別ウィンドウで開く", 'link_method', INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"));
186        $objFormParam->addParam("ランク移動", 'term', INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"));
187    }
188
189    /**
190     * 新着記事のデータの登録を行う
191     * @param Array $arrPost POSTデータの配列
192     * @param Integer $member_id 登録した管理者のID
193     */
194    function lfNewsInsert($arrPost,$member_id){
195        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
196
197        // rankの最大+1を取得する
198        $rank_max = $this->getRankMax();
199        $rank_max = $rank_max + 1;
200
201        $table = 'dtb_news';
202        $sqlval = array();
203        $news_id = $objQuery->nextVal('dtb_news_news_id');
204        $sqlval['news_id'] = $news_id;
205        $sqlval['news_date'] = $arrPost['news_date'];
206        $sqlval['news_title'] = $arrPost['news_title'];
207        $sqlval['creator_id'] = $member_id;
208        $sqlval['news_url'] = $arrPost['news_url'];
209        $sqlval['link_method'] = $arrPost['link_method'];
210        $sqlval['news_comment'] = $arrPost['news_comment'];
211        $sqlval['rank'] = $rank_max;
212        $sqlval['create_date'] = 'now()';
213        $sqlval['update_date'] = 'now()';
214        $objQuery->insert($table, $sqlval);
215
216        // 最初の1件目の登録はrankにNULLが入るので対策
217        $sqlval = array();
218        $sqlval['rank'] = 1;
219        $where = ' del_flg = 0 AND rank IS NULL';
220        $objQuery->update($table, $sqlval, $where);
221    }
222
223    function lfNewsUpdate($arrPost,$member_id){
224        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
225
226        $table = 'dtb_news';
227        $sqlval = array();
228        $sqlval['news_date'] = $arrPost['news_date'];
229        $sqlval['news_title'] = $arrPost['news_title'];
230        $sqlval['creator_id'] = $member_id;
231        $sqlval['news_url'] = $arrPost['news_url'];
232        $sqlval['news_comment'] = $arrPost['news_comment'];
233        $sqlval['link_method'] = $arrPost['link_method'];
234        $sqlval['update_date'] = 'NOW()';
235        $where = 'news_id = ?';
236        $arrValIn = array($arrPost['news_id']);
237        $objQuery->update($table, $sqlval, $where, $arrValIn);
238    }
239
240    /**
241     * データの登録日を返す。
242     * @param Array $arrPost POSTのグローバル変数
243     * @return string 登録日を示す文字列
244     */
245    function getRegistDate($arrPost){
246        $registDate = $arrPost['year'] ."/". $arrPost['month'] ."/". $arrPost['day'];
247        return $registDate;
248    }
249
250    /**
251     * チェックボックスの値が空の時は無効な値として1を格納する
252     * @param int $link_method
253     * @return int
254     */
255    function checkLinkMethod($link_method){
256        if(strlen($link_method) == 0){
257            $link_method = 1;
258        }
259        return $link_method;
260    }
261
262    /**
263     * ニュース記事を取得する。
264     * @param Integer news_id ニュースID
265     */
266    function getNews($news_id = ''){
267        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
268        $col = '*, cast(news_date as date) as cast_news_date';
269        $table = 'dtb_news';
270        $order = 'rank DESC';
271        if(strlen($news_id) == 0){
272            $where = 'del_flg = 0';
273            $arrval = array();
274        }else{
275            $where = 'del_flg = 0 AND news_id = ?';
276            $arrval = array($news_id);
277        }
278        $objQuery->setOrder($order);
279        return $objQuery->select($col, $table, $where,$arrval);
280    }
281
282    /**
283     * 指定されたニュースのランクの値を取得する。
284     * @param Integer $news_id
285     */
286    function getRankByNewsId($news_id){
287        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
288        $col = 'rank';
289        $table = 'dtb_news';
290        $where = 'del_flg = 0 AND news_id = ?';
291        $arrval = array($news_id);
292        list($rank) = $objQuery->select($col, $table, $where, $arrval);
293        return $rank['rank'];
294    }
295
296    /**
297     * 削除する新着情報以降のrankを1つ繰り上げる。
298     * @param Integer $news_id
299     * @param Integer $rank
300     */
301    function computeRankForDelete($news_id,$rank){
302        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
303        $objQuery->begin();
304        $table = 'dtb_news';
305        $sqlval = array();
306        $sqlval['rank'] = $rank;
307        $sqlval['update_date'] = 'NOW()';
308        $where = 'del_flg = 0 AND rank > ?';
309        $arrValIn = array($rank);
310        $objQuery->update($table, $sqlval, $where, $arrValIn);
311
312        $sqlval = array();
313        $sqlval['rank'] = '0';
314        $sqlval['del_flg'] = '1';
315        $sqlval['update_date'] = 'NOW()';
316        $where = 'news_id = ?';
317        $arrValIn = array($news_id);
318        $objQuery->update($table, $sqlval, $where, $arrValIn);
319        $objQuery->commit();
320    }
321
322    /**
323     * ニュースの日付の値をフロントでの表示形式に合わせるために分割
324     * @param String $news_date
325     */
326    function splitNewsDate($news_date){
327        return explode("-", $news_date);
328    }
329
330    /**
331     * ランクの最大値の値を返す。
332     * @return Intger $max ランクの最大値の値
333     */
334    function getRankMax(){
335        $objQuery =& SC_Query_Ex::getSingletonInstance();
336        $col = 'MAX(rank)';
337        $table = 'dtb_news';
338        $where = 'del_flg = 0';
339        list($result) = $objQuery->select($col, $table, $where);
340        return $result['max'];
341    }
342
343    /**
344     * POSTされたランクの値を取得する
345     * @param Object $objFormParam
346     * @param Integer $news_id
347     */
348    function getPostRank($news_id){
349        if(strlen($news_id) > 0 && is_numeric($news_id) == true){
350           $key = "pos-".$news_id;
351           $input_pos = $_POST[$key];
352           return $input_pos;
353        }
354    }
355
356}
357?>
Note: See TracBrowser for help on using the repository browser.