source: branches/version-2_5-dev/data/class/pages/upgrade/helper/LC_Upgrade_Helper_Json.php @ 19684

Revision 19684, 2.4 KB checked in by nanasess, 13 years ago (diff)

#635 処理の単純化

  • Service/JSON.php の宣言を html/require_class.php へ移動
  • 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 * Enter description here...
4 *
5 */
6class LC_Upgrade_Helper_Json extends Services_JSON {
7    /** */
8    var $arrData = array(
9        'status'  => null,
10        'errcode' => null,
11        'msg'     => null,
12        'data'    => array()
13    );
14
15    /**
16     * Enter description here...
17     *
18     * @return SC_Upgrade_Helper_Json
19     */
20    function LC_Upgrade_Helper_Json() {
21        parent::Services_JSON();
22    }
23
24    /**
25     * Enter description here...
26     *
27     */
28    function isError() {
29        return $this->isSuccess() ? false : true;
30    }
31
32    function isSuccess() {
33        if ($this->arrData['status'] === OSTORE_STATUS_SUCCESS) {
34            return true;
35        }
36        return false;
37    }
38
39    /**
40     * Enter description here...
41     *
42     * @param unknown_type $errCode
43     * @param unknown_type $errMessage
44     */
45    function setError($errCode) {
46        $masterData = new SC_DB_MasterData();
47        $arrOStoreErrMsg = $masterData->getMasterData("mtb_ownersstore_err");
48
49        $this->arrData['status']  = OSTORE_STATUS_ERROR;
50        $this->arrData['errcode'] = $errCode;
51        $this->arrData['msg']  = isset($arrOStoreErrMsg[$errCode])
52            ? $arrOStoreErrMsg[$errCode]
53            : $arrOStoreErrMsg[OSTORE_E_UNKNOWN];
54    }
55
56    /**
57     * Enter description here...
58     *
59     * @param mixed $data
60     */
61    function setSuccess($data = array(), $msg = '') {
62        $this->arrData['status'] = OSTORE_STATUS_SUCCESS;
63        $this->arrData['data']   = $data;
64        $this->arrData['msg']    = $msg;
65    }
66
67    /**
68     * Enter description here...
69     *
70     */
71    function display() {
72        header("Content-Type: text/javascript; charset=UTF-8");
73        echo $this->encode($this->arrData);
74    }
75
76    /**
77     * JSONデータをデコードする.
78     *
79     * php5.2.0からpreg_match関数に渡せるデータ長に制限がある(?)ため,
80     * Services_JSONが正常に動作しなくなる.
81     * そのため5.2.0以上の場合は組み込み関数のjson_decode()を使用する.
82     *
83     * @param string $str
84     * @return StdClass
85     */
86    function decode($str) {
87        if (function_exists('json_decode')) {
88            LC_Upgrade_Helper_Log::log(' *use json_decode()');
89            return json_decode($str);
90        }
91
92        LC_Upgrade_Helper_Log::log(' *use Services_JSON::decode()');
93        return parent::decode($str);
94    }
95}
Note: See TracBrowser for help on using the repository browser.