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

Revision 22796, 12.0 KB checked in by h_yoshimoto, 11 years ago (diff)

#2236 2.12.3リリース以降の2.12-devへのコミット差し戻し

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