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
RevLine 
[15659]1<?php
2/*
[16582]3 * This file is part of EC-CUBE
4 *
[22206]5 * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
[15659]6 *
7 * http://www.lockon.co.jp/
[16582]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.
[15659]22 */
23
24// {{{ requires
[20534]25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
[15659]26
27/**
28 * コンテンツ管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
[22567]34class LC_Page_Admin_Contents extends LC_Page_Admin_Ex
35{
[15659]36
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
[22567]45    function init()
46    {
[15659]47        parent::init();
48        $this->tpl_mainpage = 'contents/index.tpl';
[20538]49        $this->tpl_subno = 'index';
[15659]50        $this->tpl_mainno = 'contents';
[19707]51        $this->arrForm = array(
52            'year' => date('Y'),
53            'month' => date('n'),
54            'day' => date('j'),
55        );
[20911]56        $this->tpl_maintitle = 'コンテンツ管理';
[15659]57        $this->tpl_subtitle = '新着情報管理';
[20265]58        //---- 日付プルダウン設定
[20499]59        $objDate = new SC_Date_Ex(ADMIN_NEWS_STARTYEAR);
[20265]60        $this->arrYear = $objDate->getYear();
61        $this->arrMonth = $objDate->getMonth();
62        $this->arrDay = $objDate->getDay();
[15659]63    }
64
65    /**
66     * Page のプロセス.
67     *
68     * @return void
69     */
[22567]70    function process()
71    {
[19661]72        $this->action();
73        $this->sendResponse();
74    }
[15659]75
[19661]76    /**
77     * Page のアクション.
78     *
79     * @return void
80     */
[22567]81    function action()
82    {
[21591]83
[22581]84        $objNews = new SC_Helper_News_Ex();
85
[20501]86        $objFormParam = new SC_FormParam_Ex();
[20265]87        $this->lfInitParam($objFormParam);
88        $objFormParam->setParam($_POST);
89        $objFormParam->convParam();
[22581]90
[20265]91        $news_id = $objFormParam->getValue('news_id');
[15659]92
93        //---- 新規登録/編集登録
[20044]94        switch ($this->getMode()) {
[22581]95            case 'edit':
[21526]96                $this->arrErr = $this->lfCheckError($objFormParam);
[22581]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('登録が完了しました。');";
[21526]111                    }
[15659]112                }
[22581]113                // POSTデータを引き継ぐ
114                $this->tpl_news_id = $news_id;
[21526]115                break;
[22581]116
117            case 'pre_edit':
[22735]118                $news = $objNews->getNews($news_id);
[22581]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;
[21526]124                break;
[22581]125
[21526]126            case 'delete':
127            //---- データ削除
[22735]128                $objNews->deleteNews($news_id);
[22581]129                //自分にリダイレクト(再読込による誤動作防止)
130                SC_Response_Ex::reload();
131                break;
[21591]132
[21526]133            //---- 表示順位移動
[22581]134            case 'up':
135                $objNews->rankUp($news_id);
[21592]136
[22581]137                // リロード
138                SC_Response_Ex::reload();
[21526]139                break;
[22581]140
141            case 'down':
142                $objNews->rankDown($news_id);
143
144                // リロード
145                SC_Response_Ex::reload();
146                break;
147
[21526]148            case 'moveRankSet':
149            //---- 指定表示順位移動
150                $input_pos = $this->getPostRank($news_id);
151                if (SC_Utils_Ex::sfIsInt($input_pos)) {
[22581]152                    $objNews->moveRank($news_id, $input_pos);
[21526]153                }
[22581]154                SC_Response_Ex::reload();
[21526]155                break;
[22581]156
[21526]157            default:
158                break;
[15659]159        }
160
[22581]161        $this->arrNews = $objNews->getList();
[20288]162        $this->line_max = count($this->arrNews);
[21591]163
[22581]164        $this->arrForm = $objFormParam->getFormParamList();
[15659]165    }
166
167    /**
168     * デストラクタ.
169     *
170     * @return void
171     */
[22567]172    function destroy()
173    {
[15659]174        parent::destroy();
175    }
176
[20265]177    /**
[20970]178     * 入力されたパラメーターのエラーチェックを行う。
[20265]179     * @param Object $objFormParam
180     * @return Array エラー内容
181     */
[22567]182    function lfCheckError(&$objFormParam)
183    {
[20503]184        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
[20265]185        $objErr->arrErr = $objFormParam->checkError();
[21514]186        $objErr->doFunc(array('日付', 'year', 'month', 'day'), array('CHECK_DATE'));
[20265]187        return $objErr->arrErr;
188    }
[15659]189
[20265]190    /**
[20970]191     * パラメーターの初期化を行う
[20265]192     * @param Object $objFormParam
193     */
[22567]194    function lfInitParam(&$objFormParam)
195    {
[21481]196        $objFormParam->addParam('news_id', 'news_id');
[21514]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'));
[21480]201        $objFormParam->addParam('URL', 'news_url', URL_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
[21514]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'));
[20265]204    }
[15659]205
[20265]206    /**
[22581]207     * 登録処理を実行.
208     *
209     * @param integer $news_id
210     * @param array $sqlval
211     * @param object $objNews
212     * @return multiple
[20265]213     */
[22581]214    function doRegist($news_id, $sqlval, SC_Helper_News_Ex $objNews)
[22567]215    {
[20265]216        $sqlval['news_id'] = $news_id;
[22581]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']);
[22735]221        return $objNews->saveNews($sqlval);
[15659]222    }
223
[20265]224    /**
225     * データの登録日を返す。
226     * @param Array $arrPost POSTのグローバル変数
227     * @return string 登録日を示す文字列
228     */
[22567]229    function getRegistDate($arrPost)
230    {
[21515]231        $registDate = $arrPost['year'] .'/'. $arrPost['month'] .'/'. $arrPost['day'];
[20265]232        return $registDate;
[15659]233    }
234
[20265]235    /**
236     * チェックボックスの値が空の時は無効な値として1を格納する
237     * @param int $link_method
238     * @return int
239     */
[22567]240    function checkLinkMethod($link_method)
241    {
[21441]242        if (strlen($link_method) == 0) {
[20265]243            $link_method = 1;
[15659]244        }
[20265]245        return $link_method;
246    }
[15659]247
[20265]248    /**
249     * ニュースの日付の値をフロントでの表示形式に合わせるために分割
250     * @param String $news_date
251     */
[22567]252    function splitNewsDate($news_date)
253    {
[21514]254        return explode('-', $news_date);
[20265]255    }
[15659]256
[20265]257    /**
258     * POSTされたランクの値を取得する
259     * @param Object $objFormParam
260     * @param Integer $news_id
261     */
[22567]262    function getPostRank($news_id)
263    {
[21441]264        if (strlen($news_id) > 0 && is_numeric($news_id) == true) {
[21527]265            $key = 'pos-' . $news_id;
266            $input_pos = $_POST[$key];
267            return $input_pos;
[20265]268        }
[15659]269    }
[20265]270
[15659]271}
Note: See TracBrowser for help on using the repository browser.