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

Revision 22735, 8.3 KB checked in by h_yoshimoto, 11 years ago (diff)

#2193 ユニットテストチームのコミットをマージ(from camp/camp-2_13-tests)

  • 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    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init()
46    {
47        parent::init();
48        $this->tpl_mainpage = 'contents/index.tpl';
49        $this->tpl_subno = 'index';
50        $this->tpl_mainno = 'contents';
51        $this->arrForm = array(
52            'year' => date('Y'),
53            'month' => date('n'),
54            'day' => date('j'),
55        );
56        $this->tpl_maintitle = 'コンテンツ管理';
57        $this->tpl_subtitle = '新着情報管理';
58        //---- 日付プルダウン設定
59        $objDate = new SC_Date_Ex(ADMIN_NEWS_STARTYEAR);
60        $this->arrYear = $objDate->getYear();
61        $this->arrMonth = $objDate->getMonth();
62        $this->arrDay = $objDate->getDay();
63    }
64
65    /**
66     * Page のプロセス.
67     *
68     * @return void
69     */
70    function process()
71    {
72        $this->action();
73        $this->sendResponse();
74    }
75
76    /**
77     * Page のアクション.
78     *
79     * @return void
80     */
81    function action()
82    {
83
84        $objNews = new SC_Helper_News_Ex();
85
86        $objFormParam = new SC_FormParam_Ex();
87        $this->lfInitParam($objFormParam);
88        $objFormParam->setParam($_POST);
89        $objFormParam->convParam();
90
91        $news_id = $objFormParam->getValue('news_id');
92
93        //---- 新規登録/編集登録
94        switch ($this->getMode()) {
95            case 'edit':
96                $this->arrErr = $this->lfCheckError($objFormParam);
97                if (!SC_Utils_Ex::isBlank($this->arrErr['news_id'])) {
98                    trigger_error('', E_USER_ERROR);
99                    return;
100                }
101
102                if (count($this->arrErr) <= 0) {
103                    // POST値の引き継ぎ
104                    $arrParam = $objFormParam->getHashArray();
105                    // 登録実行
106                    $res_news_id = $this->doRegist($news_id, $arrParam, $objNews);
107                    if ($res_news_id !== FALSE) {
108                        // 完了メッセージ
109                        $news_id = $res_news_id;
110                        $this->tpl_onload = "alert('登録が完了しました。');";
111                    }
112                }
113                // POSTデータを引き継ぐ
114                $this->tpl_news_id = $news_id;
115                break;
116
117            case 'pre_edit':
118                $news = $objNews->getNews($news_id);
119                list($news['year'],$news['month'],$news['day']) = $this->splitNewsDate($news['cast_news_date']);
120                $objFormParam->setParam($news);
121
122                // POSTデータを引き継ぐ
123                $this->tpl_news_id = $news_id;
124                break;
125
126            case 'delete':
127            //---- データ削除
128                $objNews->deleteNews($news_id);
129                //自分にリダイレクト(再読込による誤動作防止)
130                SC_Response_Ex::reload();
131                break;
132
133            //---- 表示順位移動
134            case 'up':
135                $objNews->rankUp($news_id);
136
137                // リロード
138                SC_Response_Ex::reload();
139                break;
140
141            case 'down':
142                $objNews->rankDown($news_id);
143
144                // リロード
145                SC_Response_Ex::reload();
146                break;
147
148            case 'moveRankSet':
149            //---- 指定表示順位移動
150                $input_pos = $this->getPostRank($news_id);
151                if (SC_Utils_Ex::sfIsInt($input_pos)) {
152                    $objNews->moveRank($news_id, $input_pos);
153                }
154                SC_Response_Ex::reload();
155                break;
156
157            default:
158                break;
159        }
160
161        $this->arrNews = $objNews->getList();
162        $this->line_max = count($this->arrNews);
163
164        $this->arrForm = $objFormParam->getFormParamList();
165    }
166
167    /**
168     * デストラクタ.
169     *
170     * @return void
171     */
172    function destroy()
173    {
174        parent::destroy();
175    }
176
177    /**
178     * 入力されたパラメーターのエラーチェックを行う。
179     * @param Object $objFormParam
180     * @return Array エラー内容
181     */
182    function lfCheckError(&$objFormParam)
183    {
184        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
185        $objErr->arrErr = $objFormParam->checkError();
186        $objErr->doFunc(array('日付', 'year', 'month', 'day'), array('CHECK_DATE'));
187        return $objErr->arrErr;
188    }
189
190    /**
191     * パラメーターの初期化を行う
192     * @param Object $objFormParam
193     */
194    function lfInitParam(&$objFormParam)
195    {
196        $objFormParam->addParam('news_id', 'news_id');
197        $objFormParam->addParam('日付(年)', 'year', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
198        $objFormParam->addParam('日付(月)', 'month', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
199        $objFormParam->addParam('日付(日)', 'day', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
200        $objFormParam->addParam('タイトル', 'news_title', MTEXT_LEN, 'KVa', array('EXIST_CHECK','MAX_LENGTH_CHECK','SPTAB_CHECK'));
201        $objFormParam->addParam('URL', 'news_url', URL_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
202        $objFormParam->addParam('本文', 'news_comment', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
203        $objFormParam->addParam('別ウィンドウで開く', 'link_method', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
204    }
205
206    /**
207     * 登録処理を実行.
208     *
209     * @param integer $news_id
210     * @param array $sqlval
211     * @param object $objNews
212     * @return multiple
213     */
214    function doRegist($news_id, $sqlval, SC_Helper_News_Ex $objNews)
215    {
216        $sqlval['news_id'] = $news_id;
217        $sqlval['creator_id'] = $_SESSION['member_id'];
218        $sqlval['link_method'] = $this->checkLinkMethod($sqlval['link_method']);
219        $sqlval['news_date'] = $this->getRegistDate($sqlval);
220        unset($sqlval['year'], $sqlval['month'], $sqlval['day']);
221        return $objNews->saveNews($sqlval);
222    }
223
224    /**
225     * データの登録日を返す。
226     * @param Array $arrPost POSTのグローバル変数
227     * @return string 登録日を示す文字列
228     */
229    function getRegistDate($arrPost)
230    {
231        $registDate = $arrPost['year'] .'/'. $arrPost['month'] .'/'. $arrPost['day'];
232        return $registDate;
233    }
234
235    /**
236     * チェックボックスの値が空の時は無効な値として1を格納する
237     * @param int $link_method
238     * @return int
239     */
240    function checkLinkMethod($link_method)
241    {
242        if (strlen($link_method) == 0) {
243            $link_method = 1;
244        }
245        return $link_method;
246    }
247
248    /**
249     * ニュースの日付の値をフロントでの表示形式に合わせるために分割
250     * @param String $news_date
251     */
252    function splitNewsDate($news_date)
253    {
254        return explode('-', $news_date);
255    }
256
257    /**
258     * POSTされたランクの値を取得する
259     * @param Object $objFormParam
260     * @param Integer $news_id
261     */
262    function getPostRank($news_id)
263    {
264        if (strlen($news_id) > 0 && is_numeric($news_id) == true) {
265            $key = 'pos-' . $news_id;
266            $input_pos = $_POST[$key];
267            return $input_pos;
268        }
269    }
270
271}
Note: See TracBrowser for help on using the repository browser.