開発メモ

開発用のメモです。

規格にカラーピッカーを設定する

<?php
/*
 * This file is part of EC-CUBE
 *
 * Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved.
 *
 * http://www.lockon.co.jp/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

require_once CLASS_REALDIR . 'pages/admin/products/LC_Page_Admin_Products_ClassCategory.php';

/**
 * 規格分類 のページクラス(拡張).
 *
 * LC_Page_Admin_Products_ClassCategory をカスタマイズする場合はこのクラスを編集する.
 *
 * @package Page
 * @author LOCKON CO.,LTD.
 * @version $Id: LC_Page_Admin_Products_ClassCategory_Ex.php 23546 2014-06-12 14:47:59Z shutta $
 */
class LC_Page_Admin_Products_ClassCategory_Ex extends LC_Page_Admin_Products_ClassCategory {
    /**
     * Page を初期化する.
     *
     * @return void
     */
    function init ( ) {
        parent :: init ( );
    }

    /**
     * Page のプロセス.
     *
     * @return void
     */
    function process ( ) {
        parent :: process ( );
    }

    /**
     * パラメーターの初期化を行う.
     *
     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
     * @return void
     */
    public function lfInitParam ( &$objFormParam ) {
        parent :: lfInitParam ( $objFormParam );
        $objFormParam -> addParam ( 'カラーコード' , 'color_code' , 6 , 'n' , array (
            'SPTAB_CHECK' ,
            'MAX_LENGTH_CHECK'
        ) );
    }

    /**
     * 規格分類情報を新規登録
     *
     * @param  array   $arrForm フォームパラメータークラス
     * @return integer 更新件数
     */
    public function lfInsertClass ( $arrForm ) {
        $objQuery = &SC_Query_Ex :: getSingletonInstance ( );
        $objQuery -> begin ( );
        // 親規格IDの存在チェック
        $where = 'del_flg <> 1 AND class_id = ?';
        $class_id = $objQuery -> get ( 'class_id' , 'dtb_class' , $where , array ( $arrForm [ 'class_id' ] ) );
        if ( ! SC_Utils_Ex :: isBlank ( $class_id ) ) {
            // INSERTする値を作成する。
            $sqlval [ 'name' ] = $arrForm [ 'name' ];
            $sqlval [ 'class_id' ] = $arrForm [ 'class_id' ];
            $sqlval [ 'creator_id' ] = $_SESSION [ 'member_id' ];
            $sqlval [ 'color_code' ] = $arrForm [ 'color_code' ];

            $sqlval [ 'rank' ] = $objQuery -> max ( 'rank' , 'dtb_classcategory' , $where , array ( $arrForm [ 'class_id' ] ) ) + 1;
            $sqlval [ 'create_date' ] = 'CURRENT_TIMESTAMP';
            $sqlval [ 'update_date' ] = 'CURRENT_TIMESTAMP';
            // INSERTの実行
            $sqlval [ 'classcategory_id' ] = $objQuery -> nextVal ( 'dtb_classcategory_classcategory_id' );
            $ret = $objQuery -> insert ( 'dtb_classcategory' , $sqlval );
        }
        $objQuery -> commit ( );

        return $ret;
    }

    /**
     * 規格分類情報を更新
     *
     * @param  array   $arrForm フォームパラメータークラス
     * @return integer 更新件数
     */
    public function lfUpdateClass ( $arrForm ) {
        $objQuery = &SC_Query_Ex :: getSingletonInstance ( );
        // UPDATEする値を作成する。
        $sqlval [ 'name' ] = $arrForm [ 'name' ];
        $sqlval [ 'color_code' ] = $arrForm [ 'color_code' ];
        $sqlval [ 'update_date' ] = 'CURRENT_TIMESTAMP';
        $where = 'classcategory_id = ?';
        // UPDATEの実行
        $ret = $objQuery -> update ( 'dtb_classcategory' , $sqlval , $where , array ( $arrForm [ 'classcategory_id' ] ) );

        return $ret;
    }

    /**
     * 有効な規格分類情報の取得
     *
     * @param  integer $class_id 規格ID
     * @return array   規格分類情報
     */
    public function lfGetClassCat ( $class_id ) {
        $objQuery = &SC_Query_Ex :: getSingletonInstance ( );

        $where = 'del_flg <> 1 AND class_id = ?';
        $objQuery -> setOrder ( 'rank DESC' );
        // XXX 降順
        $arrClassCat = $objQuery -> select ( 'name, classcategory_id, color_code' , 'dtb_classcategory' , $where , array ( $class_id ) );

        return $arrClassCat;
    }

    /**
     * 規格分類名を取得する
     *
     * @param  integer $classcategory_id 規格分類ID
     * @return string  規格分類名
     */
    public function lfGetClassCatName ( $classcategory_id ) {
        $objQuery = &SC_Query_Ex :: getSingletonInstance ( );
        $where = 'classcategory_id = ?';
        $name = $objQuery -> getRow ( 'name, color_code' , 'dtb_classcategory' , $where , array ( $classcategory_id ) );
        $this -> arrForm [ "color_code" ] = $name [ "color_code" ];
        return $name [ "name" ];
    }

}
<!--{*
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
*}-->
<link rel="stylesheet" href="/plugin/ProductClassCategoryCombo/jquery-hex-colorpicker.css" />
<script src="/plugin/ProductClassCategoryCombo/jquery-hex-colorpicker.js" type="text/javascript"></script>
<script type="text/javascript">
    $ ( document ).ready ( function ( ) {
        $ ( ".color-picker" ).hexColorPicker ( {
            "colorModel" : "hsl" ,
            "pickerWidth" : 300 ,
            "size" : 5 ,
            "style" : "hex",
            "outputFormat":"<hexcode>"
        } );
    } ); 
</script>
<form name="form1" id="form1" method="post" action="">
    <input type="hidden" name="<!--{$smarty.const.TRANSACTION_ID_NAME}-->" value="<!--{$transactionid}-->" />
    <input type="hidden" name="mode" value="edit" />
    <input type="hidden" name="classcategory_id" value="<!--{$tpl_classcategory_id}-->" />
    <!--{foreach key=key item=item from=$arrHidden}-->
    <input type="hidden" name="<!--{$key}-->" value="<!--{$item|h}-->" />
    <!--{/foreach}-->
    <div id="products" class="contents-main">

        <table>
            <tr>
                <th>規格名</th>
                <td>
                    <!--{$tpl_class_name|h}-->
                </td>
            </tr>
            <tr>
                <th>分類名<span class="attention"> *</span></th>
                <td>
                    <!--{if $arrErr.name}-->
                    <span class="attention">
                        <!--{$arrErr.name}-->
                    </span>
                    <!--{/if}-->
                    <input type="text" name="name" value="<!--{$arrForm.name|h}-->" maxlength="<!--{$smarty.const.STEXT_LEN}-->" style="<!--{$arrErr.name|sfGetErrorColor}-->" size="30" class="box30" />
                    <span class="attention"> (上限
                        <!--{$smarty.const.STEXT_LEN}-->
                        文字)</span>
                </td>
            </tr>
            <tr>
                <th>カラーコード
                    <td>
                        <!--{if $arrErr.color_code}-->
                        <span class="attention">
                            <!--{$arrErr.color_code}-->
                        </span>
                        <!--{/if}-->
                        <input type="text" name="color_code" value="<!--{$arrForm.color_code|h}-->" maxlength="6" style="<!--{$arrErr.name|sfGetErrorColor}-->;" size="6" class="box6 color-picker"/>
                        <span style="background-color: #<!--{$arrForm.color_code|h}-->; border: 1px solid black;">&nbsp;</span>
                        <span class="attention"> (上限6文字)</span>
                    </td>
            </tr>
        </table>
        <div class="btn-area">
            <ul>
                <li>
                    <a class="btn-action" href="javascript:;" onclick="eccube.fnFormModeSubmit('form1', 'edit', '', ''); return false;"><span class="btn-next">この内容で登録する</span></a>
                </li>
            </ul>
        </div>

        <table class="list">
            <col />
            <col width="10%" />
            <col width="10%" />
            <col width="15%" />
            <tr>
                <th>分類名</th>
                <th class="edit">編集</th>
                <th class="delete">削除</th>
                <th>移動</th>
            </tr>
            <!--{section name=cnt loop=$arrClassCat}-->
            <tr style="background:<!--{if $tpl_classcategory_id != $arrClassCat[cnt].classcategory_id}-->#ffffff<!--{else}--><!--{$smarty.const.SELECT_RGB}--><!--{/if}-->;">
                <td>
                    <!--{* 規格名 *}-->
                    <!--{$arrClassCat[cnt].name|h}-->
                </td>
                <td align="center" >
                    <!--{if $tpl_classcategory_id != $arrClassCat[cnt].classcategory_id}-->
                    <a href="?" onclick="eccube.setModeAndSubmit('pre_edit','classcategory_id', <!--{$arrClassCat[cnt].classcategory_id}-->); return false;">編集</a>
                    <!--{else}-->
                    編集中
                    <!--{/if}-->
                </td>
                <td align="center">
                    <a href="?" onclick="if(window.confirm('分類名を削除すると、その分類を利用している商品規格が無効になります。\n整合性の問題を把握し、バックアップを行ってから削除することを推奨致します。')){ eccube.setModeAndSubmit('delete','classcategory_id', <!--{$arrClassCat[cnt].classcategory_id}-->); } return false;">削除</a>
                </td>
                <td align="center">
                    <!--{if $smarty.section.cnt.iteration != 1}-->
                    <a href="?" onclick="eccube.setModeAndSubmit('up','classcategory_id', <!--{$arrClassCat[cnt].classcategory_id}-->); return false;">上へ</a>
                    <!--{/if}-->
                    <!--{if $smarty.section.cnt.iteration != $smarty.section.cnt.last}-->
                    <a href="?" onclick="eccube.setModeAndSubmit('down','classcategory_id', <!--{$arrClassCat[cnt].classcategory_id}-->); return false;">下へ</a>
                    <!--{/if}-->
                </td>
            </tr>
            <!--{/section}-->
        </table>
        <div class="btn">
            <a class="btn-action" href="./class.php"><span class="btn-prev">規格一覧に戻る</span></a>
        </div>
    </div>
</form>
Twitter: @asahina_alice