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

Revision 22926, 8.1 KB checked in by Seasoft, 11 years ago (diff)

#2287 (環境によりデストラクタが正しく動作しないケースがある)
#2288 (リクエスト単位で実行されるべきログ出力がブロックにも適用されている)
#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

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