Changeset 20349


Ignore:
Timestamp:
2011/02/23 19:26:40 (13 years ago)
Author:
homan
Message:

#974 [管理画面]システム設定 高度なデータベース管理 リファクタリング

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_5-dev/data/class/pages/admin/system/LC_Page_Admin_System_Editdb.php

    r20345 r20349  
    4444    function init() { 
    4545        parent::init(); 
    46  
    4746        $this->tpl_mainpage = 'system/editdb.tpl'; 
    4847        $this->tpl_subnavi  = 'system/subnavi.tpl'; 
     
    5352 
    5453    /** 
    55      * フォームパラメータ初期化 
    56      * 
    57      * @return void 
    58      */ 
    59     function initForm() { 
    60         $objForm = new SC_FormParam(); 
    61         $objForm->addParam('モード', 'mode', INT_LEN, 'n', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK')); 
    62         $objForm->addParam('テーブル名', 'table_name'); 
    63         $objForm->addParam('カラム名', 'column_name'); 
    64         $objForm->addParam('インデックス', 'indexflag'); 
    65         $objForm->addParam('インデックス(変更後)', 'indexflag_new'); 
    66         $objForm->setParam($_POST); 
    67         $this->objForm = $objForm; 
    68     } 
    69  
    70     /** 
    7154     * Page のプロセス. 
    7255     * 
     
    8467     */ 
    8568    function action() { 
    86         //フォームの値を取得 
    87         $this->initForm(); 
     69<<<<<<< .mine 
     70 
     71======= 
     72>>>>>>> .r20348 
     73        // 認証可否の判定 
     74        SC_Utils_Ex::sfIsSuccess(new SC_Session()); 
     75 
     76        $objFormParam = new SC_FormParam(); 
     77 
     78        // パラメータの初期化 
     79        $this->initForm($objFormParam, $_POST); 
     80 
    8881 
    8982        switch($this->getMode()) { 
    9083        case 'confirm' : 
    91             $this->lfDoChange(); 
     84            $message = $this->lfDoChange($objFormParam); 
     85            if (!is_array($message) && $message != "") { 
     86                $this->tpl_onload = $message; 
     87            } 
    9288            break; 
    9389        default: 
    9490            break; 
    95         } 
     91    } 
    9692 
    9793        //インデックスの現在値を取得 
     
    108104    } 
    109105 
    110     function lfGetTargetData() { 
    111         $objQuery = new SC_Query(); 
    112         $arrIndexFlag = $this->objForm->getValue('indexflag'); 
    113         $arrIndexFlagNew = $this->objForm->getValue('indexflag_new'); 
    114         $arrTableName = $this->objForm->getValue('table_name'); 
    115         $arrColumnName =$this->objForm->getValue('column_name'); 
     106    /** 
     107     * フォームパラメータ初期化 
     108     * 
     109     * @param object $objFormParam 
     110     * @param array $arrParams $_POST値 
     111     * @return void 
     112     */ 
     113    function initForm(&$objFormParam, &$arrParams) { 
     114 
     115        $objFormParam->addParam('モード', 'mode', INT_LEN, 'n', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK')); 
     116        $objFormParam->addParam('テーブル名', 'table_name'); 
     117        $objFormParam->addParam('カラム名', 'column_name'); 
     118        $objFormParam->addParam('インデックス', 'indexflag'); 
     119        $objFormParam->addParam('インデックス(変更後)', 'indexflag_new'); 
     120        $objFormParam->setParam($arrParams); 
     121 
     122    } 
     123 
     124    function lfDoChange(&$objFormParam) { 
     125        $objQuery =& SC_Query::getSingletonInstance(); 
     126        $arrTarget = $this->lfGetTargetData($objFormParam); 
     127        $message = ""; 
     128        if(is_array($arrTarget) && count($arrTarget) == 0) { 
     129            $message = "window.alert('変更対象となるデータはありませんでした。');"; 
     130            return $message; 
     131        } elseif(!is_array($arrTarget) && $arrTarget != "") { 
     132            return $arrTarget; // window.alert が返ってきているはず。 
     133        } 
     134 
     135        // 変更対象の設定変更 
     136        foreach($arrTarget as $item) { 
     137            $index_name = $item['table_name'] . '_' . $item['column_name'] . "_key"; 
     138            $arrField = array( 'fields' => array($item['column_name'] => array())); 
     139            if($item['indexflag_new'] == '1') { 
     140                $objQuery->createIndex($item['table_name'], $index_name, $arrField); 
     141            }else{ 
     142                $objQuery->dropIndex($item['table_name'], $index_name); 
     143            } 
     144        } 
     145        $message = "window.alert('インデックスの変更が完了しました。');"; 
     146        return $message; 
     147    } 
     148 
     149    function lfGetTargetData(&$objFormParam) { 
     150        $objQuery =& SC_Query::getSingletonInstance(); 
     151        $arrIndexFlag    = $objFormParam->getValue('indexflag'); 
     152        $arrIndexFlagNew = $objFormParam->getValue('indexflag_new'); 
     153        $arrTableName    = $objFormParam->getValue('table_name'); 
     154        $arrColumnName   = $objFormParam->getValue('column_name'); 
    116155        $arrTarget = array(); 
     156        $message = ""; 
     157 
    117158        // 変更されている対象を走査 
    118159        for($i = 1; $i <= count($arrIndexFlag); $i++) { 
     
    131172            if(count($arrErr) != 0) { 
    132173                // 通常の送信ではエラーにならないはずです。 
    133                 $this->tpl_onload = "window.alert('不正なデータがあったため処理を中断しました。');"; 
    134                 return; 
     174                $message = "window.alert('不正なデータがあったため処理を中断しました。');"; 
     175                return $message; 
    135176            } 
    136177            if($param['indexflag'] != $param['indexflag_new']) { 
     
    144185    } 
    145186 
    146     function lfDoChange() { 
    147         $objQuery = new SC_Query(); 
    148         $arrTarget = $this->lfGetTargetData(); 
    149         if(count($arrTarget) == 0) { 
    150             $this->tpl_onload = "window.alert('変更対象となるデータはありませんでした。');"; 
    151             return; 
    152         } 
    153  
    154         // 変更対象の設定変更 
    155         foreach($arrTarget as $item) { 
    156             $index_name = $item['table_name'] . '_' . $item['column_name'] . "_key"; 
    157             $arrField = array( 'fields' => array($item['column_name'] => array())); 
    158             if($item['indexflag_new'] == '1') { 
    159                 $objQuery->createIndex($item['table_name'], $index_name, $arrField); 
    160             }else{ 
    161                 $objQuery->dropIndex($item['table_name'], $index_name); 
    162             } 
    163         } 
    164         $this->tpl_onload = "window.alert('インデックスの変更が完了しました。');"; 
    165     } 
     187 
    166188 
    167189    /** 
     
    173195    { 
    174196        // データベースからインデックス設定一覧を取得する 
    175         $objQuery = new SC_Query(); 
     197        $objQuery =& SC_Query::getSingletonInstance(); 
    176198        $objQuery->setOrder("table_name, column_name"); 
    177199        $arrIndexList = $objQuery->select("table_name , column_name , recommend_flg, recommend_comment", "dtb_index_list"); 
Note: See TracChangeset for help on using the changeset viewer.